{"action":"created","issue":{"url":"https://api.github.com/repos/keras-team/keras/issues/5427","repository_url":"https://api.github.com/repos/keras-team/keras","labels_url":"https://api.github.com/repos/keras-team/keras/issues/5427/labels{/name}","comments_url":"https://api.github.com/repos/keras-team/keras/issues/5427/comments","events_url":"https://api.github.com/repos/keras-team/keras/issues/5427/events","html_url":"https://github.com/keras-team/keras/issues/5427","id":208488230,"number":5427,"title":"FailedPreconditionError: lack of intialization of Keras variables when using with TensorFlow","user":{"login":"dumkar","id":25841224,"avatar_url":"https://avatars1.githubusercontent.com/u/25841224?v=4","gravatar_id":"","url":"https://api.github.com/users/dumkar","html_url":"https://github.com/dumkar","followers_url":"https://api.github.com/users/dumkar/followers","following_url":"https://api.github.com/users/dumkar/following{/other_user}","gists_url":"https://api.github.com/users/dumkar/gists{/gist_id}","starred_url":"https://api.github.com/users/dumkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dumkar/subscriptions","organizations_url":"https://api.github.com/users/dumkar/orgs","repos_url":"https://api.github.com/users/dumkar/repos","events_url":"https://api.github.com/users/dumkar/events{/privacy}","received_events_url":"https://api.github.com/users/dumkar/received_events","type":"User","site_admin":false},"labels":[{"id":611595073,"url":"https://api.github.com/repos/keras-team/keras/labels/stale","name":"stale","color":"ffffff","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-02-17T16:19:42Z","updated_at":"2018-04-28T06:54:58Z","closed_at":"2017-06-22T19:09:55Z","author_association":"NONE","body":"I am new to Keras and just installed it (with pip3) to use with TensorFlow (1.0.0). I am trying to follow the [Keras+TensorFlow tutorial](https://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html).\r\n\r\nWhen running the code, it stops at\r\n\r\n`train_step.run(feed_dict={img: batch[0], labels: batch[1]})`\r\n\r\nand throws the error below. I figured out it is because variables are not initialized and fixed it by inserting (see #4623):\r\n\r\n`keras.backend.get_session().run(tf.global_variables_initializer())`\r\n\r\nI decided to post it here since I was wondering if this is a general issue with Keras (as this is a rather simple example) regarding the update to TensorFlow 1.0.0 or something specific to my setup?\r\n\r\nThe error:\r\n\r\n> ---------------------------------------------------------------------------\r\n\r\n> FailedPreconditionError                   Traceback (most recent call last)\r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py in _do_call(self, fn, *args)\r\n>    1021     try:\r\n> -> 1022       return fn(*args)\r\n>    1023     except errors.OpError as e:\r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)\r\n>    1003                                  feed_dict, fetch_list, target_list,\r\n> -> 1004                                  status, run_metadata)\r\n>    1005 \r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\contextlib.py in __exit__(self, type, value, traceback)\r\n>      65             try:\r\n> ---> 66                 next(self.gen)\r\n>      67             except StopIteration:\r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\errors_impl.py in raise_exception_on_not_ok_status()\r\n>     468           compat.as_text(pywrap_tensorflow.TF_Message(status)),\r\n> --> 469           pywrap_tensorflow.TF_GetCode(status))\r\n>     470   finally:\r\n> \r\n> FailedPreconditionError: Attempting to use uninitialized value dense_1_W\r\n> \t [[Node: dense_1_W/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_1_W\"], _device=\"/job:localhost/replica:0/task:0/cpu:0\"](dense_1_W)]]\r\n> \r\n> During handling of the above exception, another exception occurred:\r\n> \r\n> FailedPreconditionError                   Traceback (most recent call last)\r\n> <ipython-input-7-15092c784757> in <module>()\r\n>       9         batch= mnist_data.train.next_batch(50)\r\n>      10         train_step.run(feed_dict={img: batch[0],\r\n> ---> 11                                  labels: batch[1]})\r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py in run(self, feed_dict, session)\r\n>    1586         none, the default session will be used.\r\n>    1587     \"\"\"\r\n> -> 1588     _run_using_default_session(self, feed_dict, self.graph, session)\r\n>    1589 \r\n>    1590 \r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py in _run_using_default_session(operation, feed_dict, graph, session)\r\n>    3830                        \"the operation's graph is different from the session's \"\r\n>    3831                        \"graph.\")\r\n> -> 3832   session.run(operation, feed_dict)\r\n>    3833 \r\n>    3834 \r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py in run(self, fetches, feed_dict, options, run_metadata)\r\n>     765     try:\r\n>     766       result = self._run(None, fetches, feed_dict, options_ptr,\r\n> --> 767                          run_metadata_ptr)\r\n>     768       if run_metadata:\r\n>     769         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)\r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)\r\n>     963     if final_fetches or final_targets:\r\n>     964       results = self._do_run(handle, final_targets, final_fetches,\r\n> --> 965                              feed_dict_string, options, run_metadata)\r\n>     966     else:\r\n>     967       results = []\r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\r\n>    1013     if handle is None:\r\n>    1014       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,\r\n> -> 1015                            target_list, options, run_metadata)\r\n>    1016     else:\r\n>    1017       return self._do_call(_prun_fn, self._session, handle, feed_dict,\r\n> \r\n> C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\client\\session.py in _do_call(self, fn, *args)\r\n>    1033         except KeyError:\r\n>    1034           pass\r\n> -> 1035       raise type(e)(node_def, op, message)\r\n>    1036 \r\n>    1037   def _extend_graph(self):\r\n> \r\n> FailedPreconditionError: Attempting to use uninitialized value dense_1_W\r\n> \t [[Node: dense_1_W/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_1_W\"], _device=\"/job:localhost/replica:0/task:0/cpu:0\"](dense_1_W)]]\r\n> \r\n> Caused by op 'dense_1_W/read', defined at:\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\runpy.py\", line 184, in _run_module_as_main\r\n>     \"__main__\", mod_spec)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\runpy.py\", line 85, in _run_code\r\n>     exec(code, run_globals)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\ipykernel\\__main__.py\", line 3, in <module>\r\n>     app.launch_new_instance()\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\traitlets\\config\\application.py\", line 653, in launch_instance\r\n>     app.start()\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 474, in start\r\n>     ioloop.IOLoop.instance().start()\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\ioloop.py\", line 162, in start\r\n>     super(ZMQIOLoop, self).start()\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tornado\\ioloop.py\", line 887, in start\r\n>     handler_func(fd_obj, events)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tornado\\stack_context.py\", line 275, in null_wrapper\r\n>     return fn(*args, **kwargs)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 440, in _handle_events\r\n>     self._handle_recv()\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 472, in _handle_recv\r\n>     self._run_callback(callback, msg)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 414, in _run_callback\r\n>     callback(*args, **kwargs)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tornado\\stack_context.py\", line 275, in null_wrapper\r\n>     return fn(*args, **kwargs)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 276, in dispatcher\r\n>     return self.dispatch_shell(stream, msg)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 228, in dispatch_shell\r\n>     handler(stream, idents, msg)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 390, in execute_request\r\n>     user_expressions, allow_stdin)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 196, in do_execute\r\n>     res = shell.run_cell(code, store_history=store_history, silent=silent)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 501, in run_cell\r\n>     return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2717, in run_cell\r\n>     interactivity=interactivity, compiler=compiler, result=result)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2821, in run_ast_nodes\r\n>     if self.run_code(code, result):\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2881, in run_code\r\n>     exec(code_obj, self.user_global_ns, self.user_ns)\r\n>   File \"<ipython-input-4-9a25c9d8fa0e>\", line 4, in <module>\r\n>     x = Dense(128, activation='relu')(img)  # fully-connected layer with 128 units and ReLU activation\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\keras\\engine\\topology.py\", line 546, in __call__\r\n>     self.build(input_shapes[0])\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\keras\\layers\\core.py\", line 798, in build\r\n>     constraint=self.W_constraint)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\keras\\engine\\topology.py\", line 418, in add_weight\r\n>     weight = initializer(shape, name=name)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\keras\\initializations.py\", line 66, in glorot_uniform\r\n>     return uniform(shape, s, name=name)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\keras\\initializations.py\", line 33, in uniform\r\n>     return K.random_uniform_variable(shape, -scale, scale, name=name)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py\", line 635, in random_uniform_variable\r\n>     return variable(value, dtype=dtype, name=name)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py\", line 259, in variable\r\n>     v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\variables.py\", line 226, in __init__\r\n>     expected_shape=expected_shape)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\variables.py\", line 344, in _init_from_args\r\n>     self._snapshot = array_ops.identity(self._variable, name=\"read\")\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\gen_array_ops.py\", line 1490, in identity\r\n>     result = _op_def_lib.apply_op(\"Identity\", input=input, name=name)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py\", line 763, in apply_op\r\n>     op_def=op_def)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 2395, in create_op\r\n>     original_op=self._default_original_op, op_def=op_def)\r\n>   File \"C:\\Users\\dumon\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 1264, in __init__\r\n>     self._traceback = _extract_stack()\r\n> \r\n> FailedPreconditionError (see above for traceback): Attempting to use uninitialized value dense_1_W\r\n> \t [[Node: dense_1_W/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_1_W\"], _device=\"/job:localhost/replica:0/task:0/cpu:0\"](dense_1_W)]]\r\n> "},"comment":{"url":"https://api.github.com/repos/keras-team/keras/issues/comments/385146664","html_url":"https://github.com/keras-team/keras/issues/5427#issuecomment-385146664","issue_url":"https://api.github.com/repos/keras-team/keras/issues/5427","id":385146664,"user":{"login":"why2face","id":30194360,"avatar_url":"https://avatars3.githubusercontent.com/u/30194360?v=4","gravatar_id":"","url":"https://api.github.com/users/why2face","html_url":"https://github.com/why2face","followers_url":"https://api.github.com/users/why2face/followers","following_url":"https://api.github.com/users/why2face/following{/other_user}","gists_url":"https://api.github.com/users/why2face/gists{/gist_id}","starred_url":"https://api.github.com/users/why2face/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/why2face/subscriptions","organizations_url":"https://api.github.com/users/why2face/orgs","repos_url":"https://api.github.com/users/why2face/repos","events_url":"https://api.github.com/users/why2face/events{/privacy}","received_events_url":"https://api.github.com/users/why2face/received_events","type":"User","site_admin":false},"created_at":"2018-04-28T06:54:58Z","updated_at":"2018-04-28T06:54:58Z","author_association":"NONE","body":"Got the same error while trying to use tensorflow-gpu as backend in keras. Though it worked well using cpu before. How could this make a difference?"}}
{"actor":{"display_login":"why2face"}}