Skip to content

Commit

Permalink
docs: Added MaskRCNN to the new doc (#5900)
Browse files Browse the repository at this point in the history
* docs: Added MaskRCNN to new doc

* docs: Updated docstring

* ufmt

Co-authored-by: FG Fernandez <�[email protected]>
Co-authored-by: Nicolas Hug <[email protected]>
  • Loading branch information
3 people authored Apr 27, 2022
1 parent f014841 commit 557c5da
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
25 changes: 25 additions & 0 deletions docs/source/models/mask_rcnn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Mask R-CNN
==========

.. currentmodule:: torchvision.models.detection

The Mask R-CNN model is based on the `Mask R-CNN <https://arxiv.org/abs/1703.06870>`__
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
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/mask_rcnn.py>`_ for
more details about this class.

.. autosummary::
:toctree: generated/
:template: function.rst

maskrcnn_resnet50_fpn
maskrcnn_resnet50_fpn_v2
1 change: 1 addition & 0 deletions docs/source/models_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ weights:
:maxdepth: 1

models/retinanet
models/mask_rcnn

Table of all available detection weights
----------------------------------------
Expand Down
63 changes: 42 additions & 21 deletions torchvision/models/detection/mask_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" <https://arxiv.org/abs/1703.06870>`_.
"""Mask R-CNN model with a ResNet-50-FPN backbone from the `Mask R-CNN
<https://arxiv.org/abs/1703.06870>`_ 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.
Expand Down Expand Up @@ -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
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/mask_rcnn.py>`_
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)
Expand Down Expand Up @@ -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"
<https://arxiv.org/abs/2111.11429>`_.
"""Improved Mask R-CNN model with a ResNet-50-FPN backbone from the `Benchmarking Detection Transfer
Learning with Vision Transformers <https://arxiv.org/abs/2111.11429>`_ 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
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/mask_rcnn.py>`_
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)
Expand Down

0 comments on commit 557c5da

Please sign in to comment.