From fd6d6656932050fefc3f0d3f58952be64cd832f0 Mon Sep 17 00:00:00 2001 From: FG Fernandez <–26927750+frgfm@users.noreply.github.com> Date: Wed, 27 Apr 2022 14:06:55 +0200 Subject: [PATCH 1/3] docs: Added MaskRCNN to new doc --- docs/source/models/mask_rcnn.rst | 25 +++++++++++++++++++++++++ docs/source/models_new.rst | 1 + 2 files changed, 26 insertions(+) create mode 100644 docs/source/models/mask_rcnn.rst 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 12249571e5c..efabe8ec0ac 100644 --- a/docs/source/models_new.rst +++ b/docs/source/models_new.rst @@ -93,6 +93,7 @@ weights: :maxdepth: 1 models/retinanet + models/mask_rcnn Table of all available detection weights ---------------------------------------- From 230b4cb3cacd11edaf1f17f2df83bbd4e9d84a7b Mon Sep 17 00:00:00 2001 From: FG Fernandez <–26927750+frgfm@users.noreply.github.com> Date: Wed, 27 Apr 2022 14:07:07 +0200 Subject: [PATCH 2/3] docs: Updated docstring --- torchvision/models/detection/mask_rcnn.py | 67 +++++++++++++++-------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/torchvision/models/detection/mask_rcnn.py b/torchvision/models/detection/mask_rcnn.py index 1f5953af48e..ea5e836a1a9 100644 --- a/torchvision/models/detection/mask_rcnn.py +++ b/torchvision/models/detection/mask_rcnn.py @@ -403,11 +403,9 @@ 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) From 5e45bb61f263d234d234c64026adc6ea300a8fdb Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 27 Apr 2022 17:15:01 +0100 Subject: [PATCH 3/3] ufmt --- torchvision/models/detection/mask_rcnn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torchvision/models/detection/mask_rcnn.py b/torchvision/models/detection/mask_rcnn.py index ea5e836a1a9..1b8eaa4b168 100644 --- a/torchvision/models/detection/mask_rcnn.py +++ b/torchvision/models/detection/mask_rcnn.py @@ -405,7 +405,7 @@ def maskrcnn_resnet50_fpn( ) -> MaskRCNN: """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. @@ -506,7 +506,7 @@ def maskrcnn_resnet50_fpn_v2( ) -> MaskRCNN: """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: