Tensorflow 输出节点替换为 StatefulPartitionedCall,它在加载时抛出 ValueError

use*_*050 5 python keras tensorflow

我正在 ssd_mobilenet_v2_coco_2018_03_29 模型上应用迁移学习。训练后,我使用tf.saved_model.save(model, saved_model_dir)将 keras 模型保存为 saved_model.pb。

原始 ssd_mobilenet_v2_coco_2018_03_29 模型具有以下签名 defs。

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_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
Run Code Online (Sandbox Code Playgroud)

保存的模型具有以下签名定义(默认值)。

  signature_def['__saved_model_init_op']:
  The given SavedModel SignatureDef contains the following input(s):
  The given SavedModel SignatureDef contains the following output(s):
    outputs['__saved_model_init_op'] tensor_info:
        dtype: DT_INVALID
        shape: unknown_rank
        name: NoOp
  Method name is:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['mobilenetv2_1.00_224_input'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 224, 224, 3)
        name: serving_default_mobilenetv2_1.00_224_input:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['dense'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 5)
        name: StatefulPartitionedCall:0
  Method name is: tensorflow/serving/predict
Run Code Online (Sandbox Code Playgroud)

原始模型有 4 个输出节点detection_boxes, detection_classes, detection_scores, num_detectionsStatefulPartitionedCall当我将它导出为保存的模型时,它是如何获得的?我使用 tensorboard 查看了保存的模型,所有 4 个输出节点都可见。

[张量板图像]:[1]:https ://i.stack.imgur.com/abbqI.png

当我尝试使用 batchnorm 加载(冻结)保存的模型时,出现以下错误 ValueError: Input 1 of node prefix/StatefulPartitionedCall was passed float from prefix/Conv1/kernel:0 incompatible with expected resource.

知道发生了什么吗?如何恢复原始输出节点(仍然可见)?