Ejemplo n.º 1
0
 def testGenerateAudioSample(self, batch_size, channels=16):
   audio = np.random.randn(batch_size, 1)
   encoding = np.random.randn(batch_size, channels)
   with tf.Graph().as_default(), self.test_session() as sess:
     net = fastgen.load_fastgen_nsynth(batch_size=batch_size)
     sess.run(tf.global_variables_initializer())
     audio_gen = fastgen.generate_audio_sample(sess, net, audio, encoding)
     self.assertEqual(audio_gen.shape, audio.shape)
Ejemplo n.º 2
0
 def testGenerateAudioSample(self, batch_size, channels=16):
   audio = np.random.randn(batch_size, 1)
   encoding = np.random.randn(batch_size, channels)
   with tf.Graph().as_default(), self.test_session() as sess:
     net = fastgen.load_fastgen_nsynth(batch_size=batch_size)
     sess.run(tf.global_variables_initializer())
     audio_gen = fastgen.generate_audio_sample(sess, net, audio, encoding)
     self.assertEqual(audio_gen.shape, audio.shape)
Ejemplo n.º 3
0
def synth_samples(encodings, checkpoint_path="model.ckpt-200000"):
    """Synthesize audio from an array of encodings.
  Args:
    encodings: Numpy array with shape [batch_size, time, dim].
    save_paths: Iterable of output file names.
    checkpoint_path: Location of the pretrained model. [model.ckpt-200000]
    samples_per_save: Save files after every amount of generated samples.
  """
    session_config = tf.ConfigProto(allow_soft_placement=True)
    session_config.gpu_options.allow_growth = True
    with tf.Graph().as_default(), tf.Session(config=session_config) as sess:
        net = load_fastgen_nsynth(batch_size=encodings.shape[0])
        saver = tf.train.Saver()
        saver.restore(sess, checkpoint_path)

        # Get lengths
        batch_size, encoding_length, _ = encodings.shape
        hop_length = Config().ae_hop_length
        total_length = encoding_length * hop_length

        # initialize queues w/ 0s
        sess.run(net["init_ops"])

        # Regenerate the audio file sample by sample
        audio_batch = np.zeros((batch_size, total_length), dtype=np.float32)
        audio = np.zeros([batch_size, 1])

        for sample_i in range(total_length):
            encoding_i = sample_i // hop_length
            audio = generate_audio_sample(sess, net, audio,
                                          encodings[:, encoding_i, :])
            audio_batch[:, sample_i] = audio[:, 0]
            if sample_i % 100 == 0:
                tf.logging.info("Sample: %d" % sample_i)

        return audio_batch
Ejemplo n.º 4
0
 def testLoadFastgenNsynth(self, batch_size):
     with tf.Graph().as_default():
         net = fastgen.load_fastgen_nsynth(batch_size=batch_size)
         self.assertEqual(net['X'].shape, (batch_size, 1))
         self.assertEqual(net['encoding'].shape, (batch_size, 16))
         self.assertEqual(net['predictions'].shape, (batch_size, 256))
Ejemplo n.º 5
0
 def testLoadFastgenNsynth(self, batch_size):
   with tf.Graph().as_default():
     net = fastgen.load_fastgen_nsynth(batch_size=batch_size)
     self.assertEqual(net['X'].shape, (batch_size, 1))
     self.assertEqual(net['encoding'].shape, (batch_size, 16))
     self.assertEqual(net['predictions'].shape, (batch_size, 256))