Issues with reading Midi files

581 views
Skip to first unread message

Gunn Rouche

unread,
Feb 16, 2017, 4:31:13 AM2/16/17
to Magenta Discuss
Hi guys,
I have been testing out Magenta music, very cool (came up with this in about 20mins: https://m.facebook.com/story.php?story_fbid=10206916021379337&id=1841988303&ref=bookmarks)

The piece above was generated using the _rnn files, BUT  when I try to train the AI on my own midi set, it doesnt seem to work.
Below are the various code and resultant error messages I get:

convert_dir_to_note_sequences \
  --input_dir=/magenta-data/midi-test.mid \
  --output_file=/tmp/notesequences.tfrecord \
  --recursive

ERROR
INFO:tensorflow:Converting files in '/magenta-data/midi-test.mid/'.
Traceback (most recent call last):
  File "/usr/local/bin/convert_dir_to_note_sequences", line 11, in <module>
    sys.exit(console_entry_point())
  File "/usr/local/lib/python2.7/dist-packages/magenta/scripts/convert_dir_to_note_sequences.py", line 185, in console_entry_point
    tf.app.run(main)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "/usr/local/lib/python2.7/dist-packages/magenta/scripts/convert_dir_to_note_sequences.py", line 179, in main
    FLAGS.recursive)
  File "/usr/local/lib/python2.7/dist-packages/magenta/scripts/convert_dir_to_note_sequences.py", line 73, in convert_directory
    files_in_dir = tf.gfile.ListDirectory(os.path.join(dir_to_convert))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/lib/io/file_io.py", line 399, in list_directory
    raise errors.NotFoundError(None, None, "Could not find directory")
tensorflow.python.framework.errors_impl.NotFoundError: Could not find directory


I am able to convert midi to sequence by using this:

melody_rnn_create_dataset \
--config=lookback_rnn \
--input=/tmp/notesequences.tfrecord \
--output_dir=/tmp/melody_rnn/sequence_examples \
--eval_ratio=0.10

THEN train the AI using this:

melody_rnn_train \
--config=lookback_rnn \
--run_dir=/tmp/melody_rnn/logdir/run6 \
--sequence_example_file=/tmp/melody_rnn/sequence_examples/training_melodies.tfrecord \
--hparams="{'batch_size':64,'rnn_layer_sizes':[64,64]}" \
--num_training_steps=20000

AND THEN, if I run this code - it works
melody_rnn_generate \
--config=lookback_rnn \
--run_dir=/tmp/melody_rnn/logdir/run6 \
--output_dir=/magenta-data/lookback_rnn/generated1 \
--num_outputs=3 \
--num_steps=700 \
--hparams="{'batch_size':64,'rnn_layer_sizes':[64,64]}" \
--primer_melody="[64, -2, -2, -2, 60, -2, -2, -2, 64, -2, -2, -2]"

HOWEVER, when I try to generate the melody from Midi I get this (I assume because of the error at the very start of the process)

# melody_rnn_generate \
--config=lookback_rnn \
--run_dir=/tmp/melody_rnn/logdir/run6 \
--output_dir=/magenta-data/lookback_rnn/generated1 \
--num_outputs=10 \
--num_steps=800 \
--hparams="{'batch_size’:64,’rnn_layer_sizes':[64,64]}" \
--primer_midi=/magenta-data/midi-test.mid> > > > > > >

Traceback (most recent call last):
  File "/usr/local/bin/melody_rnn_generate", line 11, in <module>
    sys.exit(console_entry_point())
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 258, in console_entry_point
    tf.app.run(main)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 254, in main
    run_with_flags(generator)
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 173, in run_with_flags
    primer_sequence = magenta.music.midi_file_to_sequence_proto(primer_midi)
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/midi_io.py", line 281, in midi_file_to_sequence_proto
    midi_as_string = f.read()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/lib/io/file_io.py", line 106, in read
    self._preread_check()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/lib/io/file_io.py", line 73, in _preread_check
    compat.as_bytes(self.__name), 1024 * 512, status)
  File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__
    self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/errors_impl.py", line 469, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.NotFoundError: /magenta-data/midi-test.mid


