{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/3823","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/3823/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/3823/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/3823/events","html_url":"https://github.com/fchollet/keras/issues/3823","id":178125052,"number":3823,"title":"Dropout layer doesn't support Tensorflow workflow","user":{"login":"FBMachine","id":427300,"avatar_url":"https://avatars.githubusercontent.com/u/427300?v=3","gravatar_id":"","url":"https://api.github.com/users/FBMachine","html_url":"https://github.com/FBMachine","followers_url":"https://api.github.com/users/FBMachine/followers","following_url":"https://api.github.com/users/FBMachine/following{/other_user}","gists_url":"https://api.github.com/users/FBMachine/gists{/gist_id}","starred_url":"https://api.github.com/users/FBMachine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FBMachine/subscriptions","organizations_url":"https://api.github.com/users/FBMachine/orgs","repos_url":"https://api.github.com/users/FBMachine/repos","events_url":"https://api.github.com/users/FBMachine/events{/privacy}","received_events_url":"https://api.github.com/users/FBMachine/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-20T17:33:41Z","updated_at":"2016-09-23T09:28:38Z","closed_at":null,"body":"Following the workflow here:\r\nhttps://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html#using-keras-models-with-tensorflow\r\n\r\nUsing a layer with dropout throws an exception. It works if there is no dropout.\r\n\r\nEdit: it has nothing to do with the Embedding layer. The problem is specifically with the dropout layer, and will also happen if you manually add a dropout layer to the model.\r\n\r\nMinimal code to reproduce:\r\n```\r\nimport tensorflow as tf\r\nfrom keras import backend as K\r\nfrom keras.models import Sequential\r\nfrom keras.layers import Embedding\r\n\r\nwith tf.Graph().as_default():\r\n    with tf.Session() as session:\r\n        input_length = 140\r\n        x = tf.placeholder(tf.int32, shape=(None, input_length))\r\n\r\n        K.set_session(session)\r\n\r\n        model = Sequential()\r\n        model.add(Embedding(257, 300, input_length=input_length, dropout=0.2))\r\n```\r\n\r\nStack trace:\r\n```\r\n$ KERAS_BACKEND=tensorflow python exception-repro.py \r\nUsing TensorFlow backend.\r\nTraceback (most recent call last):\r\n  File \"exception-repro.py\", line 14, in <module>\r\n    model.add(Embedding(257, 300, input_length=input_length, dropout=0.2))\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/keras/models.py\", line 275, in add\r\n    layer.create_input_layer(batch_input_shape, input_dtype)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/keras/engine/topology.py\", line 367, in create_input_layer\r\n    self(x)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/keras/engine/topology.py\", line 511, in __call__\r\n    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/keras/engine/topology.py\", line 569, in add_inbound_node\r\n    Node.create_node(self, inbound_layers, node_indices, tensor_indices)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/keras/engine/topology.py\", line 150, in create_node\r\n    output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/keras/layers/embeddings.py\", line 134, in call\r\n    W = K.in_train_phase(self.W * B, self.W)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py\", line 1109, in in_train_phase\r\n    lambda: alt)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py\", line 1150, in cond\r\n    res_t = context_t.BuildCondBranch(fn1)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py\", line 1089, in BuildCondBranch\r\n    real_v = _SwitchRefOrTensor(real_v, self._pred)[self._branch]\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py\", line 304, in _SwitchRefOrTensor\r\n    return switch(data, pred, name=name)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py\", line 198, in switch\r\n    with ops.op_scope([data, pred], name, \"Switch\") as name:\r\n  File \"/usr/lib/python2.7/contextlib.py\", line 17, in __enter__\r\n    return self.gen.next()\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 3692, in op_scope\r\n    g = _get_graph_from_inputs(values)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 3499, in _get_graph_from_inputs\r\n    _assert_same_graph(original_graph_element, graph_element)\r\n  File \"/home/dgonzalez/tf_env/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 3444, in _assert_same_graph\r\n    \"%s must be from the same graph as %s.\" % (item, original_item))\r\nValueError: Tensor(\"cond/pred_id:0\", dtype=bool) must be from the same graph as Tensor(\"mul_1:0\", shape=(257, 300), dtype=float32).\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/249145613","html_url":"https://github.com/fchollet/keras/issues/3823#issuecomment-249145613","issue_url":"https://api.github.com/repos/fchollet/keras/issues/3823","id":249145613,"user":{"login":"SRTjiawei","id":17583521,"avatar_url":"https://avatars.githubusercontent.com/u/17583521?v=3","gravatar_id":"","url":"https://api.github.com/users/SRTjiawei","html_url":"https://github.com/SRTjiawei","followers_url":"https://api.github.com/users/SRTjiawei/followers","following_url":"https://api.github.com/users/SRTjiawei/following{/other_user}","gists_url":"https://api.github.com/users/SRTjiawei/gists{/gist_id}","starred_url":"https://api.github.com/users/SRTjiawei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SRTjiawei/subscriptions","organizations_url":"https://api.github.com/users/SRTjiawei/orgs","repos_url":"https://api.github.com/users/SRTjiawei/repos","events_url":"https://api.github.com/users/SRTjiawei/events{/privacy}","received_events_url":"https://api.github.com/users/SRTjiawei/received_events","type":"User","site_admin":false},"created_at":"2016-09-23T09:28:38Z","updated_at":"2016-09-23T09:28:38Z","body":"I got the same issue, seems it's because that we created multiple graphs, not a problem about the Dropout. I tried to add `with tf.Graph().as_default()`, but didn't solved it yet."}}
{"actor":{"display_login":"SRTjiawei"}}