Coder Social home page Coder Social logo

music_generator_demo's Introduction

Music Generator Demo

##Overview Use TensorFlow to generate short sequences of music with a Restricted Boltzmann Machine. This is the code for Generate Music in TensorFlow on YouTube.

##Dependencies

Use pip to install any missing dependencies (i.e pip install msgpack)

##Basic Usage To train the model and create music, simply clone this directory and run

python rbm_chords.py

The training data goes in the pop_music_midi folder. You have to use MIDI files. You can find some here. Training will take 5-10 minutes on a modern laptop. The output will be a collection of midi files. You can combine them together with a script if you'd like.

##Challenge

The challenge for this video is to create a happy/upbeat MIDI file using this script. You could play with the hyperparameters if you'd like to see what works, choose a happy/upbeat MIDI dataset, or do both. When you're done, upload your clone of this repository whether or not the code is modified with your generated MIDI files included in the repo. Post a link to your code in the comments of the video. I'll mention the winner (the most upbeat sounding MIDI, any of the snippets is fine or if you want you can combine them) in my next video. Good luck!!

##Credits

The credit for this code goes to dshieble i've merely created a wrapper around his code to make it easier to get started.

music_generator_demo's People

Contributors

cjpurackal avatar llsourcell avatar testbounty avatar yjh avatar yjh1987 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

music_generator_demo's Issues

AttributeError: 'module' object has no attribute 'While'

I really enjoyed your video and wanted to try your code out myself. However, when running python rbm_chords.py I get the following output:

$ python rbm_chords.py 100%|███████████████████████████| 126/126 [00:03<00:00, 33.76it/s] 122 songs processed Traceback (most recent call last): File "rbm_chords.py", line 87, in <module> x_sample = gibbs_sample(1) File "rbm_chords.py", line 77, in gibbs_sample [_, _, x_sample] = control_flow_ops.While(lambda count, num_iter, *args: count < num_iter, AttributeError: 'module' object has no attribute 'While'

For me that looks like my tensorflow version is not the same this script expects or something.
I am running Tensorflow version 0.11.0rc0 in a virtualenv using Python 2.7.12.

Looking at the current Tensorflow repo, While does indeed not seem to be a part of control_flow_ops.py: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/control_flow_ops.py

Is your script maybe limited to an older version of Tensorflow?

TypeError: 'float' object cannot be interpreted as an integer

Tried running the sample and got the result below.

Traceback (most recent call last):
File "/Users/MG-hooper/Desktop/TF/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "rbm_chords.py", line 117, in
song = np.reshape(song, [song.shape[0]/num_timesteps, song.shape[1]*num_timesteps])
File "/Users/MG-hooper/Desktop/TF/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 232, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
File "/Users/MG-hooper/Desktop/TF/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 67, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "/Users/MG-hooper/Desktop/TF/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 47, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: 'float' object cannot be interpreted as an integer

invalid Syntax

I get tis error running on win 10 64bit with python 3.5
python35\python.exe C:\Users\Eumi\Music_Generator_Demo-master\rbm_chords.py
File "C:\Users\Eumi\Music_Generator_Demo-master\rbm_chords.py", line 30
print "{} songs processed".format(len(songs))
^
SyntaxError: invalid syntax

module 'midi' has no attribute 'read_midifile'

Traceback (most recent call last):
File "rbm_chords.py", line 36, in
songs = get_songs('Pop_Music_Midi') # These songs have already been converted from midi to msgpack
File "rbm_chords.py", line 32, in get_songs
raise e
File "rbm_chords.py", line 28, in get_songs
song = np.array(midi_manipulation.midiToNoteStateMatrix(f))
File "C:\Users\Paras\Downloads\tensorflow-music-generator-master\midi_manipulation.py", line 11, in midiToNoteStateMatrix
pattern = midi.read_midifile(midifile)
AttributeError: module 'midi' has no attribute 'read_midifile'
Please provide a solution as soon as possible!

msgpack

Hello

in file rbm_chords.py
songs = get_songs('Pop_Music_Midi') #These songs have already been converted from midi to msgpack

How to convert midi to msgpack please?

I have tested this program on my own .mid music. The generated results are 2 seconds each and very fast.

Many thanks to all,
John

Does not work on Windows platform

I tried to run this in windows but it did not work as one of it's dependencies does not support windows..

The python-midi library is required by the midi_manipulation.py script.
But unfortunately the python-midi library requires the ALSA Sequncer which is only for Linux, so this does not work on Windows...

I tried to install python-midi, but it fails.. Upon investigation the setup code i found this

# currently, only the ALSA sequencer is supported
    if platform.startswith('linux'):
        setup_alsa(ns)
        pass
    else:
        print("No sequencer available for '%s' platform." % platform)

I think there is need of something else to be done so that it works across all platforms..

How slow will this script be if i run it on Raspberry Pi ?

I want to run this script on a raspberry pi to save costs, i don't have a powerful cloud service or something, but i want it to be trained with lots of data and so i have no problem in running the Pi 24 X 7..
I am choosing Pi because i want to run it full time, and a cloud option will cost me,
So please do let me know, also please do let me know if there are some other options that would not cost me anything ...

module 'midi' has no attribute 'Pattern'

Traceback (most recent call last):
File "H:/Python Project/venv1/practice/tensorflow-music-generator-master/rbm_chords.py", line 148, in
midi_manipulation.noteStateMatrixToMidi(S, "out/generated_chord_{}".format(i))
File "H:\Python Project\venv1\practice\tensorflow-music-generator-master\midi_manipulation.py", line 77, in noteStateMatrixToMidi
pattern = midi.Pattern()
AttributeError: module 'midi' has no attribute 'Pattern'

Dose anybody know how to solve the problem?

save and resume

Can somebody add a save and resume model function ..? that would be so great =) and also a generate songs on command .. pleeease i cant program ....

