简体   繁体   English

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

[英]sess.run(Tensor()) does nothing

I am attempting to feed my neural net with data stored in a TFRecords. 我试图用存储在TFRecords中的数据喂我的神经网络。 The data is extracted using inputs() similarly to what is on the tensorflow webpage. 类似于tensorflow网页上的内容,使用input()提取数据。 The data it returns are two Tensors. 它返回的数据是两个张量。 When I attempt to eval() the Tensors so that I can send them through my model with feed_dict, my computer just sits and does nothing. 当我尝试对Tensors进行eval()以便可以使用feed_dict通过模型发送它们时,我的计算机只是静止不动。 The code does not return an error, my system monitor leads me to believe nothing is going on other than my GPU ram is almost full. 该代码未返回错误,我的系统监视器使我相信,除了GPU内存几乎已满之外,什么都没发生。

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)

**edit:**My inputs function. **编辑:**我的输入功能。

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

TL;DR: Try adding the following line after you initialize your variables, and before trying to evaluate input_batch : TL; DR:在初始化变量之后和尝试评估input_batch之前,尝试添加以下行:

tf.train.start_queue_runners(sess)

It is difficult to be certain without seeing the implementation of inputs() , but the tensor name "input/shuffle_batch" suggests that the function is building the inputs using the tf.train.shuffle_batch() function. 很难确定没有看到inputs()的实现,但是张量名称"input/shuffle_batch"表明该函数正在使用tf.train.shuffle_batch()函数构建输入。

Many TensorFlow functions for input processing create prefetching queues internally, including tf.train.shuffle_batch() . 许多用于输入处理的TensorFlow函数在内部创建预取队列,包括tf.train.shuffle_batch() These prefetching queues initially empty, and your sess.run(input_batch) call is probably blocked waiting for elements to be put in those queues. 这些预取队列最初是空的,您的sess.run(input_batch)调用可能被阻止,等待元素放入这些队列中。 Currently, the way that this typically happens is using a "queue runner thread", which is the name for one or more background threads that are started when you call tf.train.start_queue_runners() . 当前,这种情况通常发生的方式是使用“队列运行器线程”,这是当您调用tf.train.start_queue_runners()时启动的一个或多个后台线程的名称。

This is one of the more complicated areas of TensorFlow, and it's something we're working to improve. 这是TensorFlow较为复杂的领域之一,我们正在努力对此进行改进。 In the mean time, you may find the documentation on threading and queues in TensorFlow useful. 同时,您可能会发现TensorFlow中有关线程和队列的文档很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM