Ejemplo n.º 1
0
    def reconstructAudio(self, audios, model_num=None, max_batchs=200):
        with tf.Session() as sess:
            if model_num is not None:
                path = self.modelsPath(model_num)
            else:
                path = self.modelsPath(self._initial_model_num)
            saver = tf.train.Saver()
            saver.restore(sess, path)
            print("Model restored.")

            batches_count = int(len(audios) / self._batch_size)

            reconstructed = StrechableNumpyArray()
            for batch_num in range(min(batches_count, max_batchs)):
                batch_data = audios[batch_num * self._batch_size:batch_num *
                                    self._batch_size + self._batch_size]
                feed_dict = {
                    self._model.input(): batch_data,
                    self._model.isTraining(): False
                }
                reconstructed_input = sess.run(
                    [self._reconstructed_input_data], feed_dict=feed_dict)
                reconstructed.append(np.reshape(reconstructed_input, (-1)))
            reconstructed = reconstructed.finalize()
            output_shape = self._target_model.output().shape.as_list()
            output_shape[0] = -1
            reconstructed_stft = np.reshape(reconstructed, output_shape)
            return reconstructed_stft
    def _reconstruct(self, sess, data_reader, max_steps):
        data_reader.start()
        reconstructed = StrechableNumpyArray()
        out_gaps = StrechableNumpyArray()
        for batch_num in range(max_steps):
            try:
                audio = data_reader.dataOperation(session=sess)
            except StopIteration:
                print("rec End of queue!", batch_num)
                break

            feed_dict = self._feedDict(audio, sess, False)
            reconstructed_input, original = sess.run(
                [self._architecture.output(),
                 self._architecture.target()],
                feed_dict=feed_dict)
            out_gaps.append(np.reshape(original, (-1)))
            reconstructed.append(np.reshape(reconstructed_input, (-1)))

        output_shape = self._architecture.output().shape.as_list()
        output_shape[0] = -1
        reconstructed = reconstructed.finalize()
        reconstructed = np.reshape(reconstructed, output_shape)
        out_gaps = out_gaps.finalize()
        out_gaps = np.reshape(out_gaps, output_shape)

        data_reader.finish()

        return reconstructed, out_gaps
    def reconstructAudio(self, audios, model_num=None, max_batchs=200):
        with tf.Session() as sess:
            if model_num is not None:
                path = self.modelsPath(model_num)
            else:
                path = self.modelsPath(self._initial_model_num)
            saver = tf.train.Saver()
            saver.restore(sess, path)
            print("Model restored.")

            batches_count = int(len(audios) / self._batch_size)

            reconstructed = StrechableNumpyArray()
            for batch_num in range(min(batches_count, max_batchs)):
                batch_data = audios[batch_num * self._batch_size:batch_num *
                                    self._batch_size + self._batch_size]
                feed_dict = {
                    self._model.input(): batch_data,
                    self._model.isTraining(): False
                }
                reconstructed.append(
                    np.reshape(
                        sess.run(self._reconstructed_input_data,
                                 feed_dict=feed_dict), (-1)))
            reconstructed = reconstructed.finalize()
            reconstructed = np.reshape(reconstructed, (-1, 7, 257))
            istft_reconstructed = sess.run(
                self._reconstructedAudio,
                feed_dict={self._specgram: reconstructed})
            return reconstructed, istft_reconstructed
    def _reconstruct(self, sess, data_reader, max_steps):
        data_reader.start()
        reconstructed = StrechableNumpyArray()
        out_gaps = StrechableNumpyArray()
        for batch_num in range(max_steps):
            try:
                sides, gaps = data_reader.dataOperation(session=sess)
            except StopIteration:
                print(batch_num)
                print("rec End of queue!")
                break
            reconstructed_signal = sess.run(self._reconstructedSignal,
                                            feed_dict={
                                                self._sides: sides,
                                                self.gap_data: gaps
                                            })

            # Nati comment: why is this step not done with reconstructed_signal?
            # gap_stft = reconstructed_signal[:, 15:15+7, :]
            gap_stft = tf.abs(self._stft[:, 15:15 + 7, :])

            feed_dict = {
                self._model.input(): reconstructed_signal,
                self._model.isTraining(): False
            }
            reconstructed_input, original = sess.run(
                [self._reconstructed_input_data, gap_stft],
                feed_dict=feed_dict)
            out_gaps.append(np.reshape(original, (-1)))
            reconstructed.append(np.reshape(reconstructed_input, (-1)))

        reconstructed = reconstructed.finalize()
        reconstructed = np.reshape(reconstructed, (-1, 7, 257))
        out_gaps = out_gaps.finalize()
        out_gaps = np.reshape(out_gaps, (-1, 7, 257))

        istft_original = sess.run(self._reconstructedAudio,
                                  feed_dict={self._specgram: out_gaps})
        istft_reconstructed = sess.run(
            self._reconstructedAudio,
            feed_dict={self._specgram: reconstructed})
        data_reader.finish()

        return istft_reconstructed, istft_original
