Deployed Tensorflow Serving und Renntest für Inception-V3. Funktioniert gut.Wie wird die Dosierung im Tensorflow-Serving durchgeführt?
Jetzt möchte Batching für Serving-Inception-V3 tun. Zum Beispiel möchte 10 Bilder für die Vorhersage anstelle von eins senden.
Wie geht das? Welche Dateien müssen aktualisiert werden (inception_saved_model.py oder inception_client.py)? Wie sehen diese Updates aus? und wie werden die Bilder an die Serving übergeben - ist es als Ordner mit Bildern oder wie?
Schätzen Sie einige Einblicke in dieses Problem. Jedes Code-Snippet, das damit in Zusammenhang steht, wird sehr hilfreich sein.
=================================
Aktualisiert inception_client.py
# 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
"""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.
from grpc.beta import implementations
import tensorflow as tf
from tensorflow.python.platform import flags
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2
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
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()
#request = predict_pb2.PredictRequest()
#request.model_spec.name = 'inception'
#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
# print(result)
# Build a batch of images
request = predict_pb2.PredictRequest()
request.model_spec.name = 'inception'
request.model_spec.signature_name = 'predict_images'
image_data = []
for image in FLAGS.image.split(','):
with open(image, 'rb') as f:
image_data.append(f.read())
request.inputs['images'].CopyFrom(
tf.contrib.util.make_tensor_proto(image_data, shape=[len(image_data)]))
result = stub.Predict(request, 10.0) # 10 secs timeout
print(result)
if __name__ == '__main__':
tf.app.run()
Können Sie den Einzug des eingefügten Codes überprüfen? (Es ist wahrscheinlich ein Problem mit der Formatierung von Stack Overflow, aber es könnte einen Fehler verbergen.) Und was ist der aktuelle Fehler, den Sie bekommen? – mrry
Sieht aus wie Stack Overflow Format Problem. Wird versuchen, das zu beheben. Hier ist der Fehler. Bazel-bin/tensorflow_serving/Beispiel/inception_batch_client --server = localhost: 9000 -image =/home/gpuadmin/serving/Bilder/boat.jpg,/home/gpuadmin/serving/images/boat.jpg Traceback (letzter Aufruf zuletzt): Datei "/home/gpuadmin/servicing/bazel-bin/tensorflow_serving/example/inception_batch_client.runfiles/tf_servic/tensorflow_serving/example/inception_batch_client.py", Zeile 63, in mit geöffnet (image, 'rb') as f: IOError: [Errno 2] Keine solche Datei oder Verzeichnis: '' –
Der Fehler wird ausgelöst, weil Sie versuchen, eine Datei zu lesen, die nicht gefunden wird. Es scheint, versucht zu haben, '' '' (die leere Zeichenkette) zu öffnen, also hat das 'FLAGS.image' möglicherweise nicht das richtige Format? Versuchen Sie vielleicht, 'FLAGS.image.split (',')' zu drucken, um herauszufinden, was falsch läuft? – mrry