diff --git a/docs/source/models/shufflenetv2_quant.rst b/docs/source/models/shufflenetv2_quant.rst new file mode 100644 index 00000000000..4fa236d2565 --- /dev/null +++ b/docs/source/models/shufflenetv2_quant.rst @@ -0,0 +1,27 @@ +Quantized ShuffleNet V2 +======================= + +.. currentmodule:: torchvision.models.quantization + +The Quantized ShuffleNet V2 model is based on the `ShuffleNet V2: Practical Guidelines for Efficient +CNN Architecture Design `__ paper. + + +Model builders +-------------- + +The following model builders can be used to instantiate a quantized ShuffleNetV2 +model, with or without pre-trained weights. All the model builders internally rely +on the ``torchvision.models.quantization.shufflenetv2.QuantizableShuffleNetV2`` +base class. Please refer to the `source code +`_ +for more details about this class. + +.. autosummary:: + :toctree: generated/ + :template: function.rst + + shufflenet_v2_x0_5 + shufflenet_v2_x1_0 + shufflenet_v2_x1_5 + shufflenet_v2_x2_0 diff --git a/docs/source/models_new.rst b/docs/source/models_new.rst index fe101913f70..6ded8480425 100644 --- a/docs/source/models_new.rst +++ b/docs/source/models_new.rst @@ -206,6 +206,7 @@ pre-trained weights: models/mobilenetv2_quant models/mobilenetv3_quant models/resnet_quant + models/shufflenetv2_quant | diff --git a/torchvision/models/quantization/shufflenetv2.py b/torchvision/models/quantization/shufflenetv2.py index bfb708ae768..5672d850cf2 100644 --- a/torchvision/models/quantization/shufflenetv2.py +++ b/torchvision/models/quantization/shufflenetv2.py @@ -66,8 +66,11 @@ def fuse_model(self, is_qat: Optional[bool] = None) -> None: r"""Fuse conv/bn/relu modules in shufflenetv2 model Fuse conv+bn+relu/ conv+relu/conv+bn modules to prepare for quantization. - Model is modified in place. Note that this operation does not change numerics - and the model after modification is in floating point + Model is modified in place. + + .. note:: + Note that this operation does not change numerics + and the model after modification is in floating point """ for name, m in self._modules.items(): if name in ["conv1", "conv5"] and m is not None: @@ -205,8 +208,8 @@ def shufflenet_v2_x0_5( ) -> QuantizableShuffleNetV2: """ Constructs a ShuffleNetV2 with 0.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. + `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design + `__. .. note:: Note that ``quantize = True`` returns a quantized model with 8 bit @@ -214,10 +217,26 @@ def shufflenet_v2_x0_5( GPU inference is not yet supported. Args: - weights (ShuffleNet_V2_X0_5_QuantizedWeights or ShuffleNet_V2_X0_5_Weights, optional): The pretrained - weights for the model - progress (bool): If True, displays a progress bar of the download to stderr - quantize (bool): If True, return a quantized version of the model + weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X0_5_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights` 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. + quantize (bool, optional): If True, return a quantized version of the model. + Default is False. + **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ShuffleNet_V2_X0_5_Weights + :members: + :noindex: """ weights = (ShuffleNet_V2_X0_5_QuantizedWeights if quantize else ShuffleNet_V2_X0_5_Weights).verify(weights) return _shufflenetv2( @@ -242,8 +261,8 @@ def shufflenet_v2_x1_0( ) -> QuantizableShuffleNetV2: """ Constructs a ShuffleNetV2 with 1.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. + `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design + `__. .. note:: Note that ``quantize = True`` returns a quantized model with 8 bit @@ -251,10 +270,26 @@ def shufflenet_v2_x1_0( GPU inference is not yet supported. Args: - weights (ShuffleNet_V2_X1_0_QuantizedWeights or ShuffleNet_V2_X1_0_Weights, optional): The pretrained - weights for the model - progress (bool): If True, displays a progress bar of the download to stderr - quantize (bool): If True, return a quantized version of the model + weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_0_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights` 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. + quantize (bool, optional): If True, return a quantized version of the model. + Default is False. + **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ShuffleNet_V2_X1_0_Weights + :members: + :noindex: """ weights = (ShuffleNet_V2_X1_0_QuantizedWeights if quantize else ShuffleNet_V2_X1_0_Weights).verify(weights) return _shufflenetv2( @@ -271,8 +306,8 @@ def shufflenet_v2_x1_5( ) -> QuantizableShuffleNetV2: """ Constructs a ShuffleNetV2 with 1.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. + `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design + `__. .. note:: Note that ``quantize = True`` returns a quantized model with 8 bit @@ -280,10 +315,26 @@ def shufflenet_v2_x1_5( GPU inference is not yet supported. Args: - weights (ShuffleNet_V2_X1_5_QuantizedWeights or ShuffleNet_V2_X1_5_Weights, optional): The pretrained - weights for the model - progress (bool): If True, displays a progress bar of the download to stderr - quantize (bool): If True, return a quantized version of the model + weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_5_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights` 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. + quantize (bool, optional): If True, return a quantized version of the model. + Default is False. + **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ShuffleNet_V2_X1_5_Weights + :members: + :noindex: """ weights = (ShuffleNet_V2_X1_5_QuantizedWeights if quantize else ShuffleNet_V2_X1_5_Weights).verify(weights) return _shufflenetv2( @@ -300,8 +351,8 @@ def shufflenet_v2_x2_0( ) -> QuantizableShuffleNetV2: """ Constructs a ShuffleNetV2 with 2.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. + `ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design + `__. .. note:: Note that ``quantize = True`` returns a quantized model with 8 bit @@ -309,10 +360,26 @@ def shufflenet_v2_x2_0( GPU inference is not yet supported. Args: - weights (ShuffleNet_V2_X2_0_QuantizedWeights or ShuffleNet_V2_X2_0_Weights, optional): The pretrained - weights for the model - progress (bool): If True, displays a progress bar of the download to stderr - quantize (bool): If True, return a quantized version of the model + weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X2_0_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights` 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. + quantize (bool, optional): If True, return a quantized version of the model. + Default is False. + **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ShuffleNet_V2_X2_0_Weights + :members: + :noindex: """ weights = (ShuffleNet_V2_X2_0_QuantizedWeights if quantize else ShuffleNet_V2_X2_0_Weights).verify(weights) return _shufflenetv2(