最近在学习mmdet这个工具包,用faster-rcnn训练yymnist,源代码中采用的主干网络为resnet50,在此基础上,尝试着更改了主干网络为mobilenetV2,其余暂时不变,竟然跑通了,再来学习网络结构。
打开mmdet/models/backbones/mobilenet_v2.py,查看mobilenetV2的参数说明,
# model settings model = dict( type='FasterRCNN', backbone=dict( type='MobileNetV2', #修改为MobileNetV2 widen_factor=1, out_indices=(1, 2, 4, 7), #24,32,96,1280 frozen_stages=1, norm_cfg=dict(type='BN'), act_cfg=dict(type='ReLU6'), norm_eval=True, init_cfg=dict(type='Pretrained', checkpoint='E:\Project\DL\weights\mobilenet_v2-b0353104.pth') #预训练权重 ),
复制faster_rcnn_r50_fpn.py配置文件,在这个文件中修改主干,根据mobilenetv2的初始化参数,修改配置中的参数如上图所示,就可以直接训练了。主要是修改通道数,预训练权重和一些resnet有而mobilenetv2中没有的参数,我是先把mobilenetv2的预训练权重下载到本地。
关于通道数的修改,我是参照mobilenetv2的源代码,默认的out_indices=(1, 2, 4, 7),即表示第1,2,4,7层的输出features作为MobileNet的输出。widen_factor
是Inverted residuals模块对输入通道数扩大的系数。