为什么 Torchvision 预训练模型比从头训练的模型表现更好?

时间:2020-12-19 20:44:00

标签: pytorch image-segmentation torchvision

我遵循了 torchvision 教程 (https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html),并在我自己的航拍图像数据集上训练了一个分割模型。其中只有 2 个类。结果是:

Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.640
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.700

enter image description here

不错,但我想提高面具的准确性。

然后我用 pretrained=Falsepretrained_backbone=False 进行了完全相同的训练,并且非常惊讶地发现性能大约是预训练模型的一半。

Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.328
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.472

我正在尝试了解为什么会出现这种情况以及我应该将努力改进模型的方向:

  • 训练参数,如:lr、momentum、dropout、batch size ..
  • MaskRCNN 网络的架构:roi、anchors ..
  • 关于我的数据集的一些事情:添加增强..

我不知道去哪里了解如何提高性能。有什么好的方法可以解决这个问题?

编辑:我的模型是:

def get_model_instance_segmentation(num_classes):
    # load an instance segmentation model pre-trained pre-trained on COCO
    model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True)

    # get number of input features for the classifier
    in_features = model.roi_heads.box_predictor.cls_score.in_features
    # replace the pre-trained head with a new one
    model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)

    # now get the number of input features for the mask classifier
    in_features_mask = model.roi_heads.mask_predictor.conv5_mask.in_channels
    hidden_layer = 256
    # and replace the mask predictor with a new one
    model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask, hidden_layer, num_classes)
    return model

0 个答案:

没有答案