ssd mobilenet v1:更改特征图布局

ssd mobilenet v1: change feature map layout

我正在尝试重新训练 SSD 模型以检测一个 class 自定义对象(吉他)。 我正在使用 ssd_mobilenet_v1_coco 模型,其中包含从 OpenImage 数据集下载的 1000K 预标记图像的数据集。
我指的是 this answer 以尝试改进图像中小物体的检测。

按照那里的建议,我想在已经存在的特征图上添加一个额外的特征图 (Conv2d_5_pointwise),因此总共有 7 个特征图。所以,我这样修改了 "models/ssd_mobilenet_v1_feature_extractor.py":

 feature_map_layout = {
        'from_layer': ['Conv2d_5_pointwise','Conv2d_11_pointwise', 'Conv2d_13_pointwise', '', '',
                       '', ''][:self._num_layers],
        'layer_depth': [-1, -1, -1, 512, 256, 256, 128][:self._num_layers],
        'use_explicit_padding': self._use_explicit_padding,
        'use_depthwise': self._use_depthwise,
    }

因此,我也将配置文件中的 num_layers 更改为 7。


    anchor_generator {
      ssd_anchor_generator {
        num_layers: 7
        min_scale: 0.2
        max_scale: 0.95
        aspect_ratios: 1.0
        aspect_ratios: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 3.0
        aspect_ratios: 0.3333
      }
    }

但是,当尝试使用 main_model.py 训练模型时,我收到错误消息


 File "/home/carlo/projects/tf_models/research/object_detection/core/anchor_generator.py", line 105, in generate
    raise ValueError('Number of feature maps is expected to equal the length '
ValueError: Number of feature maps is expected to equal the length of `num_anchors_per_location`.

我是否应该修改任何其他内容以使其工作? 谢谢!

好的,明白了。

简单地说,我不得不在SSDMobileNetV1FeatureExtractor的构造函数中修改另一个参数(num_layers)class:

def __init__(self,
           is_training,
           depth_multiplier,
           min_depth,
           pad_to_multiple,
           conv_hyperparams_fn,
           reuse_weights=None,
           use_explicit_padding=False,
           use_depthwise=False,

           num_layers=7,    <--- HERE

           override_base_feature_extractor_hyperparams=False):

匹配新的特征图数量。

我在 ssd 模型中尝试使用具有以下配置的 multiscale_anchor_generator 时遇到问题。我必须在 feature_extractor 部分下将 num_layers 设置为 5 才能修复它。

multiscale_anchor_generator {
  min_level: 3
  max_level: 7
  anchor_scale: 4.0
  aspect_ratios: [1.0, 2.0, 0.5]
  scales_per_octave: 2
}