maskrcnn_benchmark工程的github链接为:https://github.com/facebookresearch/maskrcnn-benchmark
该工程文件目录树如下:
maskrcnn_benchmark
|——tools
|——train.net & test_net 分别为训练和测试网络的接口文件
|——configs——*.yaml 配置文件,用户通过该文件向神经网络传递训练参数;
|——maskrcnn_benchmark 核心代码文件夹
|——config
|——defaults.py 定义了默认的训练参数,即网络需要的且未在*.yaml文件定义的参数;
|——modeling 网络结构定义
|——backbone (First stage: extract freatures, with networks such as ResNet-50, ResNet-101, ResNet-152, etc)
|——rpn (Second stage:Region Proposal Network based on the extrated feature maps, propose candidate object bounding boxes & performs classification)
|——roi_heads (可根据需求选择加或者不加)
|—— box_head (bounding-box regression)
|——mask_head
|——keypoint_head (关键点)
|——detector——generalized_rcnn.py ( assemble the rpn & backbone & roi_heads)
|——model 存储训练好的模型 (pkl格式或者为pth格式)
|——demo 存储输入给网络的图片
1. resnet.py
主要支持Resnet50, Resnet101和Resnet152。具体变种包括:
_STAGE_SPECS = Registry({
"R-50-C4": ResNet50StagesTo4,
"R-50-C5": ResNet50StagesTo5,
"R-101-C4": ResNet101StagesTo4,
"R-101-C5": ResNet101StagesTo5,
"R-50-FPN": ResNet50FPNStagesTo5,
"R-50-FPN-RETINANET": ResNet50FPNStagesTo5,
"R-101-FPN": ResNet101FPNStagesTo5,
"R-101-FPN-RETINANET": ResNet101FPNStagesTo5,
"R-152-FPN": ResNet152FPNStagesTo5,
})
其命名规则为:
StageSpec = namedtuple(
"StageSpec",
[
"index", # Index of the stage, eg 1, 2, ..,. 5
"block_count", # Number of residual blocks in the stage
"return_features", # True => return the last feature map from this stage
],
)
以ResNet50StagesTo5为例:
ResNet50StagesTo5 = tuple(
StageSpec(index=i, block_count=c, return_features=r)
for (i, c, r) in ((1, 3, False), (2, 4, False), (3, 6, False), (4, 3, True))
)
注意:如果网络结构名字中有FPN (Feature Pyramid Networks,使用网络输出的多尺度features信息),则所有的return_features全部设为True。但是,Resnet文件只根据configs文件夹中的*.yaml 配置文件所定义的MODEL.BACKBONE.CONV_BODY名称对ResNet的结构进行初始化,并不在resnet.py文件中包含FPN的网络结构。
2. backbone.py
根据cfg.MODEL.BACKBONE.CONV_BODY对Resnet网络进行初始化后,进一步根据cfg.MODEL.BACKBONE.CONV_BODY的名称添加需要的FPN网络层。
*.yaml配置文件的更改:
1、MODEL:WEIGHT: “
2、更改数据预处理(normalization),
INPUT:
PIXEL_MEAN: (mean_c1, mean_c2, mean_c3)
PIXEL_STD: (std_c1, std_c2, std_c3)
defaults.py更改:
1、_C.MODEL.SEGM_HEAD.NUM_CLASSES =
接口文件中:
image = cv2.resize(image, (Width, Height))