Skip to content

Commit 9109d8d

Browse files
authored
Cleanup Quantized ShuffleNet (#4854)
* Clean up unnecessary quant builders and add quant weights for 0.5 * Fixing mypy.
1 parent fe78a8a commit 9109d8d

File tree

3 files changed

+6
-50
lines changed

3 files changed

+6
-50
lines changed

docs/source/models.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ Model Acc@1 Acc@5
479479
================================ ============= =============
480480
MobileNet V2 71.658 90.150
481481
MobileNet V3 Large 73.004 90.858
482-
ShuffleNet V2 68.360 87.582
482+
ShuffleNet V2 x1.0 68.360 87.582
483+
ShuffleNet V2 x0.5 57.972 79.780
483484
ResNet 18 69.494 88.882
484485
ResNet 50 75.920 92.814
485486
ResNext 101 32x8d 78.986 94.480

references/classification/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ For all post training quantized models, the settings are:
168168
```
169169
python train_quantization.py --device='cpu' --post-training-quantize --backend='fbgemm' --model='$MODEL'
170170
```
171-
Here `$MODEL` is one of `googlenet`, `inception_v3`, `resnet18`, `resnet50`, `resnext101_32x8d` and `shufflenet_v2_x1_0`.
171+
Here `$MODEL` is one of `googlenet`, `inception_v3`, `resnet18`, `resnet50`, `resnext101_32x8d`, `shufflenet_v2_x0_5` and `shufflenet_v2_x1_0`.
172172

173173
### QAT MobileNetV2
174174

torchvision/models/quantization/shufflenetv2.py

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Optional
22

33
import torch
44
import torch.nn as nn
@@ -12,15 +12,11 @@
1212
"QuantizableShuffleNetV2",
1313
"shufflenet_v2_x0_5",
1414
"shufflenet_v2_x1_0",
15-
"shufflenet_v2_x1_5",
16-
"shufflenet_v2_x2_0",
1715
]
1816

1917
quant_model_urls = {
20-
"shufflenetv2_x0.5_fbgemm": None,
18+
"shufflenetv2_x0.5_fbgemm": "https://download.pytorch.org/models/quantized/shufflenetv2_x0.5_fbgemm-00845098.pth",
2119
"shufflenetv2_x1.0_fbgemm": "https://download.pytorch.org/models/quantized/shufflenetv2_x1_fbgemm-db332c57.pth",
22-
"shufflenetv2_x1.5_fbgemm": None,
23-
"shufflenetv2_x2.0_fbgemm": None,
2420
}
2521

2622

@@ -96,6 +92,7 @@ def _shufflenetv2(
9692
assert pretrained in [True, False]
9793

9894
if pretrained:
95+
model_url: Optional[str] = None
9996
if quantize:
10097
model_url = quant_model_urls[arch + "_" + backend]
10198
else:
@@ -147,45 +144,3 @@ def shufflenet_v2_x1_0(
147144
return _shufflenetv2(
148145
"shufflenetv2_x1.0", pretrained, progress, quantize, [4, 8, 4], [24, 116, 232, 464, 1024], **kwargs
149146
)
150-
151-
152-
def shufflenet_v2_x1_5(
153-
pretrained: bool = False,
154-
progress: bool = True,
155-
quantize: bool = False,
156-
**kwargs: Any,
157-
) -> QuantizableShuffleNetV2:
158-
"""
159-
Constructs a ShuffleNetV2 with 1.5x output channels, as described in
160-
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design"
161-
<https://arxiv.org/abs/1807.11164>`_.
162-
163-
Args:
164-
pretrained (bool): If True, returns a model pre-trained on ImageNet
165-
progress (bool): If True, displays a progress bar of the download to stderr
166-
quantize (bool): If True, return a quantized version of the model
167-
"""
168-
return _shufflenetv2(
169-
"shufflenetv2_x1.5", pretrained, progress, quantize, [4, 8, 4], [24, 176, 352, 704, 1024], **kwargs
170-
)
171-
172-
173-
def shufflenet_v2_x2_0(
174-
pretrained: bool = False,
175-
progress: bool = True,
176-
quantize: bool = False,
177-
**kwargs: Any,
178-
) -> QuantizableShuffleNetV2:
179-
"""
180-
Constructs a ShuffleNetV2 with 2.0x output channels, as described in
181-
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design"
182-
<https://arxiv.org/abs/1807.11164>`_.
183-
184-
Args:
185-
pretrained (bool): If True, returns a model pre-trained on ImageNet
186-
progress (bool): If True, displays a progress bar of the download to stderr
187-
quantize (bool): If True, return a quantized version of the model
188-
"""
189-
return _shufflenetv2(
190-
"shufflenetv2_x2.0", pretrained, progress, quantize, [4, 8, 4], [24, 244, 488, 976, 2048], **kwargs
191-
)

0 commit comments

Comments
 (0)