美文网首页
如何打印TensorFlow queue

如何打印TensorFlow queue

作者: CristinaXu | 来源:发表于2017-12-26 17:23 被阅读0次

阅读tensorflow脚本的时候,如何打印每一步数据是一个让人头疼的问题。

在此记录一下打印tf.train.slice_input_producer()输出的步骤。

关键步骤在tf.session()里,在传入路径后要初始化coordinator, 启动queue。这点和普通Variable只要run()一下是不一样的。

import tensorflow as tf

truth_filenames_np = ['dir/%d.jpg' % j for j in range(66)]
truth_filenames_tf = tf.convert_to_tensor(truth_filenames_np)
# get the labels
labels = [f.rsplit("/", 1)[1] for f in truth_filenames_np]
labels_tf = tf.convert_to_tensor(labels)

# My list is also already shuffled, so I set shuffle=False
truth_image_name, truth_label = tf.train.slice_input_producer(
    [truth_filenames_tf, labels_tf], shuffle=False)

# # Another key step, where I batch them together
# truth_images_batch, truth_label_batch = tf.train.batch(
#     [truth_image_name, truth_label], batch_size=11)

epochs = 7

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    for i in range(epochs):
        print("Epoch ", i)
        X_truth_batch = truth_image_name.eval()
        X_label_batch = truth_label.eval()
        # Here I display all the images in this batch, and then I check
        # which file numbers they actually are.
        # BUT, the images that are displayed don't correspond with what is
        # printed by X_label_batch!
        print(X_truth_batch)
        print(X_label_batch)
    coord.request_stop()
    coord.join(threads)

输出如下:

Epoch  0
b'dir/0.jpg'
b'1.jpg'
Epoch  1
b'dir/2.jpg'
b'3.jpg'
Epoch  2
b'dir/4.jpg'
b'5.jpg'
Epoch  3
b'dir/6.jpg'
b'7.jpg'
Epoch  4
b'dir/8.jpg'
b'9.jpg'
Epoch  5
b'dir/10.jpg'
b'11.jpg'
Epoch  6
b'dir/12.jpg'
b'13.jpg'

引用自
TF slice_input_producer not keeping tensors in sync

相关文章

  • 如何打印TensorFlow queue

    阅读tensorflow脚本的时候,如何打印每一步数据是一个让人头疼的问题。 在此记录一下打印tf.train.s...

  • 理解TensorFlow的Queue

    这篇文章来说说TensorFlow里与Queue有关的概念和用法。 其实概念只有三个: Queue是TF队列和缓存...

  • iOS perfromSelector 和线程的关系

    perfromSelector:withObject: afterDelay: 问题 为什么不打印3 queue是...

  • TensorFlow写helloworld

    用tensorflow打印输出语句 效果如下:

  • 2018-04-24

    tensorflow常量变量定义 此时的运行结果为: 知道了如何定义常量变量后,如何去打印数据内容呢?这里我们需要...

  • tensorflow读写二进制文件

    tensorflow建议用Dataset取代queue读取数据,Dataset读取数据有占用内存小、方便对数据预处...

  • Tensorflow Debugger 使用时遇到的小问题

    用打印的方式来调试tensorflow实在是太麻烦了,幸运的是,tensorflow 推出了tfdbg,他需要改动...

  • Tensorflow 数据预读取--Queue

    Google开源的深度学习框架Tensorflow在数据预取上做了一些特殊的特征来提高模型训练或者推理的效率,避免...

  • tensorflow的升级与降级

    0、如何查看当前tensorflow版本:  python  import tensorflow as tf   ...

  • GCD1

    1. 创建dispatch_queue_t 需求:我们要打印10000个数字,在打印的同时显示一个红色的视图不使用...

网友评论

      本文标题:如何打印TensorFlow queue

      本文链接:https://www.haomeiwen.com/subject/zzejgxtx.html