Tensorflow OD API - pipeline.config 在导出训练模型后发生变化

Tensorflow OD API - pipeline.config changes after exporting trained model

我正在使用 Tensorflow OD API 1.13 对来自 model zoo 的预训练 ssd_mobilent_v2_coco 进行迁移学习。完成训练后,我使用以下命令导出冻结图:

python object_detection\export_inference_graph.py ^
--input_type image_tensor ^
--pipeline_config_path C:\TF_train\models\model\pipeline.config ^
--trained_checkpoint_prefix C:\TF_train\models\model\model.ckpt-7200 ^
--output_directory C:\export\ssd_v2_7200

在输出文件夹中,有模型文件和一个pipeline.config文件。但是当我打开它并与原始的(用于训练模型)进行比较时,我发现一些字段发生了变化。

例如,这是原始 pipeline.config 中的特征提取器部分:

feature_extractor {
  type: "ssd_mobilenet_v2"
  depth_multiplier: 1.0
  min_depth: 16
  conv_hyperparams {
    regularizer {
      l2_regularizer {
        weight: 3.99999989895e-05
      }
    }
    initializer {
      truncated_normal_initializer {
        mean: 0.0
        stddev: 0.0299999993294
      }
    }
    activation: RELU_6
    batch_norm {
      decay: 0.999700009823
      center: true
      scale: true
      epsilon: 0.0010000000475
      train: true
    }
  }
  use_depthwise: true
}

并从导出 pipeline.config:

feature_extractor {
   type: "ssd_mobilenet_v2"
   depth_multiplier: 1.0
   min_depth: 16
   conv_hyperparams {
     regularizer {
       l2_regularizer {
         weight: 3.9999998989515007e-05
       }
     }
     initializer {
       truncated_normal_initializer {
         mean: 0.0
         stddev: 0.029999999329447746
       }
     }
     activation: RELU_6
     batch_norm {
       decay: 0.9997000098228455
       center: true
       scale: true
       epsilon: 0.0010000000474974513
       train: true
     }
   }
   use_depthwise: true
 }

注意,l2_regularizer 权重、stddev、衰减和 epsilon 的精度如何变化。这是预期的吗?为什么会这样?

原来是一个 protobuf issue:

We have a known issue for float type precision if it is using cpp extension:

Python does not have C-style float , it only has a C-style double. Thus pure python is using double precision for both float and double field, cpp extension is using float precision for float field.

我像这样检查了 protobuf 活动实现:

python -c "from google.protobuf.internal import api_implementation; print(api_implementation.Type())"

输出为 cpp。所以我添加了环境变量:

PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

现在它按预期工作了。