Skip to content

Commit 4d61aeb

Browse files
abhi-glitchhgdatumboxNicolasHug
authored
Revamp docs for Faster RCNN (#5918)
* init * init * Update torchvision/models/detection/faster_rcnn.py Co-authored-by: Vasilis Vryniotis <[email protected]> * Update torchvision/models/detection/faster_rcnn.py Co-authored-by: Vasilis Vryniotis <[email protected]> Co-authored-by: Vasilis Vryniotis <[email protected]> Co-authored-by: Nicolas Hug <[email protected]>
1 parent 33a408a commit 4d61aeb

File tree

3 files changed

+116
-34
lines changed

3 files changed

+116
-34
lines changed

docs/source/models/faster_rcnn.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Faster R-CNN
2+
==========
3+
4+
.. currentmodule:: torchvision.models.detection
5+
6+
The Faster R-CNN model is based on the `Faster R-CNN: Towards Real-Time Object Detection
7+
with Region Proposal Networks <https://arxiv.org/abs/1506.01497>`__
8+
paper.
9+
10+
11+
Model builders
12+
--------------
13+
14+
The following model builders can be used to instantiate a Faster R-CNN model, with or
15+
without pre-trained weights. All the model builders internally rely on the
16+
``torchvision.models.detection.faster_rcnn.FasterRCNN`` base class. Please refer to the `source
17+
code
18+
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/faster_rcnn.py>`_ for
19+
more details about this class.
20+
21+
.. autosummary::
22+
:toctree: generated/
23+
:template: function.rst
24+
25+
fasterrcnn_resnet50_fpn
26+
fasterrcnn_resnet50_fpn_v2
27+
fasterrcnn_mobilenet_v3_large_fpn
28+
fasterrcnn_mobilenet_v3_large_320_fpn
29+

docs/source/models_new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ weights:
9797
.. toctree::
9898
:maxdepth: 1
9999

100+
models/faster_rcnn
100101
models/fcos
101102
models/mask_rcnn
102103
models/retinanet

torchvision/models/detection/faster_rcnn.py

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,9 @@ def fasterrcnn_resnet50_fpn(
453453
**kwargs: Any,
454454
) -> FasterRCNN:
455455
"""
456-
Constructs a Faster R-CNN model with a ResNet-50-FPN backbone.
457-
458-
Reference: `"Faster R-CNN: Towards Real-Time Object Detection with
459-
Region Proposal Networks" <https://arxiv.org/abs/1506.01497>`_.
456+
Faster R-CNN model with a ResNet-50-FPN backbone from the `Faster R-CNN: Towards Real-Time Object
457+
Detection with Region Proposal Networks <https://arxiv.org/abs/1703.06870>`__
458+
paper.
460459
461460
The input to the model is expected to be a list of tensors, each of shape ``[C, H, W]``, one for each
462461
image, and should be in ``0-1`` range. Different images can have different sizes.
@@ -510,13 +509,26 @@ def fasterrcnn_resnet50_fpn(
510509
>>> torch.onnx.export(model, x, "faster_rcnn.onnx", opset_version = 11)
511510
512511
Args:
513-
weights (FasterRCNN_ResNet50_FPN_Weights, optional): The pretrained weights for the model
514-
progress (bool): If True, displays a progress bar of the download to stderr
512+
weights (:class:`~torchvision.models.detection.FasterRCNN_ResNet50_FPN_Weights`, optional): The
513+
pretrained weights to use. See
514+
:class:`~torchvision.models.detection.FasterRCNN_ResNet50_FPN_Weights` below for
515+
more details, and possible values. By default, no pre-trained
516+
weights are used.
517+
progress (bool, optional): If True, displays a progress bar of the
518+
download to stderr. Default is True.
515519
num_classes (int, optional): number of output classes of the model (including the background)
516-
weights_backbone (ResNet50_Weights, optional): The pretrained weights for the backbone
517-
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from final block.
518-
Valid values are between 0 and 5, with 5 meaning all backbone layers are trainable. If ``None`` is
519-
passed (the default) this value is set to 3.
520+
weights_backbone (:class:`~torchvision.models.ResNet50_Weights`, optional): The
521+
pretrained weights for the backbone.
522+
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from
523+
final block. Valid values are between 0 and 5, with 5 meaning all backbone layers are
524+
trainable. If ``None`` is passed (the default) this value is set to 3.
525+
**kwargs: parameters passed to the ``torchvision.models.detection.faster_rcnn.FasterRCNN``
526+
base class. Please refer to the `source code
527+
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/faster_rcnn.py>`_
528+
for more details about this class.
529+
530+
.. autoclass:: torchvision.models.detection.FasterRCNN_ResNet50_FPN_Weights
531+
:members:
520532
"""
521533
weights = FasterRCNN_ResNet50_FPN_Weights.verify(weights)
522534
weights_backbone = ResNet50_Weights.verify(weights_backbone)
@@ -553,21 +565,34 @@ def fasterrcnn_resnet50_fpn_v2(
553565
**kwargs: Any,
554566
) -> FasterRCNN:
555567
"""
556-
Constructs an improved Faster R-CNN model with a ResNet-50-FPN backbone.
557-
558-
Reference: `"Benchmarking Detection Transfer Learning with Vision Transformers"
559-
<https://arxiv.org/abs/2111.11429>`_.
568+
Constructs an improved Faster R-CNN model with a ResNet-50-FPN backbone from `Benchmarking Detection
569+
Transfer Learning with Vision Transformers <https://arxiv.org/abs/2111.11429>`__ paper.
560570
561-
:func:`~torchvision.models.detection.fasterrcnn_resnet50_fpn` for more details.
571+
It works similarly to Faster R-CNN with ResNet-50 FPN backbone. See
572+
:func:`~torchvision.models.detection.fasterrcnn_resnet50_fpn` for more
573+
details.
562574
563575
Args:
564-
weights (FasterRCNN_ResNet50_FPN_V2_Weights, optional): The pretrained weights for the model
565-
progress (bool): If True, displays a progress bar of the download to stderr
576+
weights (:class:`~torchvision.models.detection.FasterRCNN_ResNet50_FPN_V2_Weights`, optional): The
577+
pretrained weights to use. See
578+
:class:`~torchvision.models.detection.FasterRCNN_ResNet50_FPN_V2_Weights` below for
579+
more details, and possible values. By default, no pre-trained
580+
weights are used.
581+
progress (bool, optional): If True, displays a progress bar of the
582+
download to stderr. Default is True.
566583
num_classes (int, optional): number of output classes of the model (including the background)
567-
weights_backbone (ResNet50_Weights, optional): The pretrained weights for the backbone
568-
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from final block.
569-
Valid values are between 0 and 5, with 5 meaning all backbone layers are trainable. If ``None`` is
570-
passed (the default) this value is set to 3.
584+
weights_backbone (:class:`~torchvision.models.ResNet50_Weights`, optional): The
585+
pretrained weights for the backbone.
586+
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from
587+
final block. Valid values are between 0 and 5, with 5 meaning all backbone layers are
588+
trainable. If ``None`` is passed (the default) this value is set to 3.
589+
**kwargs: parameters passed to the ``torchvision.models.detection.faster_rcnn.FasterRCNN``
590+
base class. Please refer to the `source code
591+
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/faster_rcnn.py>`_
592+
for more details about this class.
593+
594+
.. autoclass:: torchvision.models.detection.FasterRCNN_ResNet50_FPN_V2_Weights
595+
:members:
571596
"""
572597
weights = FasterRCNN_ResNet50_FPN_V2_Weights.verify(weights)
573598
weights_backbone = ResNet50_Weights.verify(weights_backbone)
@@ -658,7 +683,8 @@ def fasterrcnn_mobilenet_v3_large_320_fpn(
658683
**kwargs: Any,
659684
) -> FasterRCNN:
660685
"""
661-
Constructs a low resolution Faster R-CNN model with a MobileNetV3-Large FPN backbone tunned for mobile use-cases.
686+
Low resolution Faster R-CNN model with a MobileNetV3-Large backbone tunned for mobile use cases.
687+
662688
It works similarly to Faster R-CNN with ResNet-50 FPN backbone. See
663689
:func:`~torchvision.models.detection.fasterrcnn_resnet50_fpn` for more
664690
details.
@@ -671,13 +697,26 @@ def fasterrcnn_mobilenet_v3_large_320_fpn(
671697
>>> predictions = model(x)
672698
673699
Args:
674-
weights (FasterRCNN_MobileNet_V3_Large_320_FPN_Weights, optional): The pretrained weights for the model
675-
progress (bool): If True, displays a progress bar of the download to stderr
700+
weights (:class:`~torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_320_FPN_Weights`, optional): The
701+
pretrained weights to use. See
702+
:class:`~torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_320_FPN_Weights` below for
703+
more details, and possible values. By default, no pre-trained
704+
weights are used.
705+
progress (bool, optional): If True, displays a progress bar of the
706+
download to stderr. Default is True.
676707
num_classes (int, optional): number of output classes of the model (including the background)
677-
weights_backbone (MobileNet_V3_Large_Weights, optional): The pretrained weights for the backbone
678-
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from final block.
679-
Valid values are between 0 and 6, with 6 meaning all backbone layers are trainable. If ``None`` is
680-
passed (the default) this value is set to 3.
708+
weights_backbone (:class:`~torchvision.models.MobileNet_V3_Large_Weights`, optional): The
709+
pretrained weights for the backbone.
710+
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from
711+
final block. Valid values are between 0 and 6, with 6 meaning all backbone layers are
712+
trainable. If ``None`` is passed (the default) this value is set to 3.
713+
**kwargs: parameters passed to the ``torchvision.models.detection.faster_rcnn.FasterRCNN``
714+
base class. Please refer to the `source code
715+
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/faster_rcnn.py>`_
716+
for more details about this class.
717+
718+
.. autoclass:: torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_320_FPN_Weights
719+
:members:
681720
"""
682721
weights = FasterRCNN_MobileNet_V3_Large_320_FPN_Weights.verify(weights)
683722
weights_backbone = MobileNet_V3_Large_Weights.verify(weights_backbone)
@@ -728,13 +767,26 @@ def fasterrcnn_mobilenet_v3_large_fpn(
728767
>>> predictions = model(x)
729768
730769
Args:
731-
weights (FasterRCNN_MobileNet_V3_Large_FPN_Weights, optional): The pretrained weights for the model
732-
progress (bool): If True, displays a progress bar of the download to stderr
770+
weights (:class:`~torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_FPN_Weights`, optional): The
771+
pretrained weights to use. See
772+
:class:`~torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_FPN_Weights` below for
773+
more details, and possible values. By default, no pre-trained
774+
weights are used.
775+
progress (bool, optional): If True, displays a progress bar of the
776+
download to stderr. Default is True.
733777
num_classes (int, optional): number of output classes of the model (including the background)
734-
weights_backbone (MobileNet_V3_Large_Weights, optional): The pretrained weights for the backbone
735-
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from final block.
736-
Valid values are between 0 and 6, with 6 meaning all backbone layers are trainable. If ``None`` is
737-
passed (the default) this value is set to 3.
778+
weights_backbone (:class:`~torchvision.models.MobileNet_V3_Large_Weights`, optional): The
779+
pretrained weights for the backbone.
780+
trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from
781+
final block. Valid values are between 0 and 6, with 6 meaning all backbone layers are
782+
trainable. If ``None`` is passed (the default) this value is set to 3.
783+
**kwargs: parameters passed to the ``torchvision.models.detection.faster_rcnn.FasterRCNN``
784+
base class. Please refer to the `source code
785+
<https://github.com/pytorch/vision/blob/main/torchvision/models/detection/faster_rcnn.py>`_
786+
for more details about this class.
787+
788+
.. autoclass:: torchvision.models.detection.FasterRCNN_MobileNet_V3_Large_FPN_Weights
789+
:members:
738790
"""
739791
weights = FasterRCNN_MobileNet_V3_Large_FPN_Weights.verify(weights)
740792
weights_backbone = MobileNet_V3_Large_Weights.verify(weights_backbone)

0 commit comments

Comments
 (0)