TensorFlowSharp icon indicating copy to clipboard operation
TensorFlowSharp copied to clipboard

Ensure that you have run the initializer operation for this iterator before getting the next element

Open JunGenius opened this issue 6 years ago • 0 comments

Hello, {"GetNext() failed because the iterator has not been initialized. Ensure that you have run the initializer operation for this iterator before getting the next element.\n\t [[{{node ds/next}} = IteratorGetNextoutput_shapes=[[?,48000], [?,2]], output_types=[DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]"}

` C#

   var runner = _session.GetRunner();          

        runner.AddInput(_graph["ph/frames"][0], x)
                .AddInput(_graph["ph/labels"][0], y)
                .AddInput(_graph["ph/n_shuffle"][0], ph_n_shuffle)
                .AddInput(_graph["ph/n_repeat"][0], ph_n_repeat)
                .AddInput(_graph["ph/n_batch"][0], ph_n_batch)
                .Fetch(_graph["net/layers/logits/dense/Softmax"][0]);

        var output = runner.Run();

`

`

Python:

  with graph.as_default():

    saver = tf.train.import_meta_graph(checkpoint_path + '.meta')

    x = graph.get_tensor_by_name(vocab['x'])
    y = graph.get_tensor_by_name(vocab['y'])
    init = graph.get_operation_by_name(vocab['init'])
    logits = graph.get_tensor_by_name(vocab['logits'])
    ph_n_shuffle = graph.get_tensor_by_name(vocab['n_shuffle'])
    ph_n_repeat = graph.get_tensor_by_name(vocab['n_repeat'])
    ph_n_batch = graph.get_tensor_by_name(vocab['n_batch'])
    sr = vocab['sample_rate']

    with tf.Session() as sess:

        saver.restore(sess, checkpoint_path)

        for file in files:

            print('processing {}'.format(file), flush=True)

            if os.path.exists(file):
                sound, _ = audio_from_file(file, sr=sr)
                input = audio_to_frames(sound, x.shape[1])
                labels = np.zeros((input.shape[0],), dtype=np.int32)
                sess.run(init,
                         feed_dict={x: input, y: labels, ph_n_shuffle: 1, ph_n_repeat: 1, ph_n_batch: n_batch})
                count = 0
                n_total = input.shape[0]
                while True:
                    try:
                        output = sess.run(logits)
                        labels[count:count + output.shape[0]] = np.argmax(output, axis=1)
                        count += output.shape[0]
                        print('{:.2f}%\r'.format(100 * (count / n_total)), end='', flush=True)
                    except tf.errors.OutOfRangeError:
                        break
                noise = input[np.argwhere(labels == 0), :].reshape(-1, 1)
                speech = input[np.argwhere(labels == 1), :].reshape(-1, 1)
                name, ext = os.path.splitext(file)
                audio_to_file(os.path.join(name + '.speech' + ext), speech, sr)
                audio_to_file(os.path.join(name + '.noise' + ext), noise, sr)

            else:
                print('skip [file not found]')

` how to initialize an iterator?Thank you very much.

JunGenius avatar Jun 26 '19 17:06 JunGenius