Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def inject_weight_metadata(app, what, name, obj, options, lines):
used within the autoclass directive.
"""

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


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

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


generate_weights_table(module=M, table_name="classification", metrics=[("acc@1", "Acc@1"), ("acc@5", "Acc@5")])
generate_weights_table(
module=M.quantization, table_name="classification_quant", metrics=[("acc@1", "Acc@1"), ("acc@5", "Acc@5")]
)
generate_weights_table(
module=M.detection, table_name="detection", metrics=[("box_map", "Box MAP")], exclude_patterns=["Mask", "Keypoint"]
)
Expand Down
24 changes: 24 additions & 0 deletions docs/source/models/googlenet_quant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Quantized GoogLeNet
===================

.. currentmodule:: torchvision.models.quantization

The Quantized GoogleNet model is based on the `Going Deeper with Convolutions <https://arxiv.org/abs/1409.4842>`__
paper.


Model builders
--------------

The following model builders can be used to instanciate a quantized GoogLeNet
model, with or without pre-trained weights. All the model builders internally
rely on the ``torchvision.models.quantization.googlenet.QuantizableGoogLeNet``
base class. Please refer to the `source code
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/googlenet.py>`_
for more details about this class.

.. autosummary::
:toctree: generated/
:template: function.rst

googlenet
21 changes: 21 additions & 0 deletions docs/source/models_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ Accuracies are reported on ImageNet

.. include:: generated/classification_table.rst

Quantized models
----------------

.. currentmodule:: torchvision.models.quantization

The following quantized classification models are available, with or without
pre-trained weights:

.. toctree::
:maxdepth: 1

models/googlenet_quant


Table of all available quantized classification weights
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Accuracies are reported on ImageNet

.. include:: generated/classification_quant_table.rst

Semantic Segmentation
=====================

Expand Down
3 changes: 2 additions & 1 deletion torchvision/models/googlenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ class GoogLeNet_Weights(WeightsEnum):

@handle_legacy_interface(weights=("pretrained", GoogLeNet_Weights.IMAGENET1K_V1))
def googlenet(*, weights: Optional[GoogLeNet_Weights] = None, progress: bool = True, **kwargs: Any) -> GoogLeNet:
r"""GoogLeNet (Inception v1) model architecture from
"""GoogLeNet (Inception v1) model architecture from
`Going Deeper with Convolutions <http://arxiv.org/abs/1409.4842>`_.

The required minimum input size of the model is 15x15.

Args:
Expand Down
30 changes: 23 additions & 7 deletions torchvision/models/quantization/googlenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,34 @@ def googlenet(
quantize: bool = False,
**kwargs: Any,
) -> QuantizableGoogLeNet:
r"""GoogLeNet (Inception v1) model architecture from
`"Going Deeper with Convolutions" <http://arxiv.org/abs/1409.4842>`_.
"""GoogLeNet (Inception v1) model architecture from `Going Deeper with Convolutions <http://arxiv.org/abs/1409.4842>`__.

Note that quantize = True returns a quantized model with 8 bit
Note that ``quantize = True`` returns a quantized model with 8 bit
weights. Quantized models only support inference and run on CPUs.
GPU inference is not yet supported

The required minimum input size of the model is 15x15.

Args:
weights (GoogLeNet_QuantizedWeights or GoogLeNet_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.GoogLeNet_QuantizedWeights` or :class:`~torchvision.models.GoogLeNet_Weights`, optional): The
pretrained weights for the model. See
:class:`~torchvision.models.quantization.GoogLeNet_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.QuantizableGoogLeNet``
base class. Please refer to the `source code
<https://github.com/pytorch/vision/blob/main/torchvision/models/quantization.googlenet.py>`_
for more details about this class.

.. autoclass:: torchvision.models.quantization.GoogLeNet_QuantizedWeights
:members:

.. autoclass:: torchvision.models.GoogLeNet_Weights
:members:
:noindex:
"""
weights = (GoogLeNet_QuantizedWeights if quantize else GoogLeNet_Weights).verify(weights)

Expand Down