diff --git a/docs/source/models/mask_rcnn.rst b/docs/source/models/mask_rcnn.rst new file mode 100644 index 00000000000..243cef7815c --- /dev/null +++ b/docs/source/models/mask_rcnn.rst @@ -0,0 +1,25 @@ +Mask R-CNN +========== + +.. currentmodule:: torchvision.models.detection + +The Mask R-CNN model is based on the `Mask R-CNN `__ +paper. + + +Model builders +-------------- + +The following model builders can be used to instantiate a Mask R-CNN model, with or +without pre-trained weights. All the model builders internally rely on the +``torchvision.models.detection.mask_rcnn.MaskRCNN`` base class. Please refer to the `source +code +`_ for +more details about this class. + +.. autosummary:: + :toctree: generated/ + :template: function.rst + + maskrcnn_resnet50_fpn + maskrcnn_resnet50_fpn_v2 diff --git a/docs/source/models_new.rst b/docs/source/models_new.rst index 41a7b3d482f..96cc260043a 100644 --- a/docs/source/models_new.rst +++ b/docs/source/models_new.rst @@ -94,6 +94,7 @@ weights: :maxdepth: 1 models/retinanet + models/mask_rcnn Table of all available detection weights ---------------------------------------- diff --git a/torchvision/models/detection/mask_rcnn.py b/torchvision/models/detection/mask_rcnn.py index 1f5953af48e..1b8eaa4b168 100644 --- a/torchvision/models/detection/mask_rcnn.py +++ b/torchvision/models/detection/mask_rcnn.py @@ -403,10 +403,8 @@ def maskrcnn_resnet50_fpn( trainable_backbone_layers: Optional[int] = None, **kwargs: Any, ) -> MaskRCNN: - """ - Constructs a Mask R-CNN model with a ResNet-50-FPN backbone. - - Reference: `"Mask R-CNN" `_. + """Mask R-CNN model with a ResNet-50-FPN backbone from the `Mask R-CNN + `_ paper. The input to the model is expected to be a list of tensors, each of shape ``[C, H, W]``, one for each image, and should be in ``0-1`` range. Different images can have different sizes. @@ -451,13 +449,26 @@ def maskrcnn_resnet50_fpn( >>> torch.onnx.export(model, x, "mask_rcnn.onnx", opset_version = 11) Args: - weights (MaskRCNN_ResNet50_FPN_Weights, optional): The pretrained weights for the model - progress (bool): If True, displays a progress bar of the download to stderr + weights (:class:`~torchvision.models.detection.MaskRCNN_ResNet50_FPN_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.detection.MaskRCNN_ResNet50_FPN_Weights` below for + more details, and possible values. By default, no pre-trained + weights are used. + progress (bool, optional): If True, displays a progress bar of the + download to stderr. Default is True. num_classes (int, optional): number of output classes of the model (including the background) - weights_backbone (ResNet50_Weights, optional): The pretrained weights for the backbone - trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from final block. - Valid values are between 0 and 5, with 5 meaning all backbone layers are trainable. If ``None`` is - passed (the default) this value is set to 3. + weights_backbone (:class:`~torchvision.models.ResNet50_Weights`, optional): The + pretrained weights for the backbone. + trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from + final block. Valid values are between 0 and 5, with 5 meaning all backbone layers are + trainable. If ``None`` is passed (the default) this value is set to 3. + **kwargs: parameters passed to the ``torchvision.models.detection.mask_rcnn.MaskRCNN`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.detection.MaskRCNN_ResNet50_FPN_Weights + :members: """ weights = MaskRCNN_ResNet50_FPN_Weights.verify(weights) weights_backbone = ResNet50_Weights.verify(weights_backbone) @@ -493,22 +504,32 @@ def maskrcnn_resnet50_fpn_v2( trainable_backbone_layers: Optional[int] = None, **kwargs: Any, ) -> MaskRCNN: - """ - Constructs an improved MaskRCNN model with a ResNet-50-FPN backbone. - - Reference: `"Benchmarking Detection Transfer Learning with Vision Transformers" - `_. + """Improved Mask R-CNN model with a ResNet-50-FPN backbone from the `Benchmarking Detection Transfer + Learning with Vision Transformers `_ paper. :func:`~torchvision.models.detection.maskrcnn_resnet50_fpn` for more details. Args: - weights (MaskRCNN_ResNet50_FPN_V2_Weights, optional): The pretrained weights for the model - progress (bool): If True, displays a progress bar of the download to stderr + weights (:class:`~torchvision.models.detection.MaskRCNN_ResNet50_FPN_V2_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.detection.MaskRCNN_ResNet50_FPN_V2_Weights` below for + more details, and possible values. By default, no pre-trained + weights are used. + progress (bool, optional): If True, displays a progress bar of the + download to stderr. Default is True. num_classes (int, optional): number of output classes of the model (including the background) - weights_backbone (ResNet50_Weights, optional): The pretrained weights for the backbone - trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from final block. - Valid values are between 0 and 5, with 5 meaning all backbone layers are trainable. If ``None`` is - passed (the default) this value is set to 3. + weights_backbone (:class:`~torchvision.models.ResNet50_Weights`, optional): The + pretrained weights for the backbone. + trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from + final block. Valid values are between 0 and 5, with 5 meaning all backbone layers are + trainable. If ``None`` is passed (the default) this value is set to 3. + **kwargs: parameters passed to the ``torchvision.models.detection.mask_rcnn.MaskRCNN`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.detection.MaskRCNN_ResNet50_FPN_V2_Weights + :members: """ weights = MaskRCNN_ResNet50_FPN_V2_Weights.verify(weights) weights_backbone = ResNet50_Weights.verify(weights_backbone)