简体   繁体   English

如何在张量流服务中传递单个图像?

[英]How to pass single image in tensorflow serving?

I have a yolo model hosted on tensorflow serving on localhost, to test it out ,I have to pass single image instead of batch of images,this is how I am trying by 我有一个托管在localhost上的tensorflow上的yolo模型,要对其进行测试,我必须传递单个图像而不是成批图像,这就是我正在尝试的方法

from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc
import cv2 as cv
channel = grpc.insecure_channel("8501")

stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)

request.model_spec.name = 'yolo'
request.model_spec.signature_name = 'predict'
image = cv.imread("test.jpg")

Now after this when Im trying to assign inputs 现在之后,当我试图分配输入时

>>> request.inputs['images'].CopyFrom(image)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Parameter to CopyFrom() must be instance of same class: expected tensorflow.TensorProto got numpy.ndarray.

I am getting this error,how can I pass single image in request ? 我收到此错误,如何在请求中传递单个图像?

request.inputs['image'].CopyFrom(
    tf.contrib.util.make_tensor_proto(image, shape = [1]))
result = stub.Predict(request, 10.0)

Try this 尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM