From 63f6131481dc44290e96d3c05ccfc680b5f749be Mon Sep 17 00:00:00 2001 From: Francisco Massa Date: Tue, 21 May 2019 11:21:36 +0200 Subject: [PATCH] Add documentation for ShuffleNet plus minor doc fixes --- docs/source/models.rst | 5 +++- torchvision/datasets/cityscapes.py | 3 +++ torchvision/models/shufflenetv2.py | 36 ++++++++++++++++++++++++++++ torchvision/transforms/transforms.py | 7 +++--- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/docs/source/models.rst b/docs/source/models.rst index 7fb2f56bbb0..7d4f568cb99 100644 --- a/docs/source/models.rst +++ b/docs/source/models.rst @@ -171,7 +171,10 @@ GoogLeNet ShuffleNet v2 ------------- -.. autofunction:: shufflenet +.. autofunction:: shufflenet_v2_x0_5 +.. autofunction:: shufflenet_v2_x1_0 +.. autofunction:: shufflenet_v2_x1_5 +.. autofunction:: shufflenet_v2_x2_0 MobileNet v2 ------------- diff --git a/torchvision/datasets/cityscapes.py b/torchvision/datasets/cityscapes.py index 4f84839063b..4c801577a0d 100644 --- a/torchvision/datasets/cityscapes.py +++ b/torchvision/datasets/cityscapes.py @@ -27,6 +27,7 @@ class Cityscapes(VisionDataset): Get semantic segmentation target .. code-block:: python + dataset = Cityscapes('./data/cityscapes', split='train', mode='fine', target_type='semantic') @@ -35,6 +36,7 @@ class Cityscapes(VisionDataset): Get multiple targets .. code-block:: python + dataset = Cityscapes('./data/cityscapes', split='train', mode='fine', target_type=['instance', 'color', 'polygon']) @@ -43,6 +45,7 @@ class Cityscapes(VisionDataset): Validate on the "coarse" set .. code-block:: python + dataset = Cityscapes('./data/cityscapes', split='val', mode='coarse', target_type='semantic') diff --git a/torchvision/models/shufflenetv2.py b/torchvision/models/shufflenetv2.py index dde1ceefd3b..8f129746ce2 100644 --- a/torchvision/models/shufflenetv2.py +++ b/torchvision/models/shufflenetv2.py @@ -146,20 +146,56 @@ def _shufflenetv2(arch, pretrained, progress, *args, **kwargs): def shufflenet_v2_x0_5(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 0.5x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ return _shufflenetv2('shufflenetv2_x0.5', pretrained, progress, [4, 8, 4], [24, 48, 96, 192, 1024], **kwargs) def shufflenet_v2_x1_0(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 1.0x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ return _shufflenetv2('shufflenetv2_x1.0', pretrained, progress, [4, 8, 4], [24, 116, 232, 464, 1024], **kwargs) def shufflenet_v2_x1_5(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 1.5x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ return _shufflenetv2('shufflenetv2_x1.5', pretrained, progress, [4, 8, 4], [24, 176, 352, 704, 1024], **kwargs) def shufflenet_v2_x2_0(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 2.0x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ return _shufflenetv2('shufflenetv2_x2.0', pretrained, progress, [4, 8, 4], [24, 244, 488, 976, 2048], **kwargs) diff --git a/torchvision/transforms/transforms.py b/torchvision/transforms/transforms.py index be800a14d13..d4b55b2a50f 100644 --- a/torchvision/transforms/transforms.py +++ b/torchvision/transforms/transforms.py @@ -108,7 +108,7 @@ class ToPILImage(object): - If the input has 3 channels, the ``mode`` is assumed to be ``RGB``. - If the input has 2 channels, the ``mode`` is assumed to be ``LA``. - If the input has 1 channel, the ``mode`` is determined by the data type (i.e ``int``, ``float``, - ``short``). + ``short``). .. _PIL.Image mode: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#concept-modes """ @@ -785,8 +785,9 @@ class LinearTransformation(object): Applications: whitening transformation: Suppose X is a column vector zero-centered data. - Then compute the data covariance matrix [D x D] with torch.mm(X.t(), X), - perform SVD on this matrix and pass it as transformation_matrix. + Then compute the data covariance matrix [D x D] with torch.mm(X.t(), X), + perform SVD on this matrix and pass it as transformation_matrix. + Args: transformation_matrix (Tensor): tensor [D x D], D = C x H x W mean_vector (Tensor): tensor [D], D = C x H x W