Tensorflow 服务类型:对象不是预期类型:uint8



所以我正在尝试通过张量流服务来提供COCO,如果我检查模型,我会得到以下内容:

signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['inputs'] tensor_info:
dtype: DT_UINT8
shape: (-1, -1, -1, 3)
name: image_tensor:0
The given SavedModel SignatureDef contains the following output(s):
outputs['detection_boxes'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 100, 4)
name: detection_boxes:0
outputs['detection_classes'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 100)
name: detection_classes:0
outputs['detection_masks'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, -1, -1)
name: detection_masks:0
outputs['detection_scores'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 100)
name: detection_scores:0
outputs['num_detections'] tensor_info:
dtype: DT_FLOAT
shape: (-1)
name: num_detections:0
Method name is: tensorflow/serving/predict

我的测试代码如下:

import json
import numpy as np
import cv2
import base64
import requests
import base64
import json
image = "./frames/IMG_0474.MOV/IMG_0474_100.jpg"
URL = "http://localhost:8501/v1/models/saved_model/versions/1:predict" 
headers = {"content-type": "application/json"}
image_content = base64.b64encode(cv2.imread(image)).decode("utf-8")
body = {
"signature_name": "serving_default",
"inputs": [{"image": {"b64":image_content}}]
}
r = requests.post(URL, data=json.dumps(body), headers = headers) 
print(r.text)

这会产生:

"error": "JSON Value: {n    "b64": [massive long base64 string]}n} Type: Object is not of expected type: uint8" }

也尝试过(相同的结果(:

body = {
"signature_name": "serving_default",
"instances": [{"inputs": {"b64":image_content}}]
}

最后(相同的结果(:

body = {
"signature_name": "serving_default",
"inputs": {"b64":image_content}
}

在文件进行base64编码之前,我还通过执行以下操作进行了仔细检查:

print(image.dtype)

输出为 uint8!

我也尝试修补对象,即删除图像并仅使用带有"b64"..."的数组 - 没有快乐。

我错过了什么?

尝试在opencv中加载图像并将其转换为列表并发送。您不必以 base64 格式对其进行编码。然后它应该可以工作。

import json
import numpy as np
import cv2
import base64
import requests
import base64
import json
image = "./frames/IMG_0474.MOV/IMG_0474_100.jpg"
URL = "http://localhost:8501/v1/models/saved_model/versions/1:predict" 
headers = {"content-type": "application/json"}
image_content = cv2.imread(image,1).astype('uint8').tolist()
body = {"instances": [{"inputs": image_content}]}
r = requests.post(URL, data=json.dumps(body), headers = headers) 
print(r.text)

相关内容

最新更新