backstopmedia / tensorflowbook

457 stars 296 forks source link

Ch 4 Logistic regression file address #6

Closed villenahkuri closed 8 years ago

villenahkuri commented 8 years ago

This mechanism to create full path:

filename_queue = tf.train.string_input_producer([os.path.dirname(__file__) + "/" + file_name])

produces just '/train.csv' for me on Mac OSX.

That generates a confusing and scary stack trace, which misleads a Tensorflow novice for quite some time.

Finally when I removed the path setting, the code works just fine (naturally requires that input file is in the same folder):

filename_queue = tf.train.string_input_producer([file_name])

Stack trace:

E tensorflow/core/client/tensor_c_api.cc:485] /train.csv
     [[Node: ReaderRead = ReaderRead[_class=["loc:@TextLineReader", "loc:@input_producer"], _device="/job:localhost/replica:0/task:0/cpu:0"](TextLineReader, input_producer)]]
E tensorflow/core/client/tensor_c_api.cc:485] RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_FLOAT, DT_INT32, DT_STRING, DT_STRING, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_STRING, DT_FLOAT, DT_STRING, DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
Traceback (most recent call last):
  File "logistic2.py", line 91, in <module>
    sess.run([train_op])
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 382, in run
    run_metadata_ptr)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 655, in _run
    feed_dict_string, options, run_metadata)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 723, in _do_run
    target_list, options, run_metadata)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 743, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors.OutOfRangeError: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_FLOAT, DT_INT32, DT_STRING, DT_STRING, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_STRING, DT_FLOAT, DT_STRING, DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
Caused by op u'shuffle_batch', defined at:
  File "logistic2.py", line 80, in <module>
    X, Y = inputs()
  File "logistic2.py", line 47, in inputs
    read_csv(100, "train.csv", [[0.0], [0.0], [0], [""], [""], [0.0], [0.0], [0.0], [""], [0.0], [""], [""]])
  File "logistic2.py", line 42, in read_csv
    min_after_dequeue=batch_size)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 817, in shuffle_batch
    dequeued = queue.dequeue_many(batch_size, name=name)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/data_flow_ops.py", line 435, in dequeue_many
    self._queue_ref, n=n, component_types=self._dtypes, name=name)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 867, in _queue_dequeue_many
    timeout_ms=timeout_ms, name=name)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op
    op_def=op_def)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2310, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/Users/villenahkuri/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1232, in __init__
    self._traceback = _extract_stack()
wp-lai commented 8 years ago

I think it would be better to use filename_queue = tf.train.string_input_producer([os.path.join(os.getcwd(), file_name)])

samjabrahams commented 8 years ago

Hi @villenahkuri and @wp-lai : sorry for the long delay in responding. I've updated the code in both the repo and our book's master files. Thank you so much for opening this up!