Ejemplo n.º 5
0
    def _reconstruct(self, sess, data_reader, max_steps):
        data_reader.start()
        reconstructed = StrechableNumpyArray()
        out_gaps = StrechableNumpyArray()
        for batch_num in range(max_steps):
            try:
                sides, gaps = data_reader.dataOperation(session=sess)
            except StopIteration:
                print(batch_num)
                print("rec End of queue!")
                break
            reconstructed_signal = sess.run(self._reconstructedSignal,
                                            feed_dict={
                                                self._sides: sides,
                                                self.gap_data: gaps
                                            })
            gap_stft = self._target_model.output()

            feed_dict = {
                self._model.input(): reconstructed_signal,
                self._target_model.input(): reconstructed_signal,
                self._model.isTraining(): False
            }
            reconstructed_input, original = sess.run(
                [self._reconstructed_input_data, gap_stft],
                feed_dict=feed_dict)
            out_gaps.append(np.reshape(original, (-1)))
            reconstructed.append(np.reshape(reconstructed_input, (-1)))

        output_shape = self._target_model.output().shape.as_list()
        output_shape[0] = -1
        reconstructed = reconstructed.finalize()
        reconstructed = np.reshape(reconstructed, output_shape)
        out_gaps = out_gaps.finalize()
        out_gaps = np.reshape(out_gaps, output_shape)

        data_reader.finish()

        return reconstructed, out_gaps
Ejemplo n.º 6
0
    def reconstructAudio(self, aBatchOfSignals, model_num, max_steps=200):
        with tf.Session() as sess:
            path = self.modelsPath(model_num)
            saver = tf.train.Saver()
            saver.restore(sess, path)
            print("Model restored.")
            sess.run([tf.local_variables_initializer()])
            reconstructed = StrechableNumpyArray()
            out_gaps = StrechableNumpyArray()
            input_shape = list(self._architecture.inputShape())
            input_shape[0] = 0
            contexts = np.empty(input_shape)

            for batch_num in range(
                    min(int(len(aBatchOfSignals) / self._batchSize),
                        max_steps)):
                feed_dict = self._feedDict(
                    aBatchOfSignals[batch_num *
                                    self._batchSize:(batch_num + 1) *
                                    self._batchSize], sess, False)
                reconstructed_input, original, context = sess.run(
                    [
                        self._architecture.output(),
                        self._architecture.target(),
                        self._architecture.input()
                    ],
                    feed_dict=feed_dict)
                out_gaps.append(np.reshape(original, (-1)))
                reconstructed.append(np.reshape(reconstructed_input, (-1)))
                contexts = np.concatenate([contexts, context], axis=0)

            output_shape = self._architecture.output().shape.as_list()
            output_shape[0] = -1
            reconstructed = reconstructed.finalize()
            reconstructed = np.reshape(reconstructed, output_shape)
            out_gaps = out_gaps.finalize()
            out_gaps = np.reshape(out_gaps, output_shape)

            return reconstructed, out_gaps, contexts
Ejemplo n.º 7
0
    def _reconstruct(self, sess, data_reader, max_steps):
        data_reader.start()
        reconstructed = StrechableNumpyArray()
        out_gaps = StrechableNumpyArray()
        for batch_num in range(max_steps):
            try:
                sides, gaps = data_reader.dataOperation(session=sess)
            except StopIteration:
                print(batch_num)
                print("rec End of queue!")
                break
            out_gaps.append(np.reshape(gaps, (-1)))

            feed_dict = {self._model.input(): sides, self._model.isTraining(): False}
            reconstructed.append(np.reshape(sess.run(self._reconstructed_input_data, feed_dict=feed_dict), (-1)))
        reconstructed = reconstructed.finalize()
        reconstructed = np.reshape(reconstructed, (-1, self._gap_length))

        out_gaps = out_gaps.finalize()
        out_gaps = np.reshape(out_gaps, (-1, self._gap_length))
        data_reader.finish()

        return reconstructed, out_gaps
Ejemplo n.º 8
0
    def _reconstruct(self, sess, aBatchOfSignals):
        reconstructed = StrechableNumpyArray()
        out_gaps = StrechableNumpyArray()
        input_shape = self._architecture.input().shape.as_list()
        input_shape[0] = 0
        contexts = np.empty(input_shape)

        for batch_num in range(int(len(aBatchOfSignals)/self._batchSize)):
            feed_dict = self._feedDict(aBatchOfSignals[batch_num*self._batchSize:(batch_num+1)*self._batchSize], sess, False)
            reconstructed_input, original, context = sess.run([self._architecture.output(), self._architecture.target(),
                                                      self._architecture.input()],
                                                     feed_dict=feed_dict)
            out_gaps.append(np.reshape(original, (-1)))
            reconstructed.append(np.reshape(reconstructed_input, (-1)))
            contexts = np.concatenate([contexts, context], axis=0)

        output_shape = self._architecture.output().shape.as_list()
        output_shape[0] = (batch_num+1) * self._batchSize
        reconstructed = reconstructed.finalize()
        reconstructed = np.reshape(reconstructed, output_shape)
        out_gaps = out_gaps.finalize()
        out_gaps = np.reshape(out_gaps, output_shape)

        return reconstructed, out_gaps, contexts