diff --git a/docs/source/models/resnet_quant.rst b/docs/source/models/resnet_quant.rst new file mode 100644 index 00000000000..5609990646c --- /dev/null +++ b/docs/source/models/resnet_quant.rst @@ -0,0 +1,25 @@ +Quantized ResNet +================ + +.. currentmodule:: torchvision.models.quantization + +The Quantized ResNet model is based on the `Deep Residual Learning for Image Recognition +`_ paper. + + +Model builders +-------------- + +The following model builders can be used to instantiate a quantized ResNet +model, with or without pre-trained weights. All the model builders internally +rely on the ``torchvision.models.quantization.resnet.QuantizableResNet`` +base class. Please refer to the `source code +`_ +for more details about this class. + +.. autosummary:: + :toctree: generated/ + :template: function.rst + + resnet18 + resnet50 diff --git a/docs/source/models_new.rst b/docs/source/models_new.rst index cf0d8d984b1..c696435238c 100644 --- a/docs/source/models_new.rst +++ b/docs/source/models_new.rst @@ -149,6 +149,7 @@ pre-trained weights: models/googlenet_quant models/inception_quant models/mobilenetv2_quant + models/resnet_quant | diff --git a/torchvision/models/quantization/resnet.py b/torchvision/models/quantization/resnet.py index 88d4f1871de..556aa98877c 100644 --- a/torchvision/models/quantization/resnet.py +++ b/torchvision/models/quantization/resnet.py @@ -267,14 +267,29 @@ def resnet18( quantize: bool = False, **kwargs: Any, ) -> QuantizableResNet: - r"""ResNet-18 model from - `"Deep Residual Learning for Image Recognition" `_ + """ResNet-18 model from + `Deep Residual Learning for Image Recognition `_ Args: - weights (ResNet18_QuantizedWeights or ResNet18_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.ResNet18_QuantizedWeights` or :class:`~torchvision.models.ResNet18_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ResNet18_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.QuantizableResNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ResNet18_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ResNet18_Weights + :members: + :noindex: """ weights = (ResNet18_QuantizedWeights if quantize else ResNet18_Weights).verify(weights) @@ -296,14 +311,29 @@ def resnet50( quantize: bool = False, **kwargs: Any, ) -> QuantizableResNet: - r"""ResNet-50 model from - `"Deep Residual Learning for Image Recognition" `_ + """ResNet-50 model from + `Deep Residual Learning for Image Recognition `_ Args: - weights (ResNet50_QuantizedWeights or ResNet50_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.ResNet50_QuantizedWeights` or :class:`~torchvision.models.ResNet50_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ResNet50_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.QuantizableResNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ResNet50_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ResNet50_Weights + :members: + :noindex: """ weights = (ResNet50_QuantizedWeights if quantize else ResNet50_Weights).verify(weights) @@ -325,14 +355,29 @@ def resnext101_32x8d( quantize: bool = False, **kwargs: Any, ) -> QuantizableResNet: - r"""ResNeXt-101 32x8d model from - `"Aggregated Residual Transformation for Deep Neural Networks" `_ + """ResNeXt-101 32x8d model from + `Aggregated Residual Transformation for Deep Neural Networks `_ Args: - weights (ResNeXt101_32X8D_QuantizedWeights or ResNeXt101_32X8D_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.ResNet101_32X8D_QuantizedWeights` or :class:`~torchvision.models.ResNet101_32X8D_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ResNet101_32X8D_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.QuantizableResNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ResNet101_32X8D_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ResNet101_32X8D_Weights + :members: + :noindex: """ weights = (ResNeXt101_32X8D_QuantizedWeights if quantize else ResNeXt101_32X8D_Weights).verify(weights) @@ -348,14 +393,29 @@ def resnext101_64x4d( quantize: bool = False, **kwargs: Any, ) -> QuantizableResNet: - r"""ResNeXt-101 64x4d model from - `"Aggregated Residual Transformation for Deep Neural Networks" `_ + """ResNeXt-101 64x4d model from + `Aggregated Residual Transformation for Deep Neural Networks `_ Args: - weights (ResNeXt101_64X4D_QuantizedWeights or ResNeXt101_64X4D_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.ResNet101_64X4D_QuantizedWeights` or :class:`~torchvision.models.ResNet101_64X4D_Weights`, optional): The + pretrained weights for the model. See + :class:`~torchvision.models.quantization.ResNet101_64X4D_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.QuantizableResNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + + .. autoclass:: torchvision.models.quantization.ResNet101_64X4D_QuantizedWeights + :members: + + .. autoclass:: torchvision.models.ResNet101_64X4D_Weights + :members: + :noindex: """ weights = (ResNeXt101_64X4D_QuantizedWeights if quantize else ResNeXt101_64X4D_Weights).verify(weights)