Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review By Rahul #1814

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions tensorflow_serving/example/inception_client.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

#!/usr/bin/env python2.7

"""Send JPEG image to tensorflow_model_server loaded with inception model.
"""

from __future__ import print_function

# This is a placeholder for a Google-internal import.
Expand All @@ -27,30 +9,45 @@

from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2

import base64
import os

tf.app.flags.DEFINE_string('server', 'localhost:9000',
'PredictionService host:port')
tf.app.flags.DEFINE_string('image', '', 'path to image in JPEG format')
FLAGS = tf.app.flags.FLAGS

class Processor:
__stub = None
__vocab = None
__wrap = None

def main(_):
host, port = FLAGS.server.split(':')
channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
# Send request
with open(FLAGS.image, 'rb') as f:
# See prediction_service.proto for gRPC request/response details.
data = f.read()
def __init__(self, server, dataDir):
host, port = server.split(':')
channel = implementations.insecure_channel(host, int(port))
self.__stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

def Process(self, modelName, inputList):
image = base64.decodestring(inputList[0])
# Send request
request = predict_pb2.PredictRequest()
request.model_spec.name = 'inception'
request.model_spec.name = modelName
request.model_spec.signature_name = 'predict_images'
request.inputs['images'].CopyFrom(
tf.contrib.util.make_tensor_proto(data, shape=[1]))
result = stub.Predict(request, 10.0) # 10 secs timeout
tf.contrib.util.make_tensor_proto(image, shape=[1]))
result = self.__stub.Predict(request, 10.0) # 10 secs timeout
print(result)
myresult = str(result)
return myresult


if __name__ == '__main__':
tf.app.run()
p = Processor(FLAGS.server, '')
image = open(FLAGS.image, 'rb')
ListOfInputs = []
image_read = image.read()
image_64_encode = base64.encodestring(image_read)
ListOfInputs.append(image_64_encode)
result = p.Process('inception', ListOfInputs)
print(result)