Tensorflow Serving从不返回用于对象检测的“检测框”和“ num_detections”

时间:2018-09-07 04:10:32

标签: object-detection tensorflow-serving object-detection-api

我正在尝试使用预训练的模型来进行Tensorflow Serving工作。我可以设置环境并使其正常运行,但是问题在于它总是返回“类”和“分数”。它从不返回“检测框”和“ num_detections”。

我尝试了多种预先训练的模型(ssd_inception,faster_rcnn_inception等),这是我遵循的步骤:

a)导出模型,使我具有以下目录结构: --1 ---- saved_model.pb ----变量 -------- variables.index -------- variables.data-00000-of-00001

b)将模型转移到我的Docker容器中 c)启动transerflow服务器 d)客户端脚本

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)

e)我每次都得到的输出:

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"
}

f)当我运行“ saved_model_cli show”命令时,我正在使用“ predict_images”签名: 带有标签集:“ serve”的MetaGraphDef包含以下SignatureDef:

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

任何人都可以帮助我了解为什么我的“结果”输出中没有显示“ detection_boxes”和“ num_detections”。 预先感谢。

0 个答案:

没有答案