Unverified Commit a1232c21 authored by Zhiqiang Wang's avatar Zhiqiang Wang Committed by GitHub
Browse files

Revamp docs for Quantized ShuffleNetV2 (#6028)

parent 769ae132
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 <https://arxiv.org/abs/1807.11164>`__ 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
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
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
...@@ -206,6 +206,7 @@ pre-trained weights: ...@@ -206,6 +206,7 @@ pre-trained weights:
models/mobilenetv2_quant models/mobilenetv2_quant
models/mobilenetv3_quant models/mobilenetv3_quant
models/resnet_quant models/resnet_quant
models/shufflenetv2_quant
| |
......
...@@ -66,8 +66,11 @@ class QuantizableShuffleNetV2(shufflenetv2.ShuffleNetV2): ...@@ -66,8 +66,11 @@ class QuantizableShuffleNetV2(shufflenetv2.ShuffleNetV2):
r"""Fuse conv/bn/relu modules in shufflenetv2 model r"""Fuse conv/bn/relu modules in shufflenetv2 model
Fuse conv+bn+relu/ conv+relu/conv+bn modules to prepare for quantization. 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 Model is modified in place.
and the model after modification is in floating point
.. 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(): for name, m in self._modules.items():
if name in ["conv1", "conv5"] and m is not None: if name in ["conv1", "conv5"] and m is not None:
...@@ -205,8 +208,8 @@ def shufflenet_v2_x0_5( ...@@ -205,8 +208,8 @@ def shufflenet_v2_x0_5(
) -> QuantizableShuffleNetV2: ) -> QuantizableShuffleNetV2:
""" """
Constructs a ShuffleNetV2 with 0.5x output channels, as described in 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
<https://arxiv.org/abs/1807.11164>`_. <https://arxiv.org/abs/1807.11164>`__.
.. note:: .. note::
Note that ``quantize = True`` returns a quantized model with 8 bit Note that ``quantize = True`` returns a quantized model with 8 bit
...@@ -214,10 +217,26 @@ def shufflenet_v2_x0_5( ...@@ -214,10 +217,26 @@ def shufflenet_v2_x0_5(
GPU inference is not yet supported. GPU inference is not yet supported.
Args: Args:
weights (ShuffleNet_V2_X0_5_QuantizedWeights or ShuffleNet_V2_X0_5_Weights, optional): The pretrained weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X0_5_Weights`, optional): The
weights for the model pretrained weights for the model. See
progress (bool): If True, displays a progress bar of the download to stderr :class:`~torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights` below for
quantize (bool): If True, return a quantized version of the model 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
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
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) weights = (ShuffleNet_V2_X0_5_QuantizedWeights if quantize else ShuffleNet_V2_X0_5_Weights).verify(weights)
return _shufflenetv2( return _shufflenetv2(
...@@ -242,8 +261,8 @@ def shufflenet_v2_x1_0( ...@@ -242,8 +261,8 @@ def shufflenet_v2_x1_0(
) -> QuantizableShuffleNetV2: ) -> QuantizableShuffleNetV2:
""" """
Constructs a ShuffleNetV2 with 1.0x output channels, as described in 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
<https://arxiv.org/abs/1807.11164>`_. <https://arxiv.org/abs/1807.11164>`__.
.. note:: .. note::
Note that ``quantize = True`` returns a quantized model with 8 bit Note that ``quantize = True`` returns a quantized model with 8 bit
...@@ -251,10 +270,26 @@ def shufflenet_v2_x1_0( ...@@ -251,10 +270,26 @@ def shufflenet_v2_x1_0(
GPU inference is not yet supported. GPU inference is not yet supported.
Args: Args:
weights (ShuffleNet_V2_X1_0_QuantizedWeights or ShuffleNet_V2_X1_0_Weights, optional): The pretrained weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_0_Weights`, optional): The
weights for the model pretrained weights for the model. See
progress (bool): If True, displays a progress bar of the download to stderr :class:`~torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights` below for
quantize (bool): If True, return a quantized version of the model 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
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
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) weights = (ShuffleNet_V2_X1_0_QuantizedWeights if quantize else ShuffleNet_V2_X1_0_Weights).verify(weights)
return _shufflenetv2( return _shufflenetv2(
...@@ -271,8 +306,8 @@ def shufflenet_v2_x1_5( ...@@ -271,8 +306,8 @@ def shufflenet_v2_x1_5(
) -> QuantizableShuffleNetV2: ) -> QuantizableShuffleNetV2:
""" """
Constructs a ShuffleNetV2 with 1.5x output channels, as described in 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
<https://arxiv.org/abs/1807.11164>`_. <https://arxiv.org/abs/1807.11164>`__.
.. note:: .. note::
Note that ``quantize = True`` returns a quantized model with 8 bit Note that ``quantize = True`` returns a quantized model with 8 bit
...@@ -280,10 +315,26 @@ def shufflenet_v2_x1_5( ...@@ -280,10 +315,26 @@ def shufflenet_v2_x1_5(
GPU inference is not yet supported. GPU inference is not yet supported.
Args: Args:
weights (ShuffleNet_V2_X1_5_QuantizedWeights or ShuffleNet_V2_X1_5_Weights, optional): The pretrained weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_5_Weights`, optional): The
weights for the model pretrained weights for the model. See
progress (bool): If True, displays a progress bar of the download to stderr :class:`~torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights` below for
quantize (bool): If True, return a quantized version of the model 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
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
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) weights = (ShuffleNet_V2_X1_5_QuantizedWeights if quantize else ShuffleNet_V2_X1_5_Weights).verify(weights)
return _shufflenetv2( return _shufflenetv2(
...@@ -300,8 +351,8 @@ def shufflenet_v2_x2_0( ...@@ -300,8 +351,8 @@ def shufflenet_v2_x2_0(
) -> QuantizableShuffleNetV2: ) -> QuantizableShuffleNetV2:
""" """
Constructs a ShuffleNetV2 with 2.0x output channels, as described in 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
<https://arxiv.org/abs/1807.11164>`_. <https://arxiv.org/abs/1807.11164>`__.
.. note:: .. note::
Note that ``quantize = True`` returns a quantized model with 8 bit Note that ``quantize = True`` returns a quantized model with 8 bit
...@@ -309,10 +360,26 @@ def shufflenet_v2_x2_0( ...@@ -309,10 +360,26 @@ def shufflenet_v2_x2_0(
GPU inference is not yet supported. GPU inference is not yet supported.
Args: Args:
weights (ShuffleNet_V2_X2_0_QuantizedWeights or ShuffleNet_V2_X2_0_Weights, optional): The pretrained weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X2_0_Weights`, optional): The
weights for the model pretrained weights for the model. See
progress (bool): If True, displays a progress bar of the download to stderr :class:`~torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights` below for
quantize (bool): If True, return a quantized version of the model 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
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
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) weights = (ShuffleNet_V2_X2_0_QuantizedWeights if quantize else ShuffleNet_V2_X2_0_Weights).verify(weights)
return _shufflenetv2( return _shufflenetv2(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment