【问题标题】:Tensorflow Serving Type: Object is not of expected type: uint8Tensorflow 服务类型:对象不是预期类型:uint8
【发布时间】:2019-09-30 17:24:17
【问题描述】:

所以我试图通过 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”“...”的数组 - 不高兴。

我错过了什么?

【问题讨论】:

    标签: python tensorflow tensorflow-serving


    【解决方案1】:

    尝试在 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)
    

    【讨论】:

    • 嘿,谢谢,我想我试过了,我现在就测试一下。如果这行得通,那将是一个严肃的面部时刻,哈哈
    • { "error": "slice index 2 of dimension 0 out of bounds.\n\t [[{{node Preprocessor/map/while/ResizeToRange/strided_slice_2}}]]" } 是我现在得到回应,让我用谷歌搜索!
    • 嘿,伙计,不,我还在试图找出原因
    • 所以这一切都是基于 Matterport 的 MASK RCNN 实现
    • 我真的很快需要这个,所以如果你之前已经实现了这个,请看这里,抓住他们的 COCO 模型github.com/matterport/Mask_RCNN,如果你能让它符合标准,我会把赏金提高到 300可可模型?我们正在为tothehighstreet.com 的发布日期而着急,我已经超负荷了!此外,如果您确实做到了,那么在 LinkedIn 上查找 marcfielding 是值得的,因为您甚至可能需要一些日薪工作(我是 AWS 的人,照片上有乌龟)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    相关资源
    最近更新 更多