Slicing type error - bug?

Installed all of the dependencies but I get this error:

Traceback (most recent call last):
File "rbm_chords.py", line 116, in
song = song[:np.floor(song.shape[0]/num_timesteps)*num_timsteps]
TypeError: slice indices must be integers or None or have an index method

New to using python/Linux so can't really decipher this myself. Would appreciate some assistance.

cannot merge samples

Hi everyone! I met a problem that when I excute the script "merge_samples.py", the result of np.shape(songs) is (0, 156). Obviously the final file is an empty file. What's wrong with my program?

can I run this demo on python3 ?

I install midi on python3 but It look like It not working in python3

➜  ~ git clone https://github.com/vishnubob/python-midi.git
➜  python-midi git:(master) python3 setup.py 
  File "setup.py", line 65
    print "No sequencer available for '%s' platform." % platform
                                                    ^
SyntaxError: Missing parentheses in call to 'print'

and I found is issues:

vishnubob/python-midi#35

or I install wrong module?

can someone help me please ! : D

MIDI import

Hi is there anything I need to import for the 'import midi' statement in midi manipulation? I get no module "MIDI" error

AttributeError: 'module' object has no attribute 'While'

Hi there,
I am getting this issue when I run the program:
RESTART: …/Music_Generator_Demo-master/Pop_Music_Midi/rbm_chords_clone.py

0it [00:00, ?it/s]
0 songs processed

Traceback (most recent call last):
File "…/Music_Generator_Demo-master/Pop_Music_Midi/rbm_chords_clone.py", line 87, in
x_sample = gibbs_sample(1)
File "…/Music_Generator_Demo-master/Pop_Music_Midi/rbm_chords_clone.py", line 77, in gibbs_sample
[_, _, x_sample] = control_flow_ops.While(lambda count, num_iter, *args: count < num_iter,
AttributeError: 'module' object has no attribute 'While'

Initially I ran the program as it was but got this error
…/Music_Generator_Demo-master/Pop_Music_Midi/midi_manipulation.py", line 1, in
import midi
ImportError: No module named midi

I updated the file to read midi_manipulation and it seemed to fix it.

Thought I would mention in case this was wrong.

Welcome thoughts on how to resolve.
Cheers

module no attribute mul?!

here's the code i got
Traceback (most recent call last):
File "rbm_chords.py", line 95, in
W_adder = tf.mul(lr/size_bt, tf.sub(tf.matmul(tf.transpose(x), h), tf.matmul(tf.transpose(x_sample), h_sample)))
AttributeError: 'module' object has no attribute 'mul'

How to convert midi to msgpack please?

Hello

in file rbm_chords.py
songs = get_songs('Pop_Music_Midi') #These songs have already been converted from midi to msgpack

How to convert midi to msgpack please?

Many thanks to all,
Dorje

AttributeError: module 'tensorflow' has no attribute 'placeholder'

You will get this error if using TensorFlow 2.x:

Traceback (most recent call last):
File "C:\Users\y\AppData\Local\Programs\Python\Python37\music-generator-1\rbm_chords.py", line 59, in
x = tf.placeholder(tf.float32, [None, n_visible], name="x")
AttributeError: module 'tensorflow' has no attribute 'placeholder'

I fixed it by changing: rbm_chords.py:

#import tensorflow as tf

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.