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

问题描述 投票:0回答:1

因此,我正在尝试通过张量流服务为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”“ ...”放置数组-不高兴。

我想念什么?

python tensorflow tensorflow-serving
1个回答
0
投票

尝试将图像加载到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)
© www.soinside.com 2019 - 2024. All rights reserved.