Welcome any Ideas on how to fix


Cheers
GR



Curtis "Fjord" Hawthorne

unread,
Feb 16, 2017, 1:21:00 PM2/16/17
to Gunn Rouche, Magenta Discuss
Hi Gunn,

I think the problems are with the paths you're giving the commands:

For convert_dir_to_note_sequences, I think you're giving the path to an individual midi file instead of a directory containing midi files: --input_dir=/magenta-data/midi-test.mid

For melody_rnn_generate, based on the output of the command, it looks like the path to your primer midi file (/magenta-data/midi-test.mid) doesn't exist.

Could you double-check the paths and try again?


--
Magenta project: magenta.tensorflow.org
To post to this group, send email to magenta...@tensorflow.org
To unsubscribe from this group, send email to magenta-discu...@tensorflow.org
---
You received this message because you are subscribed to the Google Groups "Magenta Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to magenta-discu...@tensorflow.org.

Gunn Rouche

unread,
Feb 16, 2017, 7:00:05 PM2/16/17
to Magenta Discuss, gunn....@gmail.com
You sir, are a man above men.
This has sorted out the convert / train stages (Thank you) BUT I am stil getting an error when I try to generate the midi from a specific midi file (the file is definitely in the right place - although it has polyphonic chords in the track, will that matter?):

melody_rnn_generate \
--config=lookback_rnn \
--run_dir=/tmp/melody_rnn/logdir/run7 \
--output_dir=/magenta-data/lookback_rnn/generated2 \
--num_outputs=3 \

--num_steps=800 \
--hparams="{'batch_size’:64,’rnn_layer_sizes':[64,64]}" \
--primer_midi=/magenta-data/midi-test.mid> > > > > > >
INFO:tensorflow:hparams = {'rnn_layer_sizes': [128, 128], 'decay_rate': 0.95, 'dropout_keep_prob': 1.0, 'batch_size\xe2\x80\x99:64,\xe2\x80\x99rnn_layer_sizes': [64, 64], 'batch_size': 1, 'decay_steps': 1000, 'clip_norm': 5, 'initial_learning_rate': 0.01, 'skip_first_n_losses': 0}
WARNING:tensorflow:<tensorflow.python.ops.rnn_cell.BasicLSTMCell object at 0x7f7c4ed68290>: Using a concatenated state is slower and will soon be deprecated.  Use state_is_tuple=True.
WARNING:tensorflow:<tensorflow.python.ops.rnn_cell.BasicLSTMCell object at 0x7f7c4ecda790>: Using a concatenated state is slower and will soon be deprecated.  Use state_is_tuple=True.
INFO:tensorflow:Checkpoint used: /tmp/melody_rnn/logdir/run7/train/model.ckpt-1000

