+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

如何将base64映像发送到gRPC TF服务服务器而不是HTTP请求?

发布于2020-09-12 11:53     阅读(1042)     评论(0)     点赞(13)     收藏(3)


当我在tf服务中提供对象检测模型并通过http请求访问它时,我有一个工作代码相同的代码是:

import requests
import base64
import json

URL = "http://10.10.1.38:8501/v1/models/test_model:predict" 
headers = {"content-type": "application/json"}
image = "test111.jpg"
image_content = base64.b64encode(open(image,'rb').read())
encodedStr = str(image_content, "utf-8")
body = {"signature_name": "predict_images","inputs": [{"b64":encodedStr}]}
response = requests.post(URL, data=json.dumps(body), headers = headers) 

我想做同样的事情,但是使用gRPC客户代码

该代码是:

import grpc
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc

image = "test111.jpg"
image_content = base64.b64encode(open(image,'rb').read())
encodedStr = str(image_content, "utf-8")

server = 'localhost:8500'
channel = grpc.insecure_channel(server)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = 'test_model'
request.model_spec.signature_name = 'predict_images'
request.inputs['inputs'].CopyFrom(tf.contrib.util.make_tensor_proto(encodedStr, shape=[1]))
result_future = stub.Predict(request,40.)

但这引发了下面的错误:

_Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]
[[{{node map/while/decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/Assert}}]]"
debug_error_string = "{"created":"@1579785768.913000000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]\n\t [[{{node map/while/decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/Assert}}]]","grpc_status":3}"
>

解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/519128/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

13 0
收藏该文
已收藏

评论内容:(最多支持255个字符)