首页 > 解决方案 > 使用来自 slim 的预训练模型训练 ssd inception_v3

问题描述

我想使用带有来自 SLIM(链接)的预训练模型的对象检测 API 来训练 ssd inception_v3 模型我尝试使用配置训练对象检测 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.* 后,我停止了 procces,加载并打印了所有张量的名称。

之后,我从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 中的分类器进行检测。

标签: pythontensorflow

解决方案


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

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

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


推荐阅读