From bfcd091cfeaa5722f755e9933afac32cc8f9f537 Mon Sep 17 00:00:00 2001 From: Yassine Alouini Date: Thu, 21 Apr 2022 17:43:16 +0200 Subject: [PATCH 1/6] [DOC] Add new EfficientNet doc. --- docs/source/models/efficientnet.rst | 31 +++++++++++++++++++++++++++++ docs/source/models_new.rst | 1 + 2 files changed, 32 insertions(+) create mode 100644 docs/source/models/efficientnet.rst diff --git a/docs/source/models/efficientnet.rst b/docs/source/models/efficientnet.rst new file mode 100644 index 00000000000..865a9cb6d2c --- /dev/null +++ b/docs/source/models/efficientnet.rst @@ -0,0 +1,31 @@ +EfficientNet +============ + +.. currentmodule:: torchvision.models + +The EfficientNet model is based on the `EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks `__ +paper. + + +Model builders +-------------- + +The following model builders can be used to instanciate an EfficientNet model, with or +without pre-trained weights. All the model builders internally rely on the +``torchvision.models.efficientnet.EfficientNet`` base class. Please refer to the `source +code +`_ for +more details about this class. + +.. autosummary:: + :toctree: generated/ + :template: function.rst + + efficientnet_b0 + efficientnet_b1 + efficientnet_b2 + efficientnet_b3 + efficientnet_b4 + efficientnet_b5 + efficientnet_b6 + efficientnet_b7 \ No newline at end of file diff --git a/docs/source/models_new.rst b/docs/source/models_new.rst index a8fdad8efb0..137340daf32 100644 --- a/docs/source/models_new.rst +++ b/docs/source/models_new.rst @@ -36,6 +36,7 @@ weights: .. toctree:: :maxdepth: 1 + models/efficientnet models/resnet models/squeezenet models/vgg From 64e44ed6f0c81bc031a68faedb5fb2fbaee60452 Mon Sep 17 00:00:00 2001 From: Yassine Alouini Date: Thu, 21 Apr 2022 17:44:34 +0200 Subject: [PATCH 2/6] [DOC] Add missing file. --- torchvision/models/efficientnet.py | 164 ++++++++++++++++++++++------- 1 file changed, 124 insertions(+), 40 deletions(-) diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index a5519c60824..e61cf3fe41d 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -662,17 +662,29 @@ class EfficientNet_V2_L_Weights(WeightsEnum): DEFAULT = IMAGENET1K_V1 + + @handle_legacy_interface(weights=("pretrained", EfficientNet_B0_Weights.IMAGENET1K_V1)) def efficientnet_b0( *, weights: Optional[EfficientNet_B0_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B0 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B0 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B0_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.EfficientNet_B0_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B0_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B0_Weights + :members: """ weights = EfficientNet_B0_Weights.verify(weights) @@ -680,17 +692,29 @@ def efficientnet_b0( return _efficientnet(inverted_residual_setting, 0.2, last_channel, weights, progress, **kwargs) + + @handle_legacy_interface(weights=("pretrained", EfficientNet_B1_Weights.IMAGENET1K_V1)) def efficientnet_b1( *, weights: Optional[EfficientNet_B1_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B1 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B1 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B1_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.EfficientNet_B1_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B1_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B1_Weights + :members: """ weights = EfficientNet_B1_Weights.verify(weights) @@ -702,13 +726,23 @@ def efficientnet_b1( def efficientnet_b2( *, weights: Optional[EfficientNet_B2_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B2 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B2 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B2_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.EfficientNet_B2_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B2_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B2_Weights + :members: """ weights = EfficientNet_B2_Weights.verify(weights) @@ -720,13 +754,23 @@ def efficientnet_b2( def efficientnet_b3( *, weights: Optional[EfficientNet_B3_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B3 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B3 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B3_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.EfficientNet_B3_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B3_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B3_Weights + :members: """ weights = EfficientNet_B3_Weights.verify(weights) @@ -738,13 +782,23 @@ def efficientnet_b3( def efficientnet_b4( *, weights: Optional[EfficientNet_B4_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B4 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B4 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B4_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.EfficientNet_B4_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B4_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B4_Weights + :members: """ weights = EfficientNet_B4_Weights.verify(weights) @@ -756,13 +810,23 @@ def efficientnet_b4( def efficientnet_b5( *, weights: Optional[EfficientNet_B5_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B5 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B5 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B5_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.EfficientNet_B5_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B5_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B5_Weights + :members: """ weights = EfficientNet_B5_Weights.verify(weights) @@ -782,13 +846,23 @@ def efficientnet_b5( def efficientnet_b6( *, weights: Optional[EfficientNet_B6_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B6 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B6 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B6_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.EfficientNet_B6_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B6_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B6_Weights + :members: """ weights = EfficientNet_B6_Weights.verify(weights) @@ -808,13 +882,23 @@ def efficientnet_b6( def efficientnet_b7( *, weights: Optional[EfficientNet_B7_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """ - Constructs a EfficientNet B7 architecture from - `"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" `_. + """EfficientNet B7 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks" `_ paper. Args: - weights (EfficientNet_B7_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.EfficientNet_B7_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.EfficientNet_B7_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. + **kwargs: parameters passed to the ``torchvision.models.efficientnet.EfficientNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.EfficientNet_B7_Weights + :members: """ weights = EfficientNet_B7_Weights.verify(weights) From e7531f2dd64f3d99442a50cbd0da08550ae35fc5 Mon Sep 17 00:00:00 2001 From: Yassine Alouini Date: Thu, 21 Apr 2022 18:05:07 +0200 Subject: [PATCH 3/6] [FIX] Precommits fix. --- docs/source/models/efficientnet.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/models/efficientnet.rst b/docs/source/models/efficientnet.rst index 865a9cb6d2c..45866fa313d 100644 --- a/docs/source/models/efficientnet.rst +++ b/docs/source/models/efficientnet.rst @@ -28,4 +28,4 @@ more details about this class. efficientnet_b4 efficientnet_b5 efficientnet_b6 - efficientnet_b7 \ No newline at end of file + efficientnet_b7 From 66381728ea379a2704bfb61db7707d53697d35ac Mon Sep 17 00:00:00 2001 From: Yassine Alouini Date: Thu, 21 Apr 2022 18:07:13 +0200 Subject: [PATCH 4/6] [FIX] Precommits fix. --- torchvision/models/efficientnet.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index e61cf3fe41d..63910c39dbe 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -662,8 +662,6 @@ class EfficientNet_V2_L_Weights(WeightsEnum): DEFAULT = IMAGENET1K_V1 - - @handle_legacy_interface(weights=("pretrained", EfficientNet_B0_Weights.IMAGENET1K_V1)) def efficientnet_b0( *, weights: Optional[EfficientNet_B0_Weights] = None, progress: bool = True, **kwargs: Any @@ -692,8 +690,6 @@ def efficientnet_b0( return _efficientnet(inverted_residual_setting, 0.2, last_channel, weights, progress, **kwargs) - - @handle_legacy_interface(weights=("pretrained", EfficientNet_B1_Weights.IMAGENET1K_V1)) def efficientnet_b1( *, weights: Optional[EfficientNet_B1_Weights] = None, progress: bool = True, **kwargs: Any From af9ee0d420b7dfd978366ac4fcaee9e4cd750585 Mon Sep 17 00:00:00 2001 From: Yassine Alouini Date: Fri, 22 Apr 2022 14:44:57 +0200 Subject: [PATCH 5/6] [ENH] Integrate few documentation comments from code review --- docs/source/models/efficientnet.rst | 2 +- torchvision/models/efficientnet.py | 32 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/source/models/efficientnet.rst b/docs/source/models/efficientnet.rst index 45866fa313d..643f8407862 100644 --- a/docs/source/models/efficientnet.rst +++ b/docs/source/models/efficientnet.rst @@ -3,7 +3,7 @@ EfficientNet .. currentmodule:: torchvision.models -The EfficientNet model is based on the `EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks `__ +The EfficientNet model is based on the `EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks `__ paper. diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index 374b6c27a02..79c3b967492 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -651,8 +651,8 @@ class EfficientNet_V2_L_Weights(WeightsEnum): def efficientnet_b0( *, weights: Optional[EfficientNet_B0_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B0 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B0 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B0_Weights`, optional): The @@ -679,8 +679,8 @@ def efficientnet_b0( def efficientnet_b1( *, weights: Optional[EfficientNet_B1_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B1 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B1 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B1_Weights`, optional): The @@ -707,8 +707,8 @@ def efficientnet_b1( def efficientnet_b2( *, weights: Optional[EfficientNet_B2_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B2 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B2 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B2_Weights`, optional): The @@ -735,8 +735,8 @@ def efficientnet_b2( def efficientnet_b3( *, weights: Optional[EfficientNet_B3_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B3 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B3 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B3_Weights`, optional): The @@ -763,8 +763,8 @@ def efficientnet_b3( def efficientnet_b4( *, weights: Optional[EfficientNet_B4_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B4 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B4 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B4_Weights`, optional): The @@ -791,8 +791,8 @@ def efficientnet_b4( def efficientnet_b5( *, weights: Optional[EfficientNet_B5_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B5 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B5 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B5_Weights`, optional): The @@ -827,8 +827,8 @@ def efficientnet_b5( def efficientnet_b6( *, weights: Optional[EfficientNet_B6_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B6 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B6 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B6_Weights`, optional): The @@ -863,8 +863,8 @@ def efficientnet_b6( def efficientnet_b7( *, weights: Optional[EfficientNet_B7_Weights] = None, progress: bool = True, **kwargs: Any ) -> EfficientNet: - """EfficientNet B7 model architecture from the `"EfficientNet: Rethinking Model Scaling for Convolutional - Neural Networks" `_ paper. + """EfficientNet B7 model architecture from the `EfficientNet: Rethinking Model Scaling for Convolutional + Neural Networks `_ paper. Args: weights (:class:`~torchvision.models.EfficientNet_B7_Weights`, optional): The From 56abb92436a0e3ca7f11b53bc2d5ad75f12fc6d4 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 25 Apr 2022 09:58:48 +0100 Subject: [PATCH 6/6] Update docs/source/models/efficientnet.rst --- docs/source/models/efficientnet.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/models/efficientnet.rst b/docs/source/models/efficientnet.rst index 643f8407862..4df547b3cbd 100644 --- a/docs/source/models/efficientnet.rst +++ b/docs/source/models/efficientnet.rst @@ -3,7 +3,7 @@ EfficientNet .. currentmodule:: torchvision.models -The EfficientNet model is based on the `EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks `__ +The EfficientNet model is based on the `EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks `__ paper.