Skip to content

Commit a1232c2

Browse files
authored
Revamp docs for Quantized ShuffleNetV2 (#6028)
1 parent 769ae13 commit a1232c2

File tree

3 files changed

+121
-26
lines changed

3 files changed

+121
-26
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Quantized ShuffleNet V2
2+
=======================
3+
4+
.. currentmodule:: torchvision.models.quantization
5+
6+
The Quantized ShuffleNet V2 model is based on the `ShuffleNet V2: Practical Guidelines for Efficient
7+
CNN Architecture Design <https://arxiv.org/abs/1807.11164>`__ paper.
8+
9+
10+
Model builders
11+
--------------
12+
13+
The following model builders can be used to instantiate a quantized ShuffleNetV2
14+
model, with or without pre-trained weights. All the model builders internally rely
15+
on the ``torchvision.models.quantization.shufflenetv2.QuantizableShuffleNetV2``
16+
base class. Please refer to the `source code
17+
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
18+
for more details about this class.
19+
20+
.. autosummary::
21+
:toctree: generated/
22+
:template: function.rst
23+
24+
shufflenet_v2_x0_5
25+
shufflenet_v2_x1_0
26+
shufflenet_v2_x1_5
27+
shufflenet_v2_x2_0

docs/source/models_new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ pre-trained weights:
206206
models/mobilenetv2_quant
207207
models/mobilenetv3_quant
208208
models/resnet_quant
209+
models/shufflenetv2_quant
209210

210211
|
211212

torchvision/models/quantization/shufflenetv2.py

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ def fuse_model(self, is_qat: Optional[bool] = None) -> None:
6666
r"""Fuse conv/bn/relu modules in shufflenetv2 model
6767
6868
Fuse conv+bn+relu/ conv+relu/conv+bn modules to prepare for quantization.
69-
Model is modified in place. Note that this operation does not change numerics
70-
and the model after modification is in floating point
69+
Model is modified in place.
70+
71+
.. note::
72+
Note that this operation does not change numerics
73+
and the model after modification is in floating point
7174
"""
7275
for name, m in self._modules.items():
7376
if name in ["conv1", "conv5"] and m is not None:
@@ -205,19 +208,35 @@ def shufflenet_v2_x0_5(
205208
) -> QuantizableShuffleNetV2:
206209
"""
207210
Constructs a ShuffleNetV2 with 0.5x output channels, as described in
208-
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design"
209-
<https://arxiv.org/abs/1807.11164>`_.
211+
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
212+
<https://arxiv.org/abs/1807.11164>`__.
210213
211214
.. note::
212215
Note that ``quantize = True`` returns a quantized model with 8 bit
213216
weights. Quantized models only support inference and run on CPUs.
214217
GPU inference is not yet supported.
215218
216219
Args:
217-
weights (ShuffleNet_V2_X0_5_QuantizedWeights or ShuffleNet_V2_X0_5_Weights, optional): The pretrained
218-
weights for the model
219-
progress (bool): If True, displays a progress bar of the download to stderr
220-
quantize (bool): If True, return a quantized version of the model
220+
weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X0_5_Weights`, optional): The
221+
pretrained weights for the model. See
222+
:class:`~torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights` below for
223+
more details, and possible values. By default, no pre-trained
224+
weights are used.
225+
progress (bool, optional): If True, displays a progress bar of the download to stderr.
226+
Default is True.
227+
quantize (bool, optional): If True, return a quantized version of the model.
228+
Default is False.
229+
**kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights``
230+
base class. Please refer to the `source code
231+
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
232+
for more details about this class.
233+
234+
.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights
235+
:members:
236+
237+
.. autoclass:: torchvision.models.ShuffleNet_V2_X0_5_Weights
238+
:members:
239+
:noindex:
221240
"""
222241
weights = (ShuffleNet_V2_X0_5_QuantizedWeights if quantize else ShuffleNet_V2_X0_5_Weights).verify(weights)
223242
return _shufflenetv2(
@@ -242,19 +261,35 @@ def shufflenet_v2_x1_0(
242261
) -> QuantizableShuffleNetV2:
243262
"""
244263
Constructs a ShuffleNetV2 with 1.0x output channels, as described in
245-
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design"
246-
<https://arxiv.org/abs/1807.11164>`_.
264+
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
265+
<https://arxiv.org/abs/1807.11164>`__.
247266
248267
.. note::
249268
Note that ``quantize = True`` returns a quantized model with 8 bit
250269
weights. Quantized models only support inference and run on CPUs.
251270
GPU inference is not yet supported.
252271
253272
Args:
254-
weights (ShuffleNet_V2_X1_0_QuantizedWeights or ShuffleNet_V2_X1_0_Weights, optional): The pretrained
255-
weights for the model
256-
progress (bool): If True, displays a progress bar of the download to stderr
257-
quantize (bool): If True, return a quantized version of the model
273+
weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_0_Weights`, optional): The
274+
pretrained weights for the model. See
275+
:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights` below for
276+
more details, and possible values. By default, no pre-trained
277+
weights are used.
278+
progress (bool, optional): If True, displays a progress bar of the download to stderr.
279+
Default is True.
280+
quantize (bool, optional): If True, return a quantized version of the model.
281+
Default is False.
282+
**kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights``
283+
base class. Please refer to the `source code
284+
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
285+
for more details about this class.
286+
287+
.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights
288+
:members:
289+
290+
.. autoclass:: torchvision.models.ShuffleNet_V2_X1_0_Weights
291+
:members:
292+
:noindex:
258293
"""
259294
weights = (ShuffleNet_V2_X1_0_QuantizedWeights if quantize else ShuffleNet_V2_X1_0_Weights).verify(weights)
260295
return _shufflenetv2(
@@ -271,19 +306,35 @@ def shufflenet_v2_x1_5(
271306
) -> QuantizableShuffleNetV2:
272307
"""
273308
Constructs a ShuffleNetV2 with 1.5x output channels, as described in
274-
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design"
275-
<https://arxiv.org/abs/1807.11164>`_.
309+
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
310+
<https://arxiv.org/abs/1807.11164>`__.
276311
277312
.. note::
278313
Note that ``quantize = True`` returns a quantized model with 8 bit
279314
weights. Quantized models only support inference and run on CPUs.
280315
GPU inference is not yet supported.
281316
282317
Args:
283-
weights (ShuffleNet_V2_X1_5_QuantizedWeights or ShuffleNet_V2_X1_5_Weights, optional): The pretrained
284-
weights for the model
285-
progress (bool): If True, displays a progress bar of the download to stderr
286-
quantize (bool): If True, return a quantized version of the model
318+
weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_5_Weights`, optional): The
319+
pretrained weights for the model. See
320+
:class:`~torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights` below for
321+
more details, and possible values. By default, no pre-trained
322+
weights are used.
323+
progress (bool, optional): If True, displays a progress bar of the download to stderr.
324+
Default is True.
325+
quantize (bool, optional): If True, return a quantized version of the model.
326+
Default is False.
327+
**kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights``
328+
base class. Please refer to the `source code
329+
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
330+
for more details about this class.
331+
332+
.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights
333+
:members:
334+
335+
.. autoclass:: torchvision.models.ShuffleNet_V2_X1_5_Weights
336+
:members:
337+
:noindex:
287338
"""
288339
weights = (ShuffleNet_V2_X1_5_QuantizedWeights if quantize else ShuffleNet_V2_X1_5_Weights).verify(weights)
289340
return _shufflenetv2(
@@ -300,19 +351,35 @@ def shufflenet_v2_x2_0(
300351
) -> QuantizableShuffleNetV2:
301352
"""
302353
Constructs a ShuffleNetV2 with 2.0x output channels, as described in
303-
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design"
304-
<https://arxiv.org/abs/1807.11164>`_.
354+
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
355+
<https://arxiv.org/abs/1807.11164>`__.
305356
306357
.. note::
307358
Note that ``quantize = True`` returns a quantized model with 8 bit
308359
weights. Quantized models only support inference and run on CPUs.
309360
GPU inference is not yet supported.
310361
311362
Args:
312-
weights (ShuffleNet_V2_X2_0_QuantizedWeights or ShuffleNet_V2_X2_0_Weights, optional): The pretrained
313-
weights for the model
314-
progress (bool): If True, displays a progress bar of the download to stderr
315-
quantize (bool): If True, return a quantized version of the model
363+
weights (:class:`~torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X2_0_Weights`, optional): The
364+
pretrained weights for the model. See
365+
:class:`~torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights` below for
366+
more details, and possible values. By default, no pre-trained
367+
weights are used.
368+
progress (bool, optional): If True, displays a progress bar of the download to stderr.
369+
Default is True.
370+
quantize (bool, optional): If True, return a quantized version of the model.
371+
Default is False.
372+
**kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights``
373+
base class. Please refer to the `source code
374+
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
375+
for more details about this class.
376+
377+
.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights
378+
:members:
379+
380+
.. autoclass:: torchvision.models.ShuffleNet_V2_X2_0_Weights
381+
:members:
382+
:noindex:
316383
"""
317384
weights = (ShuffleNet_V2_X2_0_QuantizedWeights if quantize else ShuffleNet_V2_X2_0_Weights).verify(weights)
318385
return _shufflenetv2(

0 commit comments

Comments
 (0)