资源简介
基于深度学习生成音乐(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
相关资源
- 7.图像风格迁移 基于深度学习 pyt
- dronet源码+论文(深度学习)
- 012345手势识别神经网络代码
- 深度学习(SPOT-RNA)
- 爬虫爬取网易云音乐
- 深度学习YOLOv3分类算法
- 网易云音乐
- Deep Learning Cookbook_ practical recipes to g
- 深度学习视频中的行为识别
- deep learning with python 中文版
- 吴恩达深度学习超参数调制完整程序
- Python贪吃蛇源码+背景音乐+中文字体
- 深度学习入门 基于python理论与实现
- Python-基于深度学习的语音增强使用
- 《深度学习Deep Learning with Python 2017》
- 深度学习进阶:自然语言处理
- 基于深度学习堆栈自动编码器模型的
- python机器学习-音乐分类器实现
- 深度学习入门:基于python的理论与实
- 吴恩达深度学习1-21-31-42-1编程作业线
- 基于Python的深度学习
- 安全帽检测detect.7z
- deep_learning_with_python.pdf(Jason Brownlee)
- 人脸识别python代码
- Make Your Own Neural Network - 搭建自己的神
- BrownLee Better Deep Learning
- python 直方图规定化代码
- 简单粗暴 TensorFlow
- 5. 深度学习中的目标检测 python代码实
- 深度学习入门:基于Python的理论与实
评论
共有 条评论