original link: http://www.cnblogs.com/learn-to-rock/p/5677458.htmlaccidentally on the internet to see a I am very interested in the project Magenta, with TensorFlow let neural network automatically create music. The vernacular is: You can use some of the style of music to make models, and then use the training model of the new music processing to create new music. spent a half-time to finally have the results, very happy, but also this half-day experience to share, can let everyone save some time is also my contribution to the community to make it. feel Google's black technology againI hope you will like my chinglish. --First step, install, tool ready! --operating system: Please abandon windows, choose Linux or Unix It's really no use trying to run on Windows right now, just beginning to try out new technology, applying container--docker, but without Windows professional HyperV, you won't be able to install Docker successfully.
Installing on Linux1. BASIC Programming Environmentpython 2.7/3.* can use the TensorFlow APIJava Environment: JDKcan be installed with Apt-getadd Java to the environment by the way, modify BASHRC in Linux. Path path= "$PATH: $HOME/bin"This Part I will not repeat, anyway you want this will not Baidu basically say goodbye programming. 2. Project MagentaHttps://github.com/tensorflow/magenta.git 3. Installation of TensorFlowhttps://www.tensorflow.org/versions/r0.9/get_started/os_setup.htmlThis is done by the members:$ sudo apt-get install Python-pip python-dev$ sudo pip install--upgrade https://storage.googleapis.com/tensorflow/linux/cpu/ TENSORFLOW-0.9.0-CP27-NONE-LINUX_X86_64.WHL you may encounter version dependency issues in this process, and you can try to refer to the following procedure:sudo aptitude install Python-dev 4. Installing Bazelhttps://github.com/bazelbuild/bazel/releases/tag/0.3.0Select the appropriate versionhttp://www.bazel.io/docs/install.html In the face of fresh things, please listen to your biological parents, please read the Official document: Http://www.bazel.io/docs/install.html Note: You can use the wget when Linux download
--Step two: Start writing! --commands can be saved as bash format for later use, I was in four steps, compiled 4 batch files,Please be careful to modify the path//Halfway through the need to download something from GitHub, do not create what is, so please keep the network unblocked 1. First bash: Create a Melody database
#!/bin/bash # #创建旋律数据库 Midi_directory=/home/liukun/tensorflow/magenta/music/train # Here's your file path. Sequences_tfrecord=/home/liukun/tensorflow/magenta/music/train/notesequences.tfrecord Bazel Run //magenta/scripts:convert_midi_dir_to_note_sequences--\--midi_dir= $MIDI _ DIRECTORY \ --output_file= $SEQUENCES _tfrecord \ --recursive
2. Second bash: Extract the Training sample
# Tfrecord file containing notesequence protocol buffers from convert_midi_dir_to_note_sequences.py. Sequences_tfrecord=/home/liukun/tensorflow/magenta/music/train/notesequences.tfrecord # Tfrecord file that TensorFlow ' s sequenceexample protos would be written to. This is the training dataset. Train_data=/home/liukun/tensorflow/magenta/music/train/training_melodies.tfrecord # Optional Evaluation DataSet. Also, a Tfrecord file containing sequenceexample protos. Eval_data=/home/liukun/tensorflow/magenta/music/eval_melodies.tfrecord # Fraction of input data that would be written to the Eval dataset (if Eval_output flag is set). eval_ratio=0.10 Bazel Run//magenta/models/basic_rnn:basic_rnn_create_dataset--\ --input= $SEQUENCES _tfrecord \ --train_output= $TRAIN _data \ --eval_output= $EVAL _data \ --eval_ratio= $EVAL _ratio
problem: A local github saved account may be wrong because it is different from the remote GitHub account, my root account is bound to GitHub users, which thought today ..... So don't use sudo. 3. Third bash: Train the neural network model, the most time-consuming!!!
#首先compile basic_rnn tool Bazel build//magenta/models/basic_rnn:basic_rnn_train Train_data=/home/liukun/tensorflow/magenta/music/train/training_melodies.tfrecord #训练模型, of which "rnn_layer_ Size "is the number of layers in a neural network and can be customized /home/liukun/tensorflow/magenta/bazel-bin/magenta/models/basic_rnn/basic_rnn_train --experiment_run_dir=/home/liukun/tensorflow/magenta/music--sequence_example_file= $TRAIN _data--eval=false-- Hparams= ' {"rnn_layer_sizes": [+]} '--num_training_steps=2000
in order to save time, I only trained 2000 times, so ... 4. Fourth bash: Create a new melody!
# #生成旋律 #指定测试旋律的文件地址 Primer_path=/home/liukun/tensorflow/magenta/music/origional/canon.mid #注意这里是绝对地址, only one song can be specified # NUM_OUTPUTS Specifies the number of tracks to be generated Bazel Run//magenta/models/basic_rnn:basic_rnn_generate--\ --experiment_run_dir=/home/liukun/tensorflow/magenta/magenta/models \ --hparams= ' {"rnn_layer_sizes": [+]} ' \ --primer_midi= $PRIMER _path \ --output_dir=/home/liukun/tensorflow/magenta/music/generate \ --num_steps=64 \ --num_outputs=3
waiting seems so long. The execution of the program ended, I can't resist a curious heart, full of anticipation to open the newly born in the world's new art, tears, this fusion of the 21st century's most cutting-edge technology worksMelody played, Real TM ... Not nice. The
old driver left a message:The main need to modify is the path of the file. My train of thought uses some style of prominent songs as the training set, then the simple melody processing, this should be more able to reflect the effect. Reminder: File path to use absolute path, although do not know what to ask, but do not make an error, prompt permission problem. Google discussion group on this project:Https://groups.google.com/a/tensorflow.org/forum/#!forum/magenta-discuss Finally, I wish you a happy holiday! 5555 half a day to brush the problem ~ ~ ~ Author Blog: http://www.cnblogs.com/learn-to-rock/
Reprint please pay attention to the layout, do not make an ugly ratio!!! Project file directory tree for reference:
. ├──bazel installer│ ├──bazel│ └──bazel-0.3.0-installer-linux-x86_64.sh├──magenta│ & nbsp ├──1.sh│ ├──1.sh~│ ├──2.sh│ ├──2.sh~│ ├──3.sh│ ├──3.sh~ │ ├──4.sh│ ├──4.sh~│ ├──bazel-bin-/home/liukun/.cache/bazel/_bazel_liukun /ebbbbefb206fd0a3aa08c53b60fb3fee/execroot/magenta/bazel-out/local-opt/bin│ ├──bazel-genfiles/ home/liukun/.cache/bazel/_bazel_liukun/ebbbbefb206fd0a3aa08c53b60fb3fee/execroot/magenta/bazel-out/local-opt/ Genfiles│ ├──bazel-magenta-/home/liukun/.cache/bazel/_bazel_liukun/ Ebbbbefb206fd0a3aa08c53b60fb3fee/execroot/magenta│ ├──bazel-out-/home/liukun/.cache/bazel/_ Bazel_liukun/ebbbbefb206fd0a3aa08c53b60fb3fee/execroot/magenta/bazel-out│ ├──bazel-testlogs/ Home/liukun/.cache/bazel/_bazel_liukun/ebbbbefb206fd0a3aa08c53b60fb3fee/execroot/magenta/bazel-out/local-opt/testlogs│ ├──__init__.py│ ├──license│ ├──magenta│ │ ├──1.sh│ │ ├──2.sh~│ │ ├──build│ │ ├──__init __.py│ │ ├──__init__.pyc│ │ ├──lib│ │ │ ├──BUILD│ │ │ ├──__init__.py│ │ │ ├──__init__.pyc│ │ │ ├──melodies_lib.py│ │ │ ├──melodies_lib_test.py│ │ │ ├──midi_io.py│ │ │ ├──midi_io.pyc│ │ │ ├──midi_io_test.py│ │ │ ├──note_sequence_io.py│ │ │ ├──note_sequence_io_test.py│ │ │ ├──sequence_example_lib.py│   │ │ ├──sequence_to_melodies.py│ │ │ ├──sequence_to_ melodies_test.py│ │ │ └──tf_lib.py│ │ ├──models│ & nbsp │ │ ├──attention_rnn│ │ │ │ ├──attention_rnn _create_dataset.py│ │ │ │ ├──attention_rnn_encoder_decoder.py│ │ │ │ ├──attention_rnn_generate.py│ │ │ │ ├──attention_rnn_graph.py│ │ │ │ ├── attention_rnn_train.py│ │ │ │ ├──build│ │ │& nbsp; │ └──readme.md│ │ │ ├──basic_rnn│ │ │ │ ├──basic_rnn_create_dataset.py│&nbsP; │ │ │ ├──basic_rnn_encoder_decoder.py│ │ │ │ ├──basic_rnn_encoder_decoder.pyc│ │ │ │ ├──basic_rnn_generate.py│ │ │ │ ├──basic_rnn_graph.py│ │ │ │ ├──basic_rnn_graph.pyc│ │ │ │ ├──basic_rnn_train.py│ │ │ │ ├──BUILD│ │ │ │ ├──readme.md│ │ │ │ └──run_basic_ Rnn_train.sh│ │ │ ├──lookback_rnn│ │ │ │ ├──build│ │ │ │ ├──lookback_rnn_create_dataset.py│ │ │ │ ├──lookback_rnn_encoder_decoder.py│ │ │ │ ├──lookback_rnn_generate.py│ │ │ │ ├──lookback_rnn_graph.py│ │ │ │ ├──lookback_rnn_train.py│ │ │ │ └──readme.md│ │ │ └──shared│ │ │ ├──build│ │ │ & nbsp ├──melody_rnn_create_dataset.py│ │ │ ├──melody_rnn_generate.py│ │& Nbsp; │ ├──melody_rnn_train.py│ │ │ ├──primer.mid│ &n Bsp │ │ └──readme.md│ │ ├──protobuf│ │ │ &n Bsp ├──build│ │ │ └──music.proto│ │ ├──reviews│ │ │ ├── assets│ │ │ │ ├──attention_interpolation.png│ │ │ │ ├──attention_parameterization.png│ │ │ │ ├──color-preserving-ny.jpg│ │ │ │ ├──diagram.png│ │ │ │ ├──generation.gif│ │ │ │& Nbsp; ├──mnist_generation.png│ │ │ │ ├──pixelrnn_figure6.png│ │ │ │ ├──pixelrnn_full_context.png│ │ │ │ ├──pixelrnn_masks_a.png│ │ │ │ ├── pixelrnn_masks_b.png│ │ │ │ ├──pixelrnn_masks_highlevel.png│ │ │ │ ├──svhn_generation.png│ │ │ │ └──tubingen-starry-night.jpg│ │ │ ├── draw.md│ │ │ ├──pixelrnn.md│ │ │ ├── readme.md│ │ │ ├──styletransfer.md│ │ │ └── Summary_generation_sequences.md│ │ ├──rossini_barbe (2). mid│ │ ├── Rossini_barbe (3) .mid│ │ ├──rossini_barbe.mid│ │ ├──scripts│ │ │ ├──build│ │ │ ├──convert_midi_dir_to_note_ Sequences.py│ │ │ └──convert_midi_dir_to_note_sequences_test.py│ │ └──testdata│ │ ├──build│ │ ├──example_complex.mid│ │ ├──example.mid│ │ └──notesequences.tfrecord│ ├──music│ │ ├──eval_melodies.tfrecord│ │ ├──generate│ │ │ ├──2016-07-16_224233_1.mid│ │ & nbsp │ ├──2016-07-16_224233_2.mid│ │ │ └──2016-07-16_224233_3.mid│ │ ├──origional│ │ │ └──canon.mid│ │ & nbsp └──train│ │ ├──basket.mid│ │ ├──detective.mid│ │&nb Sp; ├──notesequences.tfrecord│ │ └──training_melodies.tfrecord│ ├──pr Etty_midi. Build│ ├──python_midi. Build│ ├──readme.md│ ├──six. build│ ├──tools│ │ └──bazel.rc│ ├──util│ │ └──python│ │ └──build│ ├──workspace│ └──workspace~
"Magenta project" to teach you to create music with TensorFlow neural network