Skip to main content
 首页 » 编程设计

python之使用来自 slim 的预训练模型训练 ssd inception_v3

2024年12月31日24itcoder

我想使用对象检测 API 和来自 SLIM 的预训练模型来训练 ssd inception_v3 模型 (link) 我尝试使用配置来训练对象检测 ssd inception v3 模型:

model { 
  ssd { 
    num_classes: 1 
    image_resizer { 
      fixed_shape_resizer { 
        height: 240 
        width: 320 
      } 
    } 
    feature_extractor { 
      type: "ssd_inception_v3" 
      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 
        } 
      } 
      override_base_feature_extractor_hyperparams: true 
    } 
... 

我在创建文件 model.ckpt-0.* 后停止了进程,加载并打印了所有张量的名称。

之后,我从 https://github.com/tensorflow/models/tree/master/research/slim 加载了预训练模型使用

reader = pywrap_tensorflow.NewCheckpointReader(os.path.join(folder, 'model.ckpt')) 
var_to_shape_map = reader.get_variable_to_shape_map() 

当我比较输出时,我没有看到 ssd incpetion v3 模型有很多层。例如:

InceptionV3/AuxLogits/Conv2d_2a_5x5/weights InceptionV3/Mixed_7c/Branch_3/Conv2d_0b_1x1/weight

在 ssd_inception_v3 的模型中,我看到了 5c 之前的混合层。

SSD_inception 和 SLIM 模型中的 Feature Extractor 有什么区别?一般来说,是否可以从 SLIM 加载权重用于对象检测 API 中的分类器以进行检测。

请您参考如下方法:

您可以在 ssd_inception_v3_feature_extractor 中看到发生了什么. 它使用来自 inception_v3.inception_v3_base(注意 _base)的 InceptionV3 的“Mixed_5d”、“Mixed_6e”、“Mixed_7c”的输出,并使用 512 创建 3 个额外的特征图, 256、128 个 channel (这发生在 feature_map_generators.multi_resolution_feature_maps by feature_map_layout 中)。 加载检测模型的分类器的权重可以通过配置来完成:

train_config{ 
    ... 
    fine_tune_checkpoint: <path_to_inception_checkpoint> 
    fine_tune_checkpoint_type: "classification" 
} 

当然,检查点必须与您使用的模型相匹配,例如ssd_inception_v3。