Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

So I'm trying to serve COCO via tensorflow serving, if I inspect the model I get the following:

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

My test code is as follows:

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)

Which yields:

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

Also tried(same result):

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

And finally(Same result):

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

I also double checked before the file is base64 encoded by doing:

print(image.dtype)

Output is uint8!

I've also tried tinkering with the object, ie remove image and just having the array with "b64" "..." - no joy.

What am I missing?

like image 409
Mrk Fldig Avatar asked Jan 23 '26 06:01

Mrk Fldig


1 Answers

Try loading the image in opencv and convert it to a list and send that. You don't have to encode it in base64 format. It should work then.

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)
like image 190
Chandan Gm Avatar answered Jan 24 '26 21:01

Chandan Gm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!