{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/serving/issues/972","repository_url":"https://api.github.com/repos/tensorflow/serving","labels_url":"https://api.github.com/repos/tensorflow/serving/issues/972/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/serving/issues/972/comments","events_url":"https://api.github.com/repos/tensorflow/serving/issues/972/events","html_url":"https://github.com/tensorflow/serving/issues/972","id":337883170,"node_id":"MDU6SXNzdWUzMzc4ODMxNzA=","number":972,"title":"Tensorflow serving predict call to keras pre trained model always give same result","user":{"login":"amithbk12man","id":10739723,"node_id":"MDQ6VXNlcjEwNzM5NzIz","avatar_url":"https://avatars1.githubusercontent.com/u/10739723?v=4","gravatar_id":"","url":"https://api.github.com/users/amithbk12man","html_url":"https://github.com/amithbk12man","followers_url":"https://api.github.com/users/amithbk12man/followers","following_url":"https://api.github.com/users/amithbk12man/following{/other_user}","gists_url":"https://api.github.com/users/amithbk12man/gists{/gist_id}","starred_url":"https://api.github.com/users/amithbk12man/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amithbk12man/subscriptions","organizations_url":"https://api.github.com/users/amithbk12man/orgs","repos_url":"https://api.github.com/users/amithbk12man/repos","events_url":"https://api.github.com/users/amithbk12man/events{/privacy}","received_events_url":"https://api.github.com/users/amithbk12man/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-03T12:44:51Z","updated_at":"2018-07-08T18:30:05Z","closed_at":"2018-07-08T18:30:05Z","author_association":"NONE","body":"I have exported two models one keras pre built Xception model and one my own model when I try to call predict call to them in tensorflow serving I always get the same result. Please help me what is the mistake am doing. In the below code    \" print(result2)\" aways give same result.\r\n\r\ndef main(_):\r\n    print(FLAGS.image)\r\n    host, port = FLAGS.server.split(':')\r\n    channel = implementations.insecure_channel(host, int(port))\r\n    stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)\r\n\r\n    # Change test image to RGB mode\r\n    # my code added\r\n    img = image.load_img(FLAGS.image, target_size=(299, 299))\r\n    a = image.img_to_array(img)\r\n    a = np.expand_dims(a, axis=0)\r\n    image_data = preprocess_input(a)\r\n    #print(image_data)\r\n    from keras.applications.xception import Xception\r\n    img_array = np.vstack(image_data)\r\n    model1 = Xception(weights='imagenet', include_top=False)\r\n    model1._make_predict_function()\r\n    print('now callng')\r\n    value = model1.predict(image_data, verbose=1)\r\n\r\n    # Create PredictRequest ProtoBuf from image data\r\n    request = predict_pb2.PredictRequest()\r\n    request.model_spec.name = \"Xception\"\r\n    request.model_spec.signature_name = \"prediction\"\r\n    print('calling function')\r\n    request.inputs[\"images\"].CopyFrom(\r\n        tf.contrib.util.make_tensor_proto(image_data, dtype=\"float32\", shape=[1,299,299,3]))\r\n\r\n    result = stub.Predict(request, 10.0)\r\n\r\n    stub2 = prediction_service_pb2.beta_create_PredictionService_stub(channel)\r\n    request2 = predict_pb2.PredictRequest()\r\n    request2.model_spec.name = \"Xception1a\"\r\n    request2.model_spec.signature_name = \"prediction\"\r\n\r\n    #request2.inputs[\"images\"].CopyFrom(\r\n    #    tf.contrib.util.make_tensor_proto(tensor_util.MakeNdarray(result.outputs[\"prediction\"]), dtype=\"float32\",shape=[1,10,10,2048]))\r\n\r\n    request2.inputs[\"images\"].CopyFrom(\r\n        tf.contrib.util.make_tensor_proto(value, dtype=\"float32\",shape=[1,10,10,2048]))\r\n    result2 = stub2.Predict(request2, 10.0)\r\n\r\n    print(result2)\r\n\r\nif __name__ == '__main__':\r\n  tf.app.run()"},"comment":{"url":"https://api.github.com/repos/tensorflow/serving/issues/comments/403306607","html_url":"https://github.com/tensorflow/serving/issues/972#issuecomment-403306607","issue_url":"https://api.github.com/repos/tensorflow/serving/issues/972","id":403306607,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzMwNjYwNw==","user":{"login":"amithbk12man","id":10739723,"node_id":"MDQ6VXNlcjEwNzM5NzIz","avatar_url":"https://avatars1.githubusercontent.com/u/10739723?v=4","gravatar_id":"","url":"https://api.github.com/users/amithbk12man","html_url":"https://github.com/amithbk12man","followers_url":"https://api.github.com/users/amithbk12man/followers","following_url":"https://api.github.com/users/amithbk12man/following{/other_user}","gists_url":"https://api.github.com/users/amithbk12man/gists{/gist_id}","starred_url":"https://api.github.com/users/amithbk12man/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amithbk12man/subscriptions","organizations_url":"https://api.github.com/users/amithbk12man/orgs","repos_url":"https://api.github.com/users/amithbk12man/repos","events_url":"https://api.github.com/users/amithbk12man/events{/privacy}","received_events_url":"https://api.github.com/users/amithbk12man/received_events","type":"User","site_admin":false},"created_at":"2018-07-08T18:30:05Z","updated_at":"2018-07-08T18:30:05Z","author_association":"NONE","body":"I found out the issue. In case of exception which is a pre trained model I was not explicitly loading the weights. Yes, preprocessing is required in the client call and I did so. Now, it works."}}
{"actor":{"display_login":"amithbk12man"}}