{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/3850","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/3850/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/3850/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/3850/events","html_url":"https://github.com/fchollet/keras/issues/3850","id":178695241,"number":3850,"title":"Exception: The shape of the input to \"Flatten\" is not fully defined","user":{"login":"hadikazemi","id":22330454,"avatar_url":"https://avatars.githubusercontent.com/u/22330454?v=3","gravatar_id":"","url":"https://api.github.com/users/hadikazemi","html_url":"https://github.com/hadikazemi","followers_url":"https://api.github.com/users/hadikazemi/followers","following_url":"https://api.github.com/users/hadikazemi/following{/other_user}","gists_url":"https://api.github.com/users/hadikazemi/gists{/gist_id}","starred_url":"https://api.github.com/users/hadikazemi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadikazemi/subscriptions","organizations_url":"https://api.github.com/users/hadikazemi/orgs","repos_url":"https://api.github.com/users/hadikazemi/repos","events_url":"https://api.github.com/users/hadikazemi/events{/privacy}","received_events_url":"https://api.github.com/users/hadikazemi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-22T19:08:56Z","updated_at":"2016-09-22T21:33:29Z","closed_at":null,"body":"The following code generates no error on a virtualbox Ubuntu 14.04 (CPU only). The code is an tutorial from [www.pyimagesearch.com](http://www.pyimagesearch.com/2016/08/01/lenet-convolutional-neural-network-in-python)\r\n\r\n``` python\r\n    from sklearn.cross_validation import train_test_split\r\n    from sklearn import datasets\r\n    from keras.optimizers import SGD\r\n    from keras.utils import np_utils\r\n    import numpy as np\r\n    import argparse\r\n    import cv2\r\n    from keras.models import Sequential\r\n    from keras.layers.convolutional import Convolution2D\r\n    from keras.layers.convolutional import MaxPooling2D\r\n    from keras.layers.core import Activation\r\n    from keras.layers.core import Flatten\r\n    from keras.layers.core import Dense\r\n\r\n    def LeNet_build(width, height, depth, classes, weightsPath=None):\r\n        print width, height, depth\r\n        model = Sequential()\r\n\r\n        # first set of CONV => RELU => POOL\r\n        model.add(Convolution2D(20, 5, 5, border_mode=\"same\",\r\n            input_shape=(depth, height, width)))\r\n        model.add(Activation(\"relu\"))\r\n        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))\r\n\r\n        # second set of CONV => RELU => POOL\r\n        model.add(Convolution2D(50, 5, 5, border_mode=\"same\"))\r\n        model.add(Activation(\"relu\"))\r\n        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))\r\n\r\n        # set of FC => RELU layers\r\n        model.add(Flatten())\r\n        model.add(Dense(500))\r\n        model.add(Activation(\"relu\"))\r\n\r\n        # softmax classifier\r\n        model.add(Dense(classes))\r\n        model.add(Activation(\"softmax\"))\r\n\r\n        # if a weights path is supplied (inicating that the model was\r\n        # pre-trained), then load the weights\r\n        if weightsPath is not None:\r\n            model.load_weights(weightsPath)\r\n\r\n        # return the constructed network architecture\r\n        return model\r\n\r\n    dataset = datasets.fetch_mldata(\"MNIST Original\")\r\n\r\n    # reshape the MNIST dataset from a flat list of 784-dim vectors, to\r\n    # 28 x 28 pixel images, then scale the data to the range [0, 1.0]\r\n    # and construct the training and testing splits\r\n    data = dataset.data.reshape((dataset.data.shape[0], 28, 28))\r\n    data = data[:, np.newaxis, :, :]\r\n    (trainData, testData, trainLabels, testLabels) = train_test_split(\r\n\t    data / 255.0, dataset.target.astype(\"int\"), test_size=0.33)\r\n\r\n    # transform the training and testing labels into vectors in the\r\n    # range [0, classes] -- this generates a vector for each label,\r\n    # where the index of the label is set to `1` and all other entries\r\n    # to `0`; in the case of MNIST, there are 10 class labels\r\n    trainLabels = np_utils.to_categorical(trainLabels, 10)\r\n    testLabels = np_utils.to_categorical(testLabels, 10)\r\n\r\n    # initialize the optimizer and model\r\n    print(\"[INFO] compiling model...\")\r\n    opt = SGD(lr=0.01)\r\n    model = LeNet_build(width=28, height=28, depth=1, classes=10, weightsPath=None)\r\n```\r\n\r\nHowever, it generates the following error inside a fresh installed Ubuntu 14.04 with Titan X Pascal and Cuda 8.0 (tested both on CPU and GPU - Theano backend) - the same error is reported before and remained unsolved [(https://github.com/fchollet/keras/issues/1592):](https://github.com/fchollet/keras/issues/1592)\r\n```\r\n Exception                                 Traceback (most recent call last)\r\n<ipython-input-3-c61646d5fa78> in <module>()\r\n     23 print(\"[INFO] compiling model...\")\r\n     24 opt = SGD(lr=0.01)\r\n---> 25 model = LeNet_build(width=28, height=28, depth=1, classes=10, weightsPath=None)\r\n\r\n<ipython-input-2-a36c66483235> in LeNet_build(width, height, depth, classes, weightsPath)\r\n     16 \r\n     17         # set of FC => RELU layers\r\n---> 18         model.add(Flatten())\r\n     19         model.add(Dense(500))\r\n     20         model.add(Activation(\"relu\"))\r\n\r\n/home/hadi/.virtualenvs/keras/local/lib/python2.7/site-packages/keras/models.pyc in add(self, layer)\r\n    306                  output_shapes=[self.outputs[0]._keras_shape])\r\n    307         else:\r\n--> 308             output_tensor = layer(self.outputs[0])\r\n    309             if type(output_tensor) is list:\r\n    310                 raise Exception('All layers in a Sequential model '\r\n\r\n/home/hadi/.virtualenvs/keras/local/lib/python2.7/site-packages/keras/engine/topology.pyc in __call__(self, x, mask)\r\n    512         if inbound_layers:\r\n    513             # this will call layer.build() if necessary\r\n--> 514             self.add_inbound_node(inbound_layers, node_indices, tensor_indices)\r\n    515             input_added = True\r\n    516 \r\n\r\n/home/hadi/.virtualenvs/keras/local/lib/python2.7/site-packages/keras/engine/topology.pyc in add_inbound_node(self, inbound_layers, node_indices, tensor_indices)\r\n    570         # creating the node automatically updates self.inbound_nodes\r\n    571         # as well as outbound_nodes on inbound layers.\r\n--> 572         Node.create_node(self, inbound_layers, node_indices, tensor_indices)\r\n    573 \r\n    574     def get_output_shape_for(self, input_shape):\r\n\r\n/home/hadi/.virtualenvs/keras/local/lib/python2.7/site-packages/keras/engine/topology.pyc in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices)\r\n    150             output_masks = to_list(outbound_layer.compute_mask(input_tensors[0], input_masks[0]))\r\n    151             # TODO: try to auto-infer shape if exception is raised by get_output_shape_for\r\n--> 152             output_shapes = to_list(outbound_layer.get_output_shape_for(input_shapes[0]))\r\n    153         else:\r\n    154             output_tensors = to_list(outbound_layer.call(input_tensors, mask=input_masks))\r\n\r\n/home/hadi/.virtualenvs/keras/local/lib/python2.7/site-packages/keras/layers/core.pyc in get_output_shape_for(self, input_shape)\r\n    400             raise Exception('The shape of the input to \"Flatten\" '\r\n    401                             'is not fully defined '\r\n--> 402                             '(got ' + str(input_shape[1:]) + '. '\r\n    403                             'Make sure to pass a complete \"input_shape\" '\r\n    404                             'or \"batch_input_shape\" argument to the first '\r\n\r\nException: The shape of the input to \"Flatten\" is not fully defined (got (0, 7, 50). Make sure to pass a complete \"input_shape\" or \"batch_input_shape\" argument to the first layer in your model.\r\n```\r\n\r\nUpdate: I have checked all of my previous Keras codes which were working in the virtualbox and all of them give the same error:\r\n```\r\nException: The shape of the input to \"Flatten\" is not fully defined (got (0, 7, 512). Make sure to pass a complete \"input_shape\" or \"batch_input_shape\" argument to the first layer in your model.\r\n```"},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/249034588","html_url":"https://github.com/fchollet/keras/issues/3850#issuecomment-249034588","issue_url":"https://api.github.com/repos/fchollet/keras/issues/3850","id":249034588,"user":{"login":"hadikazemi","id":22330454,"avatar_url":"https://avatars.githubusercontent.com/u/22330454?v=3","gravatar_id":"","url":"https://api.github.com/users/hadikazemi","html_url":"https://github.com/hadikazemi","followers_url":"https://api.github.com/users/hadikazemi/followers","following_url":"https://api.github.com/users/hadikazemi/following{/other_user}","gists_url":"https://api.github.com/users/hadikazemi/gists{/gist_id}","starred_url":"https://api.github.com/users/hadikazemi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadikazemi/subscriptions","organizations_url":"https://api.github.com/users/hadikazemi/orgs","repos_url":"https://api.github.com/users/hadikazemi/repos","events_url":"https://api.github.com/users/hadikazemi/events{/privacy}","received_events_url":"https://api.github.com/users/hadikazemi/received_events","type":"User","site_admin":false},"created_at":"2016-09-22T21:33:29Z","updated_at":"2016-09-22T21:33:29Z","body":"You saved my day... image_dim_ordering was 'tf'"}}
{"actor":{"display_login":"hadikazemi"}}