Repository: magenta/magenta

Issue:
NSynth wavenet:save_embeddings only saves first batch
When I run the command provided in the readme, modified to run on my machine (Ubuntu 14.04 Google Compute Engine with K80):

```
bazel run //magenta/models/nsynth/wavenet:save_embeddings -- \
--checkpoint_path=/home/kyle/magenta/magenta/models/nsynth/wavenet-ckpt/model.ckpt-200000 \
--wavdir=/home/kyle/magenta/magenta/models/nsynth/data/nsynth-test/audio \
--savedir=/home/kyle/magenta/magenta/models/nsynth/data/nsynth-test/embeddings \
--sample_length=5120 \
--batch_size=16
```

Only the first batch of embeddings are saved:

```
kyle@gpu:~/magenta/magenta/models/nsynth/data/nsynth-test/embeddings$ ls
bass_electronic_018-022-100_embeddings.npy  bass_electronic_018-026-127_embeddings.npy
bass_electronic_018-023-025_embeddings.npy  bass_electronic_018-027-075_embeddings.npy
bass_electronic_018-023-075_embeddings.npy  bass_electronic_018-029-025_embeddings.npy
bass_electronic_018-023-127_embeddings.npy  bass_electronic_018-029-075_embeddings.npy
bass_electronic_018-024-025_embeddings.npy  bass_electronic_018-030-050_embeddings.npy
bass_electronic_018-024-100_embeddings.npy  bass_electronic_018-031-025_embeddings.npy
bass_electronic_018-026-025_embeddings.npy  bass_electronic_018-032-025_embeddings.npy
bass_electronic_018-026-075_embeddings.npy  bass_electronic_018-032-127_embeddings.npy
```

But I can see it's processing all the files (I'm embedding the NSynth test dataset files):

```
...
INFO:tensorflow:On file number 4000 (batch 251).
INFO:tensorflow:On file number 4016 (batch 252).
INFO:tensorflow:On file number 4032 (batch 253).
INFO:tensorflow:On file number 4048 (batch 254).
INFO:tensorflow:On file number 4064 (batch 255).
INFO:tensorflow:On file number 4080 (batch 256).
```

Should this script be saving all the embeddings, or do I need to modify it to do that?

Thanks!


Discussion:

Resolving patch:
diff --git a/magenta/models/nsynth/wavenet/save_embeddings.py b/magenta/models/nsynth/wavenet/save_embeddings.py
--- a/magenta/models/nsynth/wavenet/save_embeddings.py
+++ b/magenta/models/nsynth/wavenet/save_embeddings.py
@@ -114,18 +114,19 @@ def is_wav(f):
       batch_number = (start_file / batch_size) + 1
       tf.logging.info("On file number %s (batch %d).", start_file, batch_number)
       end_file = start_file + batch_size
-      files = wavfiles[start_file:end_file]
+      wavefiles_batch = wavfiles[start_file:end_file]
 
       # Ensure that files has batch_size elements.
-      batch_filler = batch_size - len(files)
-      files.extend(batch_filler * [files[-1]])
+      batch_filler = batch_size - len(wavefiles_batch)
+      wavefiles_batch.extend(batch_filler * [wavefiles_batch[-1]])
 
-      wavdata = np.array([utils.load_wav(f)[:sample_length] for f in files])
+      wavdata = np.array(
+          [utils.load_wav(f)[:sample_length] for f in wavefiles_batch])
 
       try:
         encoding = sess.run(
             graph_encoding, feed_dict={wav_placeholder: wavdata})
-        for num, (wavfile, enc) in enumerate(zip(wavfiles, encoding)):
+        for num, (wavfile, enc) in enumerate(zip(wavefiles_batch, encoding)):
           filename = "%s_embeddings.npy" % wavfile.split("/")[-1].strip(".wav")
           with tf.gfile.Open(os.path.join(savedir, filename), "w") as f:
             np.save(f, enc)


Test patch: