Skip to content

Commit

Permalink
Reducing Resolution to 320-640 and anchor sizes to 16-256.
Browse files Browse the repository at this point in the history
  • Loading branch information
datumbox committed Jan 14, 2021
1 parent c3dfca1 commit 24f1e90
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions torchvision/models/detection/faster_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def fasterrcnn_resnet50_fpn(pretrained=False, progress=True,


def fasterrcnn_mobilenet_v3_large(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True,
trainable_backbone_layers=None, **kwargs):
trainable_backbone_layers=None, min_size=320, max_size=640, **kwargs):
"""
Constructs a Faster R-CNN model with a MobileNetV3-Large backbone. It works similarly
to Faster R-CNN with ResNet-50 FPN backbone. See `fasterrcnn_resnet50_fpn` for more details.
Expand All @@ -391,6 +391,8 @@ def fasterrcnn_mobilenet_v3_large(pretrained=False, progress=True, num_classes=9
pretrained_backbone (bool): If True, returns a model with backbone pre-trained on Imagenet
trainable_backbone_layers (int): number of trainable (not frozen) resnet layers starting from final block.
Valid values are between 0 and 6, with 6 meaning all backbone layers are trainable.
min_size (int): minimum size of the image to be rescaled before feeding it to the backbone
max_size (int): maximum size of the image to be rescaled before feeding it to the backbone
"""
trainable_backbone_layers = _validate_trainable_layers(
pretrained or pretrained_backbone, trainable_backbone_layers, 6, 3)
Expand All @@ -400,19 +402,19 @@ def fasterrcnn_mobilenet_v3_large(pretrained=False, progress=True, num_classes=9
backbone = mobilenet_backbone("mobilenet_v3_large", pretrained_backbone, False,
trainable_layers=trainable_backbone_layers)

anchor_sizes = ((32, 64, 128, 256, 512), )
anchor_sizes = ((16, 32, 64, 128, 256), )
aspect_ratios = ((0.5, 1.0, 2.0), )

model = FasterRCNN(backbone, num_classes, rpn_anchor_generator=AnchorGenerator(anchor_sizes, aspect_ratios),
**kwargs)
min_size=min_size, max_size=max_size, **kwargs)
if pretrained:
state_dict = load_state_dict_from_url(model_urls['fasterrcnn_mobilenet_v3_large_coco'], progress=progress)
model.load_state_dict(state_dict)
return model


def fasterrcnn_mobilenet_v3_large_fpn(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True,
trainable_backbone_layers=None, **kwargs):
trainable_backbone_layers=None, min_size=320, max_size=640, **kwargs):
"""
Constructs a Faster R-CNN model with a MobileNetV3-Large FPN backbone. It works similarly
to Faster R-CNN with ResNet-50 FPN backbone. See `fasterrcnn_resnet50_fpn` for more details.
Expand All @@ -431,6 +433,8 @@ def fasterrcnn_mobilenet_v3_large_fpn(pretrained=False, progress=True, num_class
pretrained_backbone (bool): If True, returns a model with backbone pre-trained on Imagenet
trainable_backbone_layers (int): number of trainable (not frozen) resnet layers starting from final block.
Valid values are between 0 and 6, with 6 meaning all backbone layers are trainable.
min_size (int): minimum size of the image to be rescaled before feeding it to the backbone
max_size (int): maximum size of the image to be rescaled before feeding it to the backbone
"""
trainable_backbone_layers = _validate_trainable_layers(
pretrained or pretrained_backbone, trainable_backbone_layers, 6, 3)
Expand All @@ -440,11 +444,11 @@ def fasterrcnn_mobilenet_v3_large_fpn(pretrained=False, progress=True, num_class
backbone = mobilenet_backbone("mobilenet_v3_large", pretrained_backbone, True,
trainable_layers=trainable_backbone_layers)

anchor_sizes = ((32, 64, 128, 256, 512, ), ) * 3
anchor_sizes = ((16, 32, 64, 128, 256, ), ) * 3
aspect_ratios = ((0.5, 1.0, 2.0),) * len(anchor_sizes)

model = FasterRCNN(backbone, num_classes, rpn_anchor_generator=AnchorGenerator(anchor_sizes, aspect_ratios),
**kwargs)
min_size=min_size, max_size=max_size, **kwargs)
if pretrained:
state_dict = load_state_dict_from_url(model_urls['fasterrcnn_mobilenet_v3_large_fpn_coco'], progress=progress)
model.load_state_dict(state_dict)
Expand Down

0 comments on commit 24f1e90

Please sign in to comment.