简体   繁体   中英

sess.run(Tensor()) does nothing

I am attempting to feed my neural net with data stored in a TFRecords. The data is extracted using inputs() similarly to what is on the tensorflow webpage. 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. 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.

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 :

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.

Many TensorFlow functions for input processing create prefetching queues internally, including 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. 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() .

This is one of the more complicated areas of TensorFlow, and it's something we're working to improve. In the mean time, you may find the documentation on threading and queues in TensorFlow useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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