sess.run(Tensor())什么都不做

时间:2016-12-22 04:55:15

标签: python tensorflow

我试图用存储在TFRecords中的数据来提供我的神经网络。与tensorflow网页上的内容类似,使用 inputs()提取数据。它返回的数据是两个Tensors。当我尝试 eval() Tensors以便我可以使用feed_dict通过我的模型发送它们时,我的计算机只是坐着而什么都不做。代码没有返回错误,我的系统监视器让我相信除了我的GPU ram几乎已满之外什么都没有发生。

image = tf.placeholder("float32", [None, 30000])

image_batch, label_batch = inputs(train_dir, True, batch_size, hm_epochs, one_hot_labels=True)
print(image_batch)
with tf.Session().as_default() as sess:
    tf.global_variables_initializer().run()
    results = sess.run(image_batch)
print(results)


I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
Tensor("input/shuffle_batch:0", shape=(100, 30000), dtype=float32)
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: GeForce GTX 960
major: 5 minor: 2 memoryClockRate (GHz) 1.342
pciBusID 0000:01:00.0
Total memory: 3.94GiB
Free memory: 3.38GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 960, pci bus id: 0000:01:00.0)

**编辑:**我的输入功能。

def inputs(train_dir, train, batch_size, num_epochs, one_hot_labels=False):

if not num_epochs: num_epochs = None
filename = os.path.join(train_dir,
                        TRAIN_FILE if train else VALIDATION_FILE)

with tf.name_scope('input'):
    filename_queue = tf.train.string_input_producer(
        [filename], num_epochs=num_epochs)

    image, label = read_and_decode(filename_queue)

    if one_hot_labels:
        label = tf.one_hot(label, 2, dtype=tf.int32) 

    example_batch, label_batch = tf.train.shuffle_batch(
        [image, label], batch_size=batch_size, num_threads=1,
        capacity=1000,
        # Ensures a minimum amount of shuffling of examples.
        min_after_dequeue=10)

return example_batch, label_batch

1 个答案:

答案 0 :(得分:3)

TL; DR :在初始化变量之后,在尝试评估input_batch之前尝试添加以下行:

tf.train.start_queue_runners(sess)

如果没有看到inputs()的实现,很难确定,但张量名称"input/shuffle_batch"表明函数正在使用tf.train.shuffle_batch()函数构建输入。

许多用于输入处理的TensorFlow函数在内部创建预取队列,包括tf.train.shuffle_batch()。这些预取队列最初为空,并且可能阻止您的sess.run(input_batch)调用,等待将元素放入这些队列中。目前,这通常发生的方式是使用“队列运行程序线程”,这是在您调用tf.train.start_queue_runners()时启动的一个或多个后台线程的名称。

这是TensorFlow更复杂的领域之一,我们正在努力改进。与此同时,您可能会发现threading and queues in TensorFlow上的文档很有用。