Skip to content

Commit a6336f7

Browse files
authored
Add Docs for QuantizedGoogleNet (#5975)
* Add Docs for QuantizedGoogleNet * ufmt * Use explicit _QuantizedWeights or _Weights suffix
1 parent 651b97e commit a6336f7

File tree

5 files changed

+76
-10
lines changed

5 files changed

+76
-10
lines changed

docs/source/conf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def inject_weight_metadata(app, what, name, obj, options, lines):
315315
used within the autoclass directive.
316316
"""
317317

318-
if obj.__name__.endswith("_Weights"):
318+
if obj.__name__.endswith(("_Weights", "_QuantizedWeights")):
319319
lines[:] = [
320320
"The model builder above accepts the following values as the ``weights`` parameter.",
321321
f"``{obj.__name__}.DEFAULT`` is equivalent to ``{obj.DEFAULT}``.",
@@ -349,7 +349,8 @@ def inject_weight_metadata(app, what, name, obj, options, lines):
349349

350350

351351
def generate_weights_table(module, table_name, metrics, include_patterns=None, exclude_patterns=None):
352-
weight_enums = [getattr(module, name) for name in dir(module) if name.endswith("_Weights")]
352+
weights_endswith = "_QuantizedWeights" if module.__name__.split(".")[-1] == "quantization" else "_Weights"
353+
weight_enums = [getattr(module, name) for name in dir(module) if name.endswith(weights_endswith)]
353354
weights = [w for weight_enum in weight_enums for w in weight_enum]
354355

355356
if include_patterns is not None:
@@ -382,6 +383,9 @@ def generate_weights_table(module, table_name, metrics, include_patterns=None, e
382383

383384

384385
generate_weights_table(module=M, table_name="classification", metrics=[("acc@1", "Acc@1"), ("acc@5", "Acc@5")])
386+
generate_weights_table(
387+
module=M.quantization, table_name="classification_quant", metrics=[("acc@1", "Acc@1"), ("acc@5", "Acc@5")]
388+
)
385389
generate_weights_table(
386390
module=M.detection, table_name="detection", metrics=[("box_map", "Box MAP")], exclude_patterns=["Mask", "Keypoint"]
387391
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Quantized GoogLeNet
2+
===================
3+
4+
.. currentmodule:: torchvision.models.quantization
5+
6+
The Quantized GoogleNet model is based on the `Going Deeper with Convolutions <https://arxiv.org/abs/1409.4842>`__
7+
paper.
8+
9+
10+
Model builders
11+
--------------
12+
13+
The following model builders can be used to instanciate a quantized GoogLeNet
14+
model, with or without pre-trained weights. All the model builders internally
15+
rely on the ``torchvision.models.quantization.googlenet.QuantizableGoogLeNet``
16+
base class. Please refer to the `source code
17+
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/googlenet.py>`_
18+
for more details about this class.
19+
20+
.. autosummary::
21+
:toctree: generated/
22+
:template: function.rst
23+
24+
googlenet

docs/source/models_new.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@ Accuracies are reported on ImageNet
6565

6666
.. include:: generated/classification_table.rst
6767

68+
Quantized models
69+
----------------
70+
71+
.. currentmodule:: torchvision.models.quantization
72+
73+
The following quantized classification models are available, with or without
74+
pre-trained weights:
75+
76+
.. toctree::
77+
:maxdepth: 1
78+
79+
models/googlenet_quant
80+
81+
82+
Table of all available quantized classification weights
83+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
85+
Accuracies are reported on ImageNet
86+
87+
.. include:: generated/classification_quant_table.rst
88+
6889
Semantic Segmentation
6990
=====================
7091

torchvision/models/googlenet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ class GoogLeNet_Weights(WeightsEnum):
295295

296296
@handle_legacy_interface(weights=("pretrained", GoogLeNet_Weights.IMAGENET1K_V1))
297297
def googlenet(*, weights: Optional[GoogLeNet_Weights] = None, progress: bool = True, **kwargs: Any) -> GoogLeNet:
298-
r"""GoogLeNet (Inception v1) model architecture from
298+
"""GoogLeNet (Inception v1) model architecture from
299299
`Going Deeper with Convolutions <http://arxiv.org/abs/1409.4842>`_.
300+
300301
The required minimum input size of the model is 15x15.
301302
302303
Args:

torchvision/models/quantization/googlenet.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,34 @@ def googlenet(
141141
quantize: bool = False,
142142
**kwargs: Any,
143143
) -> QuantizableGoogLeNet:
144-
r"""GoogLeNet (Inception v1) model architecture from
145-
`"Going Deeper with Convolutions" <http://arxiv.org/abs/1409.4842>`_.
144+
"""GoogLeNet (Inception v1) model architecture from `Going Deeper with Convolutions <http://arxiv.org/abs/1409.4842>`__.
146145
147-
Note that quantize = True returns a quantized model with 8 bit
146+
Note that ``quantize = True`` returns a quantized model with 8 bit
148147
weights. Quantized models only support inference and run on CPUs.
149148
GPU inference is not yet supported
150149
150+
The required minimum input size of the model is 15x15.
151+
151152
Args:
152-
weights (GoogLeNet_QuantizedWeights or GoogLeNet_Weights, optional): The pretrained
153-
weights for the model
154-
progress (bool): If True, displays a progress bar of the download to stderr
155-
quantize (bool): If True, return a quantized version of the model
153+
weights (:class:`~torchvision.models.quantization.GoogLeNet_QuantizedWeights` or :class:`~torchvision.models.GoogLeNet_Weights`, optional): The
154+
pretrained weights for the model. See
155+
:class:`~torchvision.models.quantization.GoogLeNet_QuantizedWeights` below for
156+
more details, and possible values. By default, no pre-trained
157+
weights are used.
158+
progress (bool, optional): If True, displays a progress bar of the
159+
download to stderr. Default is True.
160+
quantize (bool, optional): If True, return a quantized version of the model. Default is False.
161+
**kwargs: parameters passed to the ``torchvision.models.quantization.QuantizableGoogLeNet``
162+
base class. Please refer to the `source code
163+
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization.googlenet.py>`_
164+
for more details about this class.
165+
166+
.. autoclass:: torchvision.models.quantization.GoogLeNet_QuantizedWeights
167+
:members:
168+
169+
.. autoclass:: torchvision.models.GoogLeNet_Weights
170+
:members:
171+
:noindex:
156172
"""
157173
weights = (GoogLeNet_QuantizedWeights if quantize else GoogLeNet_Weights).verify(weights)
158174

0 commit comments

Comments
 (0)