{"action":"created","issue":{"url":"https://api.github.com/repos/backstopmedia/tensorflowbook/issues/8","repository_url":"https://api.github.com/repos/backstopmedia/tensorflowbook","labels_url":"https://api.github.com/repos/backstopmedia/tensorflowbook/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/backstopmedia/tensorflowbook/issues/8/comments","events_url":"https://api.github.com/repos/backstopmedia/tensorflowbook/issues/8/events","html_url":"https://github.com/backstopmedia/tensorflowbook/issues/8","id":174277206,"number":8,"title":"Ch4_softmax","user":{"login":"Ed4Piksel","id":20833620,"avatar_url":"https://avatars.githubusercontent.com/u/20833620?v=3","gravatar_id":"","url":"https://api.github.com/users/Ed4Piksel","html_url":"https://github.com/Ed4Piksel","followers_url":"https://api.github.com/users/Ed4Piksel/followers","following_url":"https://api.github.com/users/Ed4Piksel/following{/other_user}","gists_url":"https://api.github.com/users/Ed4Piksel/gists{/gist_id}","starred_url":"https://api.github.com/users/Ed4Piksel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ed4Piksel/subscriptions","organizations_url":"https://api.github.com/users/Ed4Piksel/orgs","repos_url":"https://api.github.com/users/Ed4Piksel/repos","events_url":"https://api.github.com/users/Ed4Piksel/events{/privacy}","received_events_url":"https://api.github.com/users/Ed4Piksel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-31T13:45:20Z","updated_at":"2016-09-22T14:35:31Z","closed_at":null,"body":"File reading broken, batch size broken on fix file read as per attached \r\n\r\n# Softmax example in TF using the classical Iris dataset\r\n# Download iris.data from https://archive.ics.uci.edu/ml/datasets/Iris\r\n\r\nimport tensorflow as tf\r\nimport os\r\n\r\n# this time weights form a matrix, not a column vector, one \"weight vector\" per class.\r\nW = tf.Variable(tf.zeros([4, 3]), name=\"weights\")\r\n# so do the biases, one per class.\r\nb = tf.Variable(tf.zeros([3], name=\"bias\"))\r\n\r\n\r\ndef combine_inputs(X):\r\n    return tf.matmul(X, W) + b\r\n\r\n\r\ndef inference(X):\r\n    return tf.nn.softmax(combine_inputs(X))\r\n\r\n\r\ndef loss(X, Y):\r\n    return tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(combine_inputs(X), Y))\r\n\r\n\r\ndef read_csv(batch_size, file_name, record_defaults):\r\n    filename_queue = tf.train.string_input_producer([file_name])\r\n\r\n    reader = tf.TextLineReader(skip_header_lines=1)\r\n    key, value = reader.read(filename_queue)\r\n\r\n    # decode_csv will convert a Tensor from type string (the text line) in\r\n    # a tuple of tensor columns with the specified defaults, which also\r\n    # sets the data type for each column\r\n    decoded = tf.decode_csv(value, record_defaults=record_defaults)\r\n\r\n    # batch actually reads the file and loads \"batch_size\" rows in a single tensor\r\n    return tf.train.shuffle_batch(decoded,\r\n                                  batch_size=batch_size,\r\n                                  capacity=batch_size * 50,\r\n                                  min_after_dequeue=batch_size)\r\n\r\n\r\ndef inputs():\r\n\r\n    sepal_length, sepal_width, petal_length, petal_width, label =\\\r\n        read_csv(100, \"./iris.data\", [[0.0], [0.0], [0.0], [0.0], [\"\"]])\r\n\r\n    # convert class names to a 0 based class index.\r\n    label_number = tf.to_int32(tf.argmax(tf.to_int32(tf.pack([\r\n        tf.equal(label, [\"Iris-setosa\"]),\r\n        tf.equal(label, [\"Iris-versicolor\"]),\r\n        tf.equal(label, [\"Iris-virginica\"])\r\n    ])), 0))\r\n\r\n    # Pack all the features that we care about in a single matrix;\r\n    # We then transpose to have a matrix with one example per row and one feature per column.\r\n    features = tf.transpose(tf.pack([sepal_length, sepal_width, petal_length, petal_width]))\r\n\r\n    return features, label_number\r\n\r\n\r\ndef train(total_loss):\r\n    learning_rate = 0.01\r\n    return tf.train.GradientDescentOptimizer(learning_rate).minimize(total_loss)\r\n\r\n\r\ndef evaluate(sess, X, Y):\r\n\r\n    predicted = tf.cast(tf.arg_max(inference(X), 1), tf.int32)\r\n\r\n    print sess.run(tf.reduce_mean(tf.cast(tf.equal(predicted, Y), tf.float32)))\r\n\r\n\r\n# Launch the graph in a session, setup boilerplate\r\nwith tf.Session() as sess:\r\n\r\n    tf.initialize_all_variables().run()\r\n\r\n    X, Y = inputs()\r\n\r\n    total_loss = loss(X, Y)\r\n    train_op = train(total_loss)\r\n\r\n    coord = tf.train.Coordinator()\r\n    threads = tf.train.start_queue_runners(sess=sess, coord=coord)\r\n\r\n    # actual training loop\r\n    training_steps = 1000\r\n    for step in range(training_steps):\r\n        sess.run([train_op])\r\n        # for debugging and learning purposes, see how the loss gets decremented thru training steps\r\n        if step % 10 == 0:\r\n            print \"loss: \", sess.run([total_loss])\r\n\r\n    evaluate(sess, X, Y)\r\n\r\n    coord.request_stop()\r\n    coord.join(threads)\r\n    sess.close()\r\n\r\nloss: \r\n---------------------------------------------------------------------------\r\nOutOfRangeError                           Traceback (most recent call last)\r\n<ipython-input-4-c9efa6d62c96> in <module>()\r\n     90         # for debugging and learning purposes, see how the loss gets decremented thru training steps\r\n     91         if step % 10 == 0:\r\n---> 92             print \"loss: \", sess.run([total_loss])\r\n     93 \r\n     94     evaluate(sess, X, Y)\r\n\r\n/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)\r\n    370     try:\r\n    371       result = self._run(None, fetches, feed_dict, options_ptr,\r\n--> 372                          run_metadata_ptr)\r\n    373       if run_metadata:\r\n    374         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)\r\n\r\n/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)\r\n    634     try:\r\n    635       results = self._do_run(handle, target_list, unique_fetches,\r\n--> 636                              feed_dict_string, options, run_metadata)\r\n    637     finally:\r\n    638       # The movers are no longer used. Delete them.\r\n\r\n/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\r\n    706     if handle is None:\r\n    707       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,\r\n--> 708                            target_list, options, run_metadata)\r\n    709     else:\r\n    710       return self._do_call(_prun_fn, self._session, handle, feed_dict,\r\n\r\n/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_call(self, fn, *args)\r\n    726         except KeyError:\r\n    727           pass\r\n--> 728       raise type(e)(node_def, op, message)\r\n    729 \r\n    730   def _extend_graph(self):\r\n\r\nOutOfRangeError: RandomShuffleQueue '_7_shuffle_batch_1/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 49)\r\n\t [[Node: shuffle_batch_1 = QueueDequeueMany[_class=[\"loc:@shuffle_batch_1/random_shuffle_queue\"], component_types=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_STRING], timeout_ms=-1, _device=\"/job:localhost/replica:0/task:0/cpu:0\"](shuffle_batch_1/random_shuffle_queue, shuffle_batch_1/n)]]\r\nCaused by op u'shuffle_batch_1', defined at:\r\n  File \"/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py\", line 162, in _run_module_as_main\r\n    \"__main__\", fname, loader, pkg_name)\r\n  File \"/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py\", line 72, in _run_code\r\n    exec code in run_globals\r\n  File \"/usr/local/lib/python2.7/site-packages/ipykernel/__main__.py\", line 3, in <module>\r\n    app.launch_new_instance()\r\n  File \"/usr/local/lib/python2.7/site-packages/traitlets/config/application.py\", line 589, in launch_instance\r\n    app.start()\r\n  File \"/usr/local/lib/python2.7/site-packages/ipykernel/kernelapp.py\", line 442, in start\r\n    ioloop.IOLoop.instance().start()\r\n  File \"/usr/local/lib/python2.7/site-packages/zmq/eventloop/ioloop.py\", line 162, in start\r\n    super(ZMQIOLoop, self).start()\r\n  File \"/usr/local/lib/python2.7/site-packages/tornado/ioloop.py\", line 883, in start\r\n    handler_func(fd_obj, events)\r\n  File \"/usr/local/lib/python2.7/site-packages/tornado/stack_context.py\", line 275, in null_wrapper\r\n    return fn(*args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 440, in _handle_events\r\n    self._handle_recv()\r\n  File \"/usr/local/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 472, in _handle_recv\r\n    self._run_callback(callback, msg)\r\n  File \"/usr/local/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 414, in _run_callback\r\n    callback(*args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/tornado/stack_context.py\", line 275, in null_wrapper\r\n    return fn(*args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 276, in dispatcher\r\n    return self.dispatch_shell(stream, msg)\r\n  File \"/usr/local/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 228, in dispatch_shell\r\n    handler(stream, idents, msg)\r\n  File \"/usr/local/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 391, in execute_request\r\n    user_expressions, allow_stdin)\r\n  File \"/usr/local/lib/python2.7/site-packages/ipykernel/ipkernel.py\", line 199, in do_execute\r\n    shell.run_cell(code, store_history=store_history, silent=silent)\r\n  File \"/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2723, in run_cell\r\n    interactivity=interactivity, compiler=compiler, result=result)\r\n  File \"/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2825, in run_ast_nodes\r\n    if self.run_code(code, result):\r\n  File \"/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2885, in run_code\r\n    exec(code_obj, self.user_global_ns, self.user_ns)\r\n  File \"<ipython-input-4-c9efa6d62c96>\", line 78, in <module>\r\n    X, Y = inputs()\r\n  File \"<ipython-input-4-c9efa6d62c96>\", line 45, in inputs\r\n    sepal_length, sepal_width, petal_length, petal_width, label =        read_csv(100, \"iris.data\", [[0.0], [0.0], [0.0], [0.0], [\"\"]])\r\n  File \"<ipython-input-4-c9efa6d62c96>\", line 40, in read_csv\r\n    min_after_dequeue=batch_size)\r\n  File \"/usr/local/lib/python2.7/site-packages/tensorflow/python/training/input.py\", line 779, in shuffle_batch\r\n    dequeued = queue.dequeue_many(batch_size, name=name)\r\n  File \"/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/data_flow_ops.py\", line 400, in dequeue_many\r\n    self._queue_ref, n=n, component_types=self._dtypes, name=name)\r\n  File \"/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py\", line 465, in _queue_dequeue_many\r\n    timeout_ms=timeout_ms, name=name)\r\n  File \"/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/op_def_library.py\", line 704, in apply_op\r\n    op_def=op_def)\r\n  File \"/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 2260, in create_op\r\n    original_op=self._default_original_op, op_def=op_def)\r\n  File \"/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 1230, in __init__\r\n    self._traceback = _extract_stack()"},"comment":{"url":"https://api.github.com/repos/backstopmedia/tensorflowbook/issues/comments/248921990","html_url":"https://github.com/backstopmedia/tensorflowbook/issues/8#issuecomment-248921990","issue_url":"https://api.github.com/repos/backstopmedia/tensorflowbook/issues/8","id":248921990,"user":{"login":"stefan668668","id":22373423,"avatar_url":"https://avatars.githubusercontent.com/u/22373423?v=3","gravatar_id":"","url":"https://api.github.com/users/stefan668668","html_url":"https://github.com/stefan668668","followers_url":"https://api.github.com/users/stefan668668/followers","following_url":"https://api.github.com/users/stefan668668/following{/other_user}","gists_url":"https://api.github.com/users/stefan668668/gists{/gist_id}","starred_url":"https://api.github.com/users/stefan668668/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefan668668/subscriptions","organizations_url":"https://api.github.com/users/stefan668668/orgs","repos_url":"https://api.github.com/users/stefan668668/repos","events_url":"https://api.github.com/users/stefan668668/events{/privacy}","received_events_url":"https://api.github.com/users/stefan668668/received_events","type":"User","site_admin":false},"created_at":"2016-09-22T14:35:31Z","updated_at":"2016-09-22T14:35:31Z","body":"just change the \"skip_header_lines=1\" to 0 on line \"reader = tf.TextLineReader(skip_header_lines=1)\" because there are/is no header line(s).\r\nBefore that I had to change the filename_queue to \"filename_queue= tf.train.string_input_producer([os.path.join(os.getcwd() , file_name)])\".\r\n\r\ngreets"}}
{"actor":{"display_login":"stefan668668"}}