diff --git a/docs/source/models/faster_rcnn.rst b/docs/source/models/faster_rcnn.rst new file mode 100644 index 00000000000..43d8c8b6f68 --- /dev/null +++ b/docs/source/models/faster_rcnn.rst @@ -0,0 +1,29 @@ +Faster R-CNN +========== + +.. currentmodule:: torchvision.models.detection + +The Faster R-CNN model is based on the `Faster R-CNN: Towards Real-Time Object Detection +with Region Proposal Networks `__ +paper. + + +Model builders +-------------- + +The following model builders can be used to instantiate a Faster R-CNN model, with or +without pre-trained weights. All the model builders internally rely on the +``torchvision.models.detection.faster_rcnn.FasterRCNN`` base class. Please refer to the `source +code +`_ for +more details about this class. + +.. autosummary:: + :toctree: generated/ + :template: function.rst + + fasterrcnn_resnet50_fpn + fasterrcnn_resnet50_fpn_v2 + fasterrcnn_mobilenet_v3_large_fpn + fasterrcnn_mobilenet_v3_large_320_fpn + diff --git a/docs/source/models_new.rst b/docs/source/models_new.rst index 0bda2f3f74e..f217028412a 100644 --- a/docs/source/models_new.rst +++ b/docs/source/models_new.rst @@ -97,6 +97,7 @@ weights: .. toctree:: :maxdepth: 1 + models/faster_rcnn models/fcos models/mask_rcnn models/retinanet diff --git a/torchvision/models/detection/faster_rcnn.py b/torchvision/models/detection/faster_rcnn.py index f1da6f77835..9a0ce20410e 100644 --- a/torchvision/models/detection/faster_rcnn.py +++ b/torchvision/models/detection/faster_rcnn.py @@ -453,10 +453,9 @@ def fasterrcnn_resnet50_fpn( **kwargs: Any, ) -> FasterRCNN: """ - Constructs a Faster R-CNN model with a ResNet-50-FPN backbone. - - Reference: `"Faster R-CNN: Towards Real-Time Object Detection with - Region Proposal Networks" `_. + Faster R-CNN model with a ResNet-50-FPN backbone from the `Faster R-CNN: Towards Real-Time Object + Detection with Region Proposal Networks `__ + 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. @@ -510,13 +509,26 @@ def fasterrcnn_resnet50_fpn( >>> torch.onnx.export(model, x, "faster_rcnn.onnx", opset_version = 11) Args: - weights (FasterRCNN_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.FasterRCNN_ResNet50_FPN_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.detection.FasterRCNN_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.faster_rcnn.FasterRCNN`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.detection.FasterRCNN_ResNet50_FPN_Weights + :members: """ weights = FasterRCNN_ResNet50_FPN_Weights.verify(weights) weights_backbone = ResNet50_Weights.verify(weights_backbone) @@ -553,21 +565,34 @@ def fasterrcnn_resnet50_fpn_v2( **kwargs: Any, ) -> FasterRCNN: """ - Constructs an improved Faster R-CNN model with a ResNet-50-FPN backbone. - - Reference: `"Benchmarking Detection Transfer Learning with Vision Transformers" - `_. + Constructs an improved Faster R-CNN model with a ResNet-50-FPN backbone from `Benchmarking Detection + Transfer Learning with Vision Transformers `__ paper. - :func:`~torchvision.models.detection.fasterrcnn_resnet50_fpn` for more details. + It works similarly to Faster R-CNN with ResNet-50 FPN backbone. See + :func:`~torchvision.models.detection.fasterrcnn_resnet50_fpn` for more + details. Args: - weights (FasterRCNN_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.FasterRCNN_ResNet50_FPN_V2_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.detection.FasterRCNN_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.faster_rcnn.FasterRCNN`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.detection.FasterRCNN_ResNet50_FPN_V2_Weights + :members: """ weights = FasterRCNN_ResNet50_FPN_V2_Weights.verify(weights) weights_backbone = ResNet50_Weights.verify(weights_backbone) @@ -658,7 +683,8 @@ def fasterrcnn_mobilenet_v3_large_320_fpn( **kwargs: Any, ) -> FasterRCNN: """ - Constructs a low resolution Faster R-CNN model with a MobileNetV3-Large FPN backbone tunned for mobile use-cases. + Low resolution Faster R-CNN model with a MobileNetV3-Large backbone tunned for mobile use cases. + It works similarly to Faster R-CNN with ResNet-50 FPN backbone. See :func:`~torchvision.models.detection.fasterrcnn_resnet50_fpn` for more details. @@ -671,13 +697,26 @@ def fasterrcnn_mobilenet_v3_large_320_fpn( >>> predictions = model(x) Args: - weights (FasterRCNN_MobileNet_V3_Large_320_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.FasterRCNN_MobileNet_V3_Large_320_FPN_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_320_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 (MobileNet_V3_Large_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 6, with 6 meaning all backbone layers are trainable. If ``None`` is - passed (the default) this value is set to 3. + weights_backbone (:class:`~torchvision.models.MobileNet_V3_Large_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 6, with 6 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.faster_rcnn.FasterRCNN`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_320_FPN_Weights + :members: """ weights = FasterRCNN_MobileNet_V3_Large_320_FPN_Weights.verify(weights) weights_backbone = MobileNet_V3_Large_Weights.verify(weights_backbone) @@ -728,13 +767,26 @@ def fasterrcnn_mobilenet_v3_large_fpn( >>> predictions = model(x) Args: - weights (FasterRCNN_MobileNet_V3_Large_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.FasterRCNN_MobileNet_V3_Large_FPN_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_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 (MobileNet_V3_Large_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 6, with 6 meaning all backbone layers are trainable. If ``None`` is - passed (the default) this value is set to 3. + weights_backbone (:class:`~torchvision.models.MobileNet_V3_Large_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 6, with 6 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.faster_rcnn.FasterRCNN`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_FPN_Weights + :members: """ weights = FasterRCNN_MobileNet_V3_Large_FPN_Weights.verify(weights) weights_backbone = MobileNet_V3_Large_Weights.verify(weights_backbone)