【发布时间】:2019-10-07 03:25:21
【问题描述】:
我正在尝试将基于对象检测的模型与 Tensorflow REST API 结合使用。我已经使用 GRPC 模式做到了。我输入了一个解析为 numpy 数组的 base64 图像,如下代码:
#Converting to byte array
image = base64.b64decode(input)
#Now converting to numpy array
nparr = np.fromstring(image, np.uint8)
#Decode into image object
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
#Expandind the array
image_expanded = np.expand_dims(image, axis=0)
#Making the predict of image
result = self._predict(image_expanded, label_map_string, num_classes, image)
所以我调用了 predict 方法,这就是 grpc 调用发生的地方:
stub = self._connection()
result = None
request = predict_pb2.PredictRequest()
request.model_spec.name = self.lst_model_names[0]
request.model_spec.signature_name = self.signature_name
label_map = label_map_util.load_labelmap(label_map_string)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=num_classes,
use_display_name=True)
category_index = label_map_util.create_category_index(categories)
request.inputs['inputs'].CopyFrom(
tf.contrib.util.make_tensor_proto(data))
result = stub.Predict.future(request, self.timeout)
在请求对象中我有类似的东西:
model_spec {
name: "object_detection"
signature_name: "serving_default"
}
inputs {
key: "inputs"
value {
dtype: DT_UINT8
tensor_shape {
dim {
size: 1
}
dim {
size: 720
}
dim {
size: 1280
}
dim {
size: 3
}
}
tensor_content: "&/3 )-\037%*!\',#)..."
}
它在 grpc 中完美运行。
对于 Tensorflow REST API,我不知道它应该如何工作。 我已经构建了这样的有效载荷:
{
"signature_name": "serving_default",
"inputs":{
"inputs":[
{
"b64":""
}
]
}
}
将图像输入作为 base64 格式传递。
我做错了什么?
每次我发送请求时都会出错:
Type: Object is not of expected type: uint8"
这个结构有问题吗?
我应该如何构建正确的 json 来预测对象检测模型?
非常感谢!
【问题讨论】:
标签: rest tensorflow request tensorflow-serving object-detection-api