полученный NodeDef упоминает, что attr 'T' отсутствует в Op <name = NonMaxSuppressionV3, когда запрашивает grpc api через тензорное сохранение на деокере - PullRequest
0 голосов
/ 08 ноября 2018

Я установил Tensorflow Serving на Docker и собрал свою собственную версию keol yolov3 через модуль tf.saved_model. Но когда я запросил свою модель через Tensorflow Serving gprc api, я получил эту ошибку:

<_Rendezvous of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "NodeDef mentions attr 'T' not in Op<name=NonMaxSuppressionV3; signature=boxes:float, scores:float, max_output_size:int32, iou_threshold:float, score_threshold:float -> selected_indices:int32>; NodeDef: {{node non_max_suppression/NonMaxSuppressionV3}} = NonMaxSuppressionV3[T=DT_FLOAT, _output_shapes=[[?]], _device="/job:localhost/replica:0/task:0/device:CPU:0"](boolean_mask/GatherV2/_861, boolean_mask_1/GatherV2/_863, Const_6, non_max_suppression/iou_threshold, non_max_suppression/score_threshold). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
[[{{node non_max_suppression/NonMaxSuppressionV3}} = NonMaxSuppressionV3[T=DT_FLOAT, _output_shapes=[[?]], _device="/job:localhost/replica:0/task:0/device:CPU:0"](boolean_mask/GatherV2/_861, boolean_mask_1/GatherV2/_863, Const_6, non_max_suppression/iou_threshold, non_max_suppression/score_threshold)]]"
debug_error_string = "{"created":"@1541581883.448168389","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"NodeDef mentions attr 'T' not in Op<name=NonMaxSuppressionV3; signature=boxes:float, scores:float, max_output_size:int32, iou_threshold:float, score_threshold:float -> selected_indices:int32>; NodeDef: {{node non_max_suppression/NonMaxSuppressionV3}} = NonMaxSuppressionV3[T=DT_FLOAT, _output_shapes=[[?]], _device="/job:localhost/replica:0/task:0/device:CPU:0"](boolean_mask/GatherV2/_861, boolean_mask_1/GatherV2/_863, Const_6, non_max_suppression/iou_threshold, non_max_suppression/score_threshold). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).\n\t [[{{node non_max_suppression/NonMaxSuppressionV3}} = NonMaxSuppressionV3[T=DT_FLOAT, _output_shapes=[[?]], _device="/job:localhost/replica:0/task:0/device:CPU:0"](boolean_mask/GatherV2/_861, boolean_mask_1/GatherV2/_863, Const_6, non_max_suppression/iou_threshold, non_max_suppression/score_threshold)]]","grpc_status":3}"

PS: все работало нормально, когда я изменил модель yolov3 на простую классификационную модель

Мой env :

**OS Platform and Distribution **:Linux Ubuntu 16.04
**TensorFlow Serving installed from **: docker image tensorflow/serving:latest-gpu(Created"2018-10-23T21:38:54.625545811Z")
TensorFlow Serving version:1.11.1
TensorFlow version:1.12.0rc2
TensorFlow-Serving-api version:1.11.0

вот где я использовал NonMaxSuppression:

nms_index = tf.image.non_max_suppression(
            class_boxes, class_box_scores, max_boxes_tensor, iou_threshold=iou_threshold)
class_boxes = K.gather(class_boxes, nms_index)

вот мои коды:

#######save keras model########
person_detect_model = YOLO()
outputs = person_detect_model.outputs()
inputs = person_detect_model.inputs()

def save_model_to_serving(inputs, outputs, export_version, export_path):
    for i in range(len(inputs)):
        inputs[i] = tf.saved_model.utils.build_tensor_info(inputs[i])
    for i in range(len(outputs)):
        outputs[i] = tf.saved_model.utils.build_tensor_info(outputs[i])

    signature = tf.saved_model.signature_def_utils.build_signature_def(                                                                        
        inputs={'x': inputs[0],'shape':inputs[1]}, 
        outputs={'boxes':outputs[0], 'scores':outputs[1], 'classes': outputs[2]},
        method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)

    export_path = export_path+'/'+export_version
    builder = tf.saved_model.builder.SavedModelBuilder(export_path)
    main_op = tf.group(tf.tables_initializer(), name='main_op')
    builder.add_meta_graph_and_variables(
        sess=person_detect_model.sess,                                                                                                                    
        tags=[tf.saved_model.tag_constants.SERVING],                                                                                             
        signature_def_map={                                                                                                                      
            'detect_image': signature,                                                                                                                     
        },
        main_op=main_op)
    builder.save()

with person_detect_model.graph.as_default():
    save_model_to_serving(inputs, outputs, '1111', './yolov3')

#######request grpc api########
channel = grpc.insecure_channel('127.0.0.1:8500')
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)

request = predict_pb2.PredictRequest()
request.model_spec.name = 'yolov3'
request.model_spec.signature_name = 'detect_image'

file_path = '/home/sw/Work/tf/test2/0000.jpg'

img = Image.open(file_path)
img = np.array(img)
image = pretreat(img)

request.inputs['x'].CopyFrom(tf.contrib.util.make_tensor_proto(image))
request.inputs['shape'].CopyFrom(tf.contrib.util.make_tensor_proto([img.shape[0], img.shape[1]]))

result_future = stub.Predict.future(request, 10)
exception = result_future.exception()
if exception:
    print(exception)
else:
    response = numpy.array([
    result_future.result().outputs['boxes'].float_val,
    result_future.result().outputs['scores'].float_val,
    result_future.result().outputs['classes'].int_val])
    print response

Спасибо за помощь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...