Traceback (most recent call last):
  File "/usr/local/bin/melody_rnn_generate", line 11, in <module>
    sys.exit(console_entry_point())
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 258, in console_entry_point
    tf.app.run(main)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 254, in main
    run_with_flags(generator)
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 225, in run_with_flags
    generated_sequence = generator.generate(input_sequence, generator_options)
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/sequence_generator.py", line 203, in generate
    self.initialize()
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/sequence_generator.py", line 149, in initialize
    self._model.initialize_with_checkpoint(checkpoint_file)
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/model.py", line 63, in initialize_with_checkpoint
    saver.restore(self._session, checkpoint_file)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1388, in restore
    {self.saver_def.filename_tensor_name: save_path})
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 766, in run
    run_metadata_ptr)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 964, in _run
    feed_dict_string, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1014, in _do_run
    target_list, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1034, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [128,40] rhs shape= [64,40]
     [[Node: save/Assign_5 = Assign[T=DT_FLOAT, _class=["loc:@fully_connected/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/cpu:0"](fully_connected/weights, save/RestoreV2_5)]]

Caused by op u'save/Assign_5', defined at:

  File "/usr/local/bin/melody_rnn_generate", line 11, in <module>
    sys.exit(console_entry_point())
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 258, in console_entry_point
    tf.app.run(main)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 254, in main
    run_with_flags(generator)
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 225, in run_with_flags
    generated_sequence = generator.generate(input_sequence, generator_options)
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/sequence_generator.py", line 203, in generate
    self.initialize()
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/sequence_generator.py", line 149, in initialize
    self._model.initialize_with_checkpoint(checkpoint_file)
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/model.py", line 60, in initialize_with_checkpoint
    saver = tf.train.Saver()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1000, in __init__
    self.build()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1030, in build
    restore_sequentially=self._restore_sequentially)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 624, in build
    restore_sequentially, reshape)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 373, in _AddRestoreOps
    assign_ops.append(saveable.restore(tensors, shapes))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 130, in restore
    self.op.get_shape().is_fully_defined())
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 47, in assign
    use_locking=use_locking, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2240, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1128, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [128,40] rhs shape= [64,40]
     [[Node: save/Assign_5 = Assign[T=DT_FLOAT, _class=["loc:@fully_connected/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/cpu:0"](fully_connected/weights, save/RestoreV2_5)]]


Thanks for helping me with this, am still getting my head around it all.

Cheers
GR

Gunn Rouche

unread,
Feb 19, 2017, 1:59:54 PM2/19/17
to Magenta Discuss
Evening All,

Would anyone be so kind to take a look at the below for me, super appreciated.

Cheers
GR

Gunn Rouche

unread,
Feb 19, 2017, 2:01:18 PM2/19/17
to Magenta Discuss, gunn....@gmail.com
Hi Curtis, thanks for your help with my query - any thoughts on the new issue it has thrown up?

Cheers
GR

On Thursday, February 16, 2017 at 6:21:00 PM UTC, Curtis Hawthorne wrote:

Ian Simon

unread,
Feb 21, 2017, 1:30:41 PM2/21/17
to Gunn Rouche, Magenta Discuss
Hi Gunn, it looks like there's a shape mismatch between the saved checkpoint in your run_dir and the hparams you're passing.  This seems to be because you're using two different single-quote characters inside the hparams argument: ' and ’.  Can you try using only '?

-Ian

Gunn Rouche

unread,
Feb 22, 2017, 6:17:33 AM2/22/17
to Magenta Discuss, gunn....@gmail.com
Sigh... I knew it would be something simple. THANK YOU.
It works now.... BUT... (haha there's always a but)...

I tried a few tests and it doesnt seem to be generating any new 'content' from the midi file.

Test 1 - using single line of midi
When I primed magenta with a single line of midi, the resultant 3 x midi files (I requested 3 as the output number) came out exactly the same as each other, and the primer file.

Test 2 - Two lines of midi
When I added a new track with a different pattern in Logic Pro X (I simply took the midi file from the first track, and created a new track with some chords) I got this error - (does this mean Magenta cannot ready polyphonic midi files?)

# melody_rnn_generate \
--config=lookback_rnn \
--run_dir=/tmp/melody_rnn/logdir/run8 \
--output_dir=/magenta-data/lookback_rnn/generated2 \
--num_outputs=3 \
--num_steps=500 \

--hparams="{'batch_size':64,'rnn_layer_sizes':[64,64]}" \
--primer_midi=/magenta-data/test-2-source-midi.mid> > > > > > >
INFO:tensorflow:hparams = {'rnn_layer_sizes': [64, 64], 'decay_rate': 0.95, 'dropout_keep_prob': 1.0, 'batch_size': 1, 'decay_steps': 1000, 'clip_norm': 5, 'initial_learning_rate': 0.01, 'skip_first_n_losses': 0}
WARNING:tensorflow:<tensorflow.python.ops.rnn_cell.BasicLSTMCell object at 0x7f75bb764e50>: Using a concatenated state is slower and will soon be deprecated.  Use state_is_tuple=True.
WARNING:tensorflow:<tensorflow.python.ops.rnn_cell.BasicLSTMCell object at 0x7f75b8b27790>: Using a concatenated state is slower and will soon be deprecated.  Use state_is_tuple=True.
INFO:tensorflow:Checkpoint used: /tmp/melody_rnn/logdir/run8/train/model.ckpt-1000

Traceback (most recent call last):
  File "/usr/local/bin/melody_rnn_generate", line 11, in <module>
    sys.exit(console_entry_point())
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 258, in console_entry_point
    tf.app.run(main)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 254, in main
    run_with_flags(generator)
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_generate.py", line 225, in run_with_flags
    generated_sequence = generator.generate(input_sequence, generator_options)
  File "/usr/local/lib/python2.7/dist-packages/magenta/music/sequence_generator.py", line 204, in generate
    return self._generate(input_sequence, generator_options)
  File "/usr/local/lib/python2.7/dist-packages/magenta/models/melody_rnn/melody_rnn_sequence_generator.py", line 85, in _generate
    assert len(extracted_melodies) <= 1
AssertionError

Test 3 - short midi data
For my final test I uploded a very short piece of midi (100 lines) BUT ran the output lines to 800 lines. When the primed midi file had finished and the rest of the track continued - the midi information reverted to the RNN style (i.e. rapid / messy) - did not follow any of the primed rhythm / timing / chord progs etc (basically the same output as if I just use the pre-built RNN files).

QUESTIONS
  1. Am I thinking about priming the wrong way - how much can a track be primed from another track (2 seconds? 20 seconds? 1 minute?)?
  2. How does one control the seemingly random output that occurs when the pre-built RNN files (even after the track has been primed with another file)? i.e. how can we control the pattern / rhythm / chord prog etc?
  3. If the answer to question 2 is defined by the RNN file, how can I create my own RNN files using the same midi files I used to build the dataset in step 1? Is this posisble? Will this change the outcome of my second question?
Cheers all
GR

Gunn Rouche

unread,
Mar 6, 2017, 6:52:09 PM3/6/17
to Magenta Discuss
Hi all, any thoughts on my previous post - is there something i am missing here about training / using midi files to generate sensible outputs?

Welcome any thoughts

Cheers
GR

maninder singh

unread,
Mar 8, 2017, 1:02:10 AM3/8/17
to Gunn Rouche, Magenta Discuss
hello everyone hope you all doing well 
guys i am using linux operating system (ubuntu) forthe magenta im and having issues in training a dataset i've dwonloaded a dataset from internet and after all facing issues in converting into note sequence i've checked the complete path of the imput and output file but the file is not available there  


 im using the following command 



 --input_dir=\home\maninder\Downloads\lmd_full
  --output_file= \home\maninder\Desktop\notesequences.tfrecord
  --recursive 



Cheers
GR

--
Magenta project: magenta.tensorflow.org
To post to this group, send email to magenta...@tensorflow.org
To unsubscribe from this group, send email to magenta-discuss+unsubscribe@tensorflow.org

---
You received this message because you are subscribed to the Google Groups "Magenta Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to magenta-discuss+unsubscribe@tensorflow.org.

Gunn Rouche

unread,
Mar 8, 2017, 3:15:36 AM3/8/17
to Magenta Discuss
Cmon man, your post is unrelated to this thread (and appears under three other threads).

@Moderator: anyway to remove unrelated posts?

Curtis "Fjord" Hawthorne

unread,
Mar 9, 2017, 7:50:49 PM3/9/17
to Gunn Rouche, Magenta Discuss
Hi Gunn,

As you've observed, maintaining long-term coherent structure (e.g., sticking to the same kinds of rhythms and chord progressions) is an area where our models sometimes struggle. You might want to try modifying your training (e.g., larger/smaller networks via different hyperparameters or using a training set restricted to a particular style) and see what results in improved outputs. We'd love to hear what you find!

For a model that can stay within the same chord progression, you might want to check out our "improv" model: https://github.com/tensorflow/magenta/tree/master/magenta/models/improv_rnn It's not yet available in our pip package, but it will be in our next release (or you can use the development environment).

Good luck with your experiments!

-Fjord

Reply all
Reply to author
Forward
0 new messages