代码之家  ›  专栏  ›  技术社区  ›  quant

如何检查tf.estimator.inputs.numpy_input_fn的内容?

  •  2
  • quant  · 技术社区  · 8 年前

    我想在一组数据上反复训练我的tensorflow图,我想 tf.estimator.inputs.numpy_input_fn 可能是我要找的。我发现批处理大小、重复、epoch和迭代器之间的区别令人难以置信地混淆,所以我开始尝试检查数据集的内容,试图找出实际发生的情况。然而,每当我尝试这样做我的程序只是挂起。

    下面是我为重现这一点而提出的最小的测试用例:

    import tensorflow as tf
    import numpy
    
    class TestMock(tf.test.TestCase):
        def test(self):
            inputs = numpy.array(range(10))
            targets = numpy.array(range(10,20))
    
            input_fn = tf.estimator.inputs.numpy_input_fn(
                x=inputs,
                y=targets,
                batch_size=1,
                num_epochs=2,
                shuffle=False)
    
            print input_fn()
            with self.test_session() as sess:
                # sess.run(input_fn()[0]) # it'll hang if I run this
                pass
    
    if __name__ == '__main__':
        tf.test.main()
    

    这个程序输出

    (<tf.Tensor 'fifo_queue_DequeueUpTo:1' shape=(?,) dtype=int64>, <tf.Tensor 'fifo_queue_DequeueUpTo:2' shape=(?,) dtype=int64>)
    

    这看起来很合理,但只要我试着运行 sess.run 行,我的程序冻结,我必须终止进程。我在这里做错什么了?

    我想做的是确保我正在处理的数据实际上是我所认为的,但是我认为我没有能力去检查数据。

    1 回复  |  直到 8 年前
        1
  •  2
  •   Vijay Mariappan    8 年前

    从上面的打印语句我们可以推断出 input_fn 收益率 queue ops ,我们需要使用 start_queue_runners and Coordinator :

     features_op, labels_op = input_fn()
     with tf.Session() as sess:
         # initialise and start the queues.
         sess.run(tf.local_variables_initializer())
    
         coordinator = tf.train.Coordinator()
         _ = tf.train.start_queue_runners(coord=coordinator)
    
        print(sess.run([features_op, labels_op]))
    
        #[array([0]), array([10])]
    
    推荐文章