资源简介
基于深度学习生成音乐(mid格式的音乐) 附代码,绝对可用,我自己调试过,python3环境
代码片段和文件信息
‘‘‘
Author: Ji-Sung Kim
Project: deepjazz
Purpose: Generate jazz using a deep learning model (LSTM in deepjazz).
Some code adapted from Evan Chow‘s jazzml https://github.com/evancchow/jazzml
with express permission.
Code was built while significantly referencing public examples from the
Keras documentation on GitHub:
https://github.com/fchollet/keras/blob/master/examples/lstm_text_generation.py
GPU run command:
THEANO_FLAGS=mode=FAST_RUNdevice=gpufloatX=float32 python generator.py [# of epochs]
Note: running Keras/Theano on GPU is formally supported for only NVIDIA cards (CUDA backend).
‘‘‘
from __future__ import print_function
import sys
from music21 import *
import numpy as np
from grammar import *
from preprocess import *
from qa import *
import lstm
#----------------------------HELPER FUNCTIONS----------------------------------#
‘‘‘ Helper function to sample an index from a probability array ‘‘‘
def __sample(a temperature=1.0):
a = np.log(a) / temperature
# a = np.exp(a) / np.sum(np.exp(a))
# return np.argmax(np.random.multinomial(1 a 1))
dist = np.exp(a)/np.sum(np.exp(a))
choices = range(len(a))
return np.random.choice(choices p=dist)
‘‘‘ Helper function to generate a predicted value from a given matrix ‘‘‘
def __predict(model x indices_val diversity):
preds = model.predict(x verbose=0)[0]
next_index = __sample(preds diversity)
next_val = indices_val[next_index]
return next_val
‘‘‘ Helper function which uses the given model to generate a grammar sequence
from a given corpus indices_val (mapping) abstract_grammars (list)
and diversity floating point value. ‘‘‘
def __generate_grammar(model corpus abstract_grammars values val_indices
indices_val max_len max_tries diversity):
curr_grammar = ‘‘
# np.random.randint is exclusive to high
start_index = np.random.randint(0 len(corpus) - max_len)
sentence = corpus[start_index: start_index + max_len] # seed
running_length = 0.0
while running_length <= 4.1: # arbitrary from avg in input file
# transform sentence (previous sequence) to matrix
x = np.zeros((1 max_len len(values)))
for t val in enumerate(sentence):
if (not val in val_indices): print(val)
x[0 t val_indices[val]] = 1.
next_val = __predict(model x indices_val diversity)
# fix first note: must not have < > and not be a rest
if (running_length < 0.00001):
tries = 0
while (next_val.split(‘‘)[0] == ‘R‘ or
len(next_val.split(‘‘)) != 2):
# give up after 1000 tries; random from input‘s first notes
if tries >= max_tries:
print(‘Gave up on first note generation after‘ max_tries
‘tries‘)
# np.random is exclusive to high
rand = np.random.randint(0 len(abstrac
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-10-28 23:30 deepjazz\
文件 862 2017-08-02 09:43 deepjazz\.gitignore
文件 11357 2017-08-02 09:43 deepjazz\LICENSE
文件 309 2017-08-02 09:43 deepjazz\NOTICE
文件 2368 2017-08-02 09:43 deepjazz\README.md
目录 0 2018-10-28 22:42 deepjazz\__pycache__\
文件 7182 2018-10-28 22:42 deepjazz\__pycache__\grammar.cpython-36.pyc
文件 1624 2018-10-28 22:11 deepjazz\__pycache__\lstm.cpython-36.pyc
文件 3983 2018-10-28 22:30 deepjazz\__pycache__\preprocess.cpython-36.pyc
文件 2131 2018-10-28 22:27 deepjazz\__pycache__\qa.cpython-36.pyc
文件 6999 2018-10-28 23:30 deepjazz\generator.py
文件 15244 2018-10-28 22:41 deepjazz\grammar.py
文件 1815 2017-08-02 09:43 deepjazz\lstm.py
目录 0 2018-10-28 23:47 deepjazz\midi\
文件 4320 2018-10-28 23:33 deepjazz\midi\deepjazz_on_metheny...128_epochs.midi
文件 92549 2017-08-02 09:43 deepjazz\midi\original_metheny.mid
文件 5629 2018-10-28 22:30 deepjazz\preprocess.py
文件 2861 2018-10-28 22:27 deepjazz\qa.py
相关资源
- Python深度学习部分
- make_train_test.py
- 纯python实现mnist手写体识别.zip
- python写的深度学习代码
- caffe ssd 深度学习 摄像头 目标检测
- Python-深度学习与自然语言处理知识图
- 视杯分割增强数据
- AlexNet深度神经网络
- python深度学习电子版+源码
- 基于Keras的股票价格预测
- python 音乐播放器
- testCases_v3.py
- LSTM可以运行
- Tensorflow之CNN实现CIFAR-10图像的分类p
- Python人工智能AI深度学习全套课程.t
- 深度学习入门代码 5-1 mnist数据集.p
- 最详细神经网络python描写附注释
- 计算机视觉视频教程百度云盘资源
- tensorflow_random_forest_demo.py
- keras_inception_v4_finetune.py
- mnist_acgan.py
- 卷积神经网络轴承数故障分类
- 利用鸢尾花数据集画出P-R曲线 pytho
- python图像裁剪
- 音乐爬虫
- Python-基于pygame和tkinter本地音乐播放器
- 目标检测自动标注代码
- 梯度下降python程序实现+可视化
- 基于深度学习的表情识别系统
- 语义分割标注转为目标检测框标注
评论
共有 条评论