{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/2397","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/2397/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/2397/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/2397/events","html_url":"https://github.com/fchollet/keras/issues/2397","id":149397212,"number":2397,"title":"Tensorflow backend - bug in model._make_predict_function(...)","user":{"login":"Froskekongen","id":4319052,"avatar_url":"https://avatars.githubusercontent.com/u/4319052?v=3","gravatar_id":"","url":"https://api.github.com/users/Froskekongen","html_url":"https://github.com/Froskekongen","followers_url":"https://api.github.com/users/Froskekongen/followers","following_url":"https://api.github.com/users/Froskekongen/following{/other_user}","gists_url":"https://api.github.com/users/Froskekongen/gists{/gist_id}","starred_url":"https://api.github.com/users/Froskekongen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Froskekongen/subscriptions","organizations_url":"https://api.github.com/users/Froskekongen/orgs","repos_url":"https://api.github.com/users/Froskekongen/repos","events_url":"https://api.github.com/users/Froskekongen/events{/privacy}","received_events_url":"https://api.github.com/users/Froskekongen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-19T09:08:30Z","updated_at":"2016-04-19T21:11:13Z","closed_at":null,"body":"There appears to be a bug in the make_predict_function for the tensorflow backend. The following error message appears for me when trying to call model.predict(...)\r\n\r\n\r\n```\r\nself._make_predict_function()\r\n  File \"/usr/local/lib/python3.4/dist-packages/keras/engine/training.py\", line 679, in _make_predict_function\r\n    **self._function_kwargs)\r\n  File \"/usr/local/lib/python3.4/dist-packages/keras/backend/tensorflow_backend.py\", line 615, in function\r\n    return Function(inputs, outputs, updates=updates)\r\n  File \"/usr/local/lib/python3.4/dist-packages/keras/backend/tensorflow_backend.py\", line 589, in __init__\r\n    with tf.control_dependencies(self.outputs):\r\n  File \"/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py\", line 3192, in control_dependencies\r\n    return get_default_graph().control_dependencies(control_inputs)\r\n  File \"/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py\", line 2993, in control_dependencies\r\n    c = self.as_graph_element(c)\r\n  File \"/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py\", line 2291, in as_graph_element\r\n    raise ValueError(\"Tensor %s is not an element of this graph.\" % obj)\r\nValueError: Tensor Tensor(\"Sigmoid_2:0\", shape=(?, 17), dtype=float32) is not an element of this graph.\r\n```\r\n\r\nThis does not happen when using the theano backend.\r\n\r\nNotes: The model is loaded from json, and is defined as follows:\r\n\r\n\r\n```\r\n    seq1=Input(dtype='int32',shape=(400,),name='input_text')\r\n    seq2=Input(dtype='int32',shape=(20,),name='input_titles')\r\n\r\n    embeddeding=Embedding(max_features,embedding_dims,dropout=0.3)\r\n\r\n    encoding_1=embeddeding(seq1)\r\n    encoding_2=embeddeding(seq2)\r\n\r\n    filter_lengths = [1,3,6]\r\n\r\n\r\n    def max_1d(X):\r\n        return K.max(X, axis=1)\r\n    convs1=[]\r\n    convs2=[]\r\n    for fl in filter_lengths:\r\n\r\n        conv1=Convolution1D(nb_filter=nb_filter,\r\n                        filter_length=fl,\r\n                        border_mode='valid',\r\n                        activation='relu',\r\n                        subsample_length=1)(encoding_1)\r\n        conv1=Lambda(max_1d, output_shape=(nb_filter,))(conv1)\r\n        convs1.append(conv1)\r\n\r\n        conv2=Convolution1D(nb_filter=nb_filter,\r\n                        filter_length=fl,\r\n                        border_mode='valid',\r\n                        activation='relu',\r\n                        subsample_length=1)(encoding_2)\r\n        conv2=Lambda(max_1d, output_shape=(nb_filter,))(conv2)\r\n        convs2.append(conv2)\r\n\r\n    m=merge([*convs1,*convs2],mode='concat')\r\n    m=Highway(activation='relu')(m)\r\n    m=Highway(activation='relu')(m)\r\n    m=Dropout(0.5)(m)\r\n    hovedkategori_loss=Dense(labsHovedKat.shape[1],activation='sigmoid',name='hovedkategori')(m)\r\n\r\n    m1=merge([hovedkategori_loss,m],mode='concat')\r\n    underkategori_loss=Dense(labsUnderKat.shape[1],activation='sigmoid',name='underkategori')(m1)\r\n\r\n    model=Model(input=[seq1,seq2],output=[hovedkategori_loss,underkategori_loss])\r\n    model.compile(optimizer='adam',loss='binary_crossentropy',metrics={'hovedkategori':'accuracy','underkategori':'accuracy'})\r\n```\r\n\r\n- [x] Check that you are up-to-date with the master branch of Keras. You can update with:\r\npip install git+git://github.com/fchollet/keras.git --upgrade --no-deps\r\n\r\n- [x] If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:\r\npip install git+git://github.com/Theano/Theano.git --upgrade --no-deps\r\n"},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/212131612","html_url":"https://github.com/fchollet/keras/issues/2397#issuecomment-212131612","issue_url":"https://api.github.com/repos/fchollet/keras/issues/2397","id":212131612,"user":{"login":"fchollet","id":710255,"avatar_url":"https://avatars.githubusercontent.com/u/710255?v=3","gravatar_id":"","url":"https://api.github.com/users/fchollet","html_url":"https://github.com/fchollet","followers_url":"https://api.github.com/users/fchollet/followers","following_url":"https://api.github.com/users/fchollet/following{/other_user}","gists_url":"https://api.github.com/users/fchollet/gists{/gist_id}","starred_url":"https://api.github.com/users/fchollet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fchollet/subscriptions","organizations_url":"https://api.github.com/users/fchollet/orgs","repos_url":"https://api.github.com/users/fchollet/repos","events_url":"https://api.github.com/users/fchollet/events{/privacy}","received_events_url":"https://api.github.com/users/fchollet/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T21:11:13Z","updated_at":"2016-04-19T21:11:13Z","body":"Do you have a code snippet to reproduce this issue? I can guarantee you that `predict` does in fact work, including with TensorFlow."}}