Skip to content

Commit e325242

Browse files
datumboxfacebook-github-bot
authored andcommitted
[fbsync] Add RegNet Architecture in TorchVision (#4403)
Summary: * initial code * add SqueezeExcitation * initial code * add SqueezeExcitation * add SqueezeExcitation * regnet blocks, stems and model definition * nit * add fc layer * use Callable instead of Enum for block, stem and activation * add regnet_x and regnet_y model build functions, add docs * remove unused depth * use BN/activation constructor and ConvBNActivation * add expected test pkl files * allow custom activation in SqueezeExcitation * use ReLU as the default activation * initial code * add SqueezeExcitation * initial code * add SqueezeExcitation * add SqueezeExcitation * regnet blocks, stems and model definition * nit * add fc layer * use Callable instead of Enum for block, stem and activation * add regnet_x and regnet_y model build functions, add docs * remove unused depth * use BN/activation constructor and ConvBNActivation * reuse SqueezeExcitation from efficientnet * refactor RegNetParams into BlockParams * use nn.init, replace np with torch * update README * construct model with stem, block, classifier instances * Revert "construct model with stem, block, classifier instances" This reverts commit 850f5f3. * remove unused blocks * support scaled model * fuse into ConvBNActivation * make reset_parameters private * fix type errors * fix for unit test * add pretrained weights for 6 variant models, update docs Reviewed By: prabhat00155, NicolasHug Differential Revision: D31309546 fbshipit-source-id: 56e01f105279c3d3c5514607c23d2835896b3d03
1 parent 1207002 commit e325242

19 files changed

+659
-0
lines changed

docs/source/models.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ architectures for image classification:
3737
- `Wide ResNet`_
3838
- `MNASNet`_
3939
- `EfficientNet`_
40+
- `RegNet`_
4041

4142
You can construct a model with random weights by calling its constructor:
4243

@@ -65,6 +66,20 @@ You can construct a model with random weights by calling its constructor:
6566
efficientnet_b5 = models.efficientnet_b5()
6667
efficientnet_b6 = models.efficientnet_b6()
6768
efficientnet_b7 = models.efficientnet_b7()
69+
regnet_y_400mf = models.regnet_y_400mf()
70+
regnet_y_800mf = models.regnet_y_800mf()
71+
regnet_y_1_6gf = models.regnet_y_1_6gf()
72+
regnet_y_3_2gf = models.regnet_y_3_2gf()
73+
regnet_y_8gf = models.regnet_y_8gf()
74+
regnet_y_16gf = models.regnet_y_16gf()
75+
regnet_y_32gf = models.regnet_y_32gf()
76+
regnet_x_400mf = models.regnet_x_400mf()
77+
regnet_x_800mf = models.regnet_x_800mf()
78+
regnet_x_1_6gf = models.regnet_x_1_6gf()
79+
regnet_x_3_2gf = models.regnet_x_3_2gf()
80+
regnet_x_8gf = models.regnet_x_8gf()
81+
regnet_x_16gf = models.regnet_x_16gf()
82+
regnet_x_32gf = models.regnet_x_32gf()
6883
6984
We provide pre-trained models, using the PyTorch :mod:`torch.utils.model_zoo`.
7085
These can be constructed by passing ``pretrained=True``:
@@ -94,6 +109,12 @@ These can be constructed by passing ``pretrained=True``:
94109
efficientnet_b5 = models.efficientnet_b5(pretrained=True)
95110
efficientnet_b6 = models.efficientnet_b6(pretrained=True)
96111
efficientnet_b7 = models.efficientnet_b7(pretrained=True)
112+
regnet_y_400mf = models.regnet_y_400mf(pretrained=True)
113+
regnet_y_800mf = models.regnet_y_800mf(pretrained=True)
114+
regnet_y_8gf = models.regnet_y_8gf(pretrained=True)
115+
regnet_x_400mf = models.regnet_x_400mf(pretrained=True)
116+
regnet_x_800mf = models.regnet_x_800mf(pretrained=True)
117+
regnet_x_8gf = models.regnet_x_8gf(pretrained=True)
97118
98119
Instancing a pre-trained model will download its weights to a cache directory.
99120
This directory can be set using the `TORCH_MODEL_ZOO` environment variable. See
@@ -188,6 +209,12 @@ EfficientNet-B4 83.384 96.594
188209
EfficientNet-B5 83.444 96.628
189210
EfficientNet-B6 84.008 96.916
190211
EfficientNet-B7 84.122 96.908
212+
regnet_x_400mf 72.834 90.950
213+
regnet_x_800mf 75.190 92.418
214+
regnet_x_8gf 79.324 94.694
215+
regnet_y_400mf 74.024 91.680
216+
regnet_y_800mf 76.420 93.136
217+
regnet_y_8gf 79.966 95.100
191218
================================ ============= =============
192219

193220

@@ -204,6 +231,7 @@ EfficientNet-B7 84.122 96.908
204231
.. _ResNeXt: https://arxiv.org/abs/1611.05431
205232
.. _MNASNet: https://arxiv.org/abs/1807.11626
206233
.. _EfficientNet: https://arxiv.org/abs/1905.11946
234+
.. _RegNet: https://arxiv.org/abs/2003.13678
207235

208236
.. currentmodule:: torchvision.models
209237

@@ -317,6 +345,24 @@ EfficientNet
317345
.. autofunction:: efficientnet_b6
318346
.. autofunction:: efficientnet_b7
319347

348+
RegNet
349+
------------
350+
351+
.. autofunction:: regnet_y_400mf
352+
.. autofunction:: regnet_y_800mf
353+
.. autofunction:: regnet_y_1_6gf
354+
.. autofunction:: regnet_y_3_2gf
355+
.. autofunction:: regnet_y_8gf
356+
.. autofunction:: regnet_y_16gf
357+
.. autofunction:: regnet_y_32gf
358+
.. autofunction:: regnet_x_400mf
359+
.. autofunction:: regnet_x_800mf
360+
.. autofunction:: regnet_x_1_6gf
361+
.. autofunction:: regnet_x_3_2gf
362+
.. autofunction:: regnet_x_8gf
363+
.. autofunction:: regnet_x_16gf
364+
.. autofunction:: regnet_x_32gf
365+
320366
Quantized Models
321367
----------------
322368

hubconf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
mnasnet1_3
1818
from torchvision.models.efficientnet import efficientnet_b0, efficientnet_b1, efficientnet_b2, \
1919
efficientnet_b3, efficientnet_b4, efficientnet_b5, efficientnet_b6, efficientnet_b7
20+
from torchvision.models.regnet import regnet_y_400mf, regnet_y_800mf, \
21+
regnet_y_1_6gf, regnet_y_3_2gf, regnet_y_8gf, regnet_y_16gf, regnet_y_32gf, \
22+
regnet_x_400mf, regnet_x_800mf, regnet_x_1_6gf, regnet_x_3_2gf, regnet_x_8gf, \
23+
regnet_x_16gf, regnet_x_32gf
2024

2125
# segmentation
2226
from torchvision.models.segmentation import fcn_resnet50, fcn_resnet101, \

references/classification/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ The weights of the B0-B4 variants are ported from Ross Wightman's [timm repo](ht
7979

8080
The weights of the B5-B7 variants are ported from Luke Melas' [EfficientNet-PyTorch repo](https://github.com/lukemelas/EfficientNet-PyTorch/blob/1039e009545d9329ea026c9f7541341439712b96/efficientnet_pytorch/utils.py#L562-L564).
8181

82+
83+
### RegNet
84+
85+
#### Small models
86+
```
87+
torchrun --nproc_per_node=8 train.py\
88+
--model $MODEL --epochs 100 --batch-size 128 --wd 0.00005 --lr=0.8\
89+
--lr-scheduler=cosineannealinglr --lr-warmup-method=linear\
90+
--lr-warmup-epochs=5 --lr-warmup-decay=0.1
91+
```
92+
Here `$MODEL` is one of `regnet_x_400mf`, `regnet_x_800mf`, `regnet_x_1_6gf`, `regnet_y_400mf`, `regnet_y_800mf` and `regnet_y_1_6gf`. Please note we used learning rate 0.4 for `regent_y_400mf` to get the same Acc@1 as [the paper)(https://arxiv.org/abs/2003.13678).
93+
94+
### Medium models
95+
```
96+
torchrun --nproc_per_node=8 train.py\
97+
--model $MODEL --epochs 100 --batch-size 64 --wd 0.00005 --lr=0.4\
98+
--lr-scheduler=cosineannealinglr --lr-warmup-method=linear\
99+
--lr-warmup-epochs=5 --lr-warmup-decay=0.1
100+
```
101+
Here `$MODEL` is one of `regnet_x_3_2gf`, `regnet_x_8gf`, `regnet_x_16gf`, `regnet_y_3_2gf` and `regnet_y_8gf`.
102+
103+
### Large models
104+
```
105+
torchrun --nproc_per_node=8 train.py\
106+
--model $MODEL --epochs 100 --batch-size 32 --wd 0.00005 --lr=0.2\
107+
--lr-scheduler=cosineannealinglr --lr-warmup-method=linear\
108+
--lr-warmup-epochs=5 --lr-warmup-decay=0.1
109+
```
110+
Here `$MODEL` is one of `regnet_x_32gf`, `regnet_y_16gf` and `regnet_y_32gf`.
111+
82112
## Mixed precision training
83113
Automatic Mixed Precision (AMP) training on GPU for Pytorch can be enabled with the [NVIDIA Apex extension](https://github.com/NVIDIA/apex).
84114

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

torchvision/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .mnasnet import *
1010
from .shufflenetv2 import *
1111
from .efficientnet import *
12+
from .regnet import *
1213
from . import segmentation
1314
from . import detection
1415
from . import video

0 commit comments

Comments
 (0)