How to properly serve an object detection model from Tensorflow Object Detection API?

前端 未结 4 1040
清歌不尽
清歌不尽 2021-02-15 23:06

I am using Tensorflow Object Detection API(github.com/tensorflow/models/tree/master/object_detection) with one object detection task. Right now I am having problem on serving th

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-15 23:59

    1. Your idea is fine. It' ok to have that warning.

    2. The issue is that the input needs to be converted to uint8 as the model expects. Here is the code snippet that worked for me.

    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'gan'
    request.model_spec.signature_name = 
        signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
    
    image = Image.open('any.jpg')
    image_np = load_image_into_numpy_array(image)
    image_np_expanded = np.expand_dims(image_np, axis=0)
    
    request.inputs['inputs'].CopyFrom(
        tf.contrib.util.make_tensor_proto(image_np_expanded, 
            shape=image_np_expanded.shape, dtype='uint8'))
    

    This part is important for you shape=image_np_expanded.shape, dtype='uint8' and make sure to pull the latest update for serving.

提交回复
热议问题