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

Tensorflow Serving Type: Object is not of expected type: uint8

所以我正在尝试通过 tensorflow 服务为 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)