serving icon indicating copy to clipboard operation
serving copied to clipboard

Tensorflow Serving never returns "detection box" and "num_detections" for Object Detection

Open ashwinichhipa opened this issue 8 years ago • 1 comments

Describe the problem the feature is intended to solve

Hi,

I'm trying to get the Tensorflow Serving work with pre-trained models. I'm able to setup the environment and able to get it working, but the problem is for it always returns "classes" and "scores". It never returns "detection box" and "num_detections.

I have tried multiple pre-trained models (ssd_inception, faster_rcnn_inception etc), here are the steps I followed:

  1. Exported the model so that I have below dir structure: --1 ----saved_model.pb ----variables --------variables.index --------variables.data-00000-of-00001
  2. Transferred the model to my docker container
  3. Start the transerflow server
  4. Client Script
from grpc.beta import implementations
import tensorflow as tf
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2
import requests

server = '0.0.0.0:8500'
host, port = server.split(':')

image_url = "https://www.publicdomainpictures.net/pictures/60000/nahled/bird-1382034603Euc.jpg"

response = requests.get(image_url)

channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

request = predict_pb2.PredictRequest()
request.model_spec.name = 'inception'
request.model_spec.signature_name = 'predict_images'

request.inputs['images'].CopyFrom(
  tf.contrib.util.make_tensor_proto(response.content, shape = [1]))

result = stub.Predict(request, 10.0)
print(result)

  1. Output I get everytime:
Image shape: (407, 615, 3)
outputs {
  key: "classes"
  value {
    dtype: DT_STRING
    tensor_shape {
      dim {
        size: 1
      }
      dim {
        size: 5
      }
    }
    string_val: "brambling, Fringilla montifringilla"
    string_val: "house finch, linnet, Carpodacus mexicanus"
    string_val: "goldfinch, Carduelis carduelis"
    string_val: "indigo bunting, indigo finch, indigo bird, Passerina cyanea"
    string_val: "junco, snowbird"
  }
}
outputs {
  key: "scores"
  value {
    dtype: DT_FLOAT
    tensor_shape {
      dim {
        size: 1
      }
      dim {
        size: 5
      }
    }
    float_val: 8.91035842896
    float_val: 6.65493869781
    float_val: 5.94185781479
    float_val: 4.53237199783
    float_val: 4.1246099472
  }
}
model_spec {
  name: "inception"
  version {
    value: 1
  }
  signature_name: "predict_images"
}
  1. I'm using "predict_images" signature, when I run "saved_model_cli show" command:
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['predict_images']:
  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, 300, 4)
        name: detection_boxes:0
    outputs['detection_classes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 300)
        name: detection_classes:0
    outputs['detection_scores'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 300)
        name: detection_scores:0
    outputs['num_detections'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1)
        name: num_detections:0
  Method name is: tensorflow/serving/predict

Can anyone please help me understand why do I not get "detection_boxes" and "num_detections" in my "result" output. Thanks in advance.

ashwinichhipa avatar Sep 05 '18 03:09 ashwinichhipa

Please go to Stack Overflow for help and support:

https://stackoverflow.com/questions/tagged/tensorflow-serving

If you open a GitHub issue, it must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).

Thanks!

gautamvasudevan avatar Sep 06 '18 20:09 gautamvasudevan