{"action":"opened","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/6408","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/6408/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/6408/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/6408/events","html_url":"https://github.com/fchollet/keras/issues/6408","id":224593785,"number":6408,"title":"Merging two pretrained models  1. bottom VGG16 with its weights 2. Customized FC with weights for predicting new data","user":{"login":"KamalOthman","id":22082511,"avatar_url":"https://avatars2.githubusercontent.com/u/22082511?v=3","gravatar_id":"","url":"https://api.github.com/users/KamalOthman","html_url":"https://github.com/KamalOthman","followers_url":"https://api.github.com/users/KamalOthman/followers","following_url":"https://api.github.com/users/KamalOthman/following{/other_user}","gists_url":"https://api.github.com/users/KamalOthman/gists{/gist_id}","starred_url":"https://api.github.com/users/KamalOthman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KamalOthman/subscriptions","organizations_url":"https://api.github.com/users/KamalOthman/orgs","repos_url":"https://api.github.com/users/KamalOthman/repos","events_url":"https://api.github.com/users/KamalOthman/events{/privacy}","received_events_url":"https://api.github.com/users/KamalOthman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-26T20:44:56Z","updated_at":"2017-04-26T20:44:56Z","closed_at":null,"body":"Hi Everyone,\r\nI am working on a problem of binary-class following this link [https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html](url) using **the bottleneck features of a pre-trained network**. I trained the top model (FC), and everything is working well. After this stage, I saved top model with its weights as shown in the link.\r\n\r\nNow, I want to predict the class of a new image. Here is my code:\r\n\r\n```\r\nimport numpy as np\r\nimport scipy.misc\r\nfrom keras.applications.vgg16 import VGG16\r\nfrom keras.preprocessing import image\r\nfrom keras.applications.vgg16 import preprocess_input\r\n\r\ndef vgg16(img_path):\r\n    print('Loading VGG16')\r\n    model = VGG16(weights='imagenet', include_top=False )\r\n    img = image.load_img(img_path, target_size=(150, 150))\r\n    x = image.img_to_array(img)\r\n    print(x.shape)\r\n    x = np.expand_dims(x, axis=0)\r\n    x = preprocess_input(x)\r\n\r\n    features = model.predict(x)\r\n    print(features)\r\n    return features\r\n    \r\ndef resizing_image(img):\r\n    print('resizing an input image')\r\n    imgs = [np.transpose(scipy.misc.imresize(scipy.misc.imread(img), (150, 150)),\r\n                         (2,0,1)).astype('float32')]\r\n    print(type(imgs))\r\n    print(imgs[0].shape)\r\n    return np.array(imgs)/255 \r\n\r\ndef load_model(model_def_fname, model_weight_fname):\r\n    model = model_from_json(open(model_def_fname).read())\r\n    model.load_weights(model_weight_fname)\r\n    return model\r\n \r\ndef head_model(bottom_features):\r\n    print('loading the top model')\r\n    model = load_model(classifier_path, weights_path)\r\n    prediction = model.predict_classes(bottom_features)\r\n    return prediction\r\n       \r\nif __name__ == '__main__':\r\n\r\n    bottom_features = vgg16(image_path)\r\n    \r\n    head_prediction = head_model(bottom_features)\r\n    \r\n    print('prediction ', head_prediction)\r\n    \r\n    print('the program is done')\r\n```\r\n\r\nI need your help to solve this following error:\r\n\r\n> loading the top model\r\n('features shape ', (1, 4, 4, 512))\r\nTraceback (most recent call last):\r\n  File \"newData_prediction.py\", line 91, in <module>\r\n    head_prediction = head_model(bottom_features)\r\n  File \"newData_prediction.py\", line 77, in head_model\r\n    prediction = model.predict_classes(bottom_features)\r\n  File \"/home/kamal/anaconda2/lib/python2.7/site-packages/keras/models.py\", line 779, in predict_classes\r\n    proba = self.predict(x, batch_size=batch_size, verbose=verbose)\r\n  File \"/home/kamal/anaconda2/lib/python2.7/site-packages/keras/models.py\", line 671, in predict\r\n    return self.model.predict(x, batch_size=batch_size, verbose=verbose)\r\n  File \"/home/kamal/anaconda2/lib/python2.7/site-packages/keras/engine/training.py\", line 1161, in predict\r\n    check_batch_dim=False)\r\n  File \"/home/kamal/anaconda2/lib/python2.7/site-packages/keras/engine/training.py\", line 108, in standardize_input_data\r\n    str(array.shape))\r\nException: Error when checking : expected flatten_input_1 to have shape (None, 512, 4, 4) but got array with shape (1, 4, 4, 512)\r\n\r\n"}}
{"actor":{"display_login":"KamalOthman"}}