Repository: magenta/magenta

Issue:
UnicodeDecodeError  in  MusicVAE 
I try to run the interpolate mode in music_ave model to generate example,  but it is always produce unicodedecode error 
![2018-11-01 18-26-39](https://user-images.githubusercontent.com/35327931/47846950-ae482800-de04-11e8-8358-f0a8f3c0b446.png)
Is it about the my midi example wrong.  I selected two midi exmaple played with three tracks(piano, bass, and drum) and 4 bars long. who know what is wrong about it?


Discussion:
It seems like it's having trouble reading your MIDI file. If you are
willing to send it over, I can have a look.

On Thu, Nov 1, 2018 at 3:38 AM ericosmic <notifications@github.com> wrote:

> I try to run the interpolate mode in music_ave model to generate example,
> but it is always produce unicodedecode error
> [image: 2018-11-01 18-26-39]
> <https://user-images.githubusercontent.com/35327931/47846950-ae482800-de04-11e8-8358-f0a8f3c0b446.png>
> Is it about the my midi example wrong. I selected two midi exmaple played
> with three tracks(piano, bass, and drum) and 4 bars long. who know what is
> wrong about it?
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/magenta/issues/1330>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABCa6M8wffIi9OKNkDXFLtAAjIP6OTMwks5uqs8UgaJpZM4YGKTL>
> .
>

I tried to use two midi files(1 and 2 in attachment) generated by hier-tiro_16bar_sample mode as input file for interpolate mode , but it is reported same problem.  Before that,  I have tried to product two three-tracks midi files (11 & 12 file )from polyphone midi  ,  then it would report  unicodedecode error .   






At 2018-11-06 01:16:45, "Adam Roberts" <notifications@github.com> wrote:
It seems like it's having trouble reading your MIDI file. If you are
willing to send it over, I can have a look.

On Thu, Nov 1, 2018 at 3:38 AM ericosmic <notifications@github.com> wrote:

> I try to run the interpolate mode in music_ave model to generate example,
> but it is always produce unicodedecode error
> [image: 2018-11-01 18-26-39]
> <https://user-images.githubusercontent.com/35327931/47846950-ae482800-de04-11e8-8358-f0a8f3c0b446.png>
> Is it about the my midi example wrong. I selected two midi exmaple played
> with three tracks(piano, bass, and drum) and 4 bars long. who know what is
> wrong about it?
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/magenta/issues/1330>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABCa6M8wffIi9OKNkDXFLtAAjIP6OTMwks5uqs8UgaJpZM4YGKTL>
> .
>


—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
@ericosmic did you solve this problem? Unfortunately your attachments weren't included.
I came across the same problem. I also got the two midi file from generating model, and as I fed them into the interpolate model, it started to produce UnicodeDecodeError
This is an incompatibility issue with Python3. I have a solution and I will patch this later today.

Resolving patch:
diff --git a/magenta/models/music_vae/music_vae_generate.py b/magenta/models/music_vae/music_vae_generate.py
--- a/magenta/models/music_vae/music_vae_generate.py
+++ b/magenta/models/music_vae/music_vae_generate.py
@@ -116,8 +116,8 @@ def run(config_map):
       raise ValueError('Input MIDI 1 not found: %s' % FLAGS.input_midi_1)
     if not os.path.exists(input_midi_2):
       raise ValueError('Input MIDI 2 not found: %s' % FLAGS.input_midi_2)
-    input_1 = mm.midi_to_sequence_proto(tf.gfile.GFile(input_midi_1).read())
-    input_2 = mm.midi_to_sequence_proto(tf.gfile.GFile(input_midi_2).read())
+    input_1 = mm.midi_file_to_note_sequence(input_midi_1)
+    input_2 = mm.midi_file_to_note_sequence(input_midi_2)
 
     def _check_extract_examples(input_ns, path, input_number):
       """Make sure each input returns exactly one example from the converter."""
diff --git a/magenta/models/onsets_frames_transcription/onsets_frames_transcription_create_dataset.py b/magenta/models/onsets_frames_transcription/onsets_frames_transcription_create_dataset.py
--- a/magenta/models/onsets_frames_transcription/onsets_frames_transcription_create_dataset.py
+++ b/magenta/models/onsets_frames_transcription/onsets_frames_transcription_create_dataset.py
@@ -250,13 +250,12 @@ def generate_train_set(exclude_ids):
     for pair in train_file_pairs:
       print(pair)
       # load the wav data
-      wav_data = tf.gfile.Open(pair[0]).read()
+      wav_data = tf.gfile.Open(pair[0], 'rb').read()
       samples = audio_io.wav_data_to_samples(wav_data, FLAGS.sample_rate)
       samples = librosa.util.normalize(samples, norm=np.inf)
 
       # load the midi data and convert to a notesequence
-      midi_data = tf.gfile.Open(pair[1]).read()
-      ns = midi_io.midi_to_sequence_proto(midi_data)
+      ns = midi_io.midi_file_to_note_sequence(pair[1])
 
       splits = find_split_points(ns, samples, FLAGS.sample_rate,
                                  FLAGS.min_length, FLAGS.max_length)
@@ -319,8 +318,7 @@ def generate_test_set():
       wav_data = audio_io.samples_to_wav_data(samples, FLAGS.sample_rate)
 
       # load the midi data and convert to a notesequence
-      midi_data = tf.gfile.Open(pair[1]).read()
-      ns = midi_io.midi_to_sequence_proto(midi_data)
+      ns = midi_io.midi_file_to_note_sequence(pair[1])
 
       velocities = [note.velocity for note in ns.notes]
       velocity_max = np.max(velocities)


Test patch: