Skip to content

Commit bf41dfb

Browse files
committed
Adding pre-trained weights for EfficientNetV2-s
1 parent 8f6df0c commit bf41dfb

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

docs/source/models.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ architectures for image classification:
3838
- `ResNeXt`_
3939
- `Wide ResNet`_
4040
- `MNASNet`_
41-
- `EfficientNet`_
41+
- `EfficientNet`_ v1 & v2
4242
- `RegNet`_
4343
- `VisionTransformer`_
4444
- `ConvNeXt`_
@@ -70,6 +70,9 @@ You can construct a model with random weights by calling its constructor:
7070
efficientnet_b5 = models.efficientnet_b5()
7171
efficientnet_b6 = models.efficientnet_b6()
7272
efficientnet_b7 = models.efficientnet_b7()
73+
efficientnet_v2_s = models.efficientnet_v2_s()
74+
efficientnet_v2_m = models.efficientnet_v2_m()
75+
efficientnet_v2_l = models.efficientnet_v2_l()
7376
regnet_y_400mf = models.regnet_y_400mf()
7477
regnet_y_800mf = models.regnet_y_800mf()
7578
regnet_y_1_6gf = models.regnet_y_1_6gf()
@@ -122,6 +125,9 @@ These can be constructed by passing ``pretrained=True``:
122125
efficientnet_b5 = models.efficientnet_b5(pretrained=True)
123126
efficientnet_b6 = models.efficientnet_b6(pretrained=True)
124127
efficientnet_b7 = models.efficientnet_b7(pretrained=True)
128+
efficientnet_v2_s = models.efficientnet_v2_s(pretrained=True)
129+
efficientnet_v2_m = models.efficientnet_v2_m(pretrained=True)
130+
efficientnet_v2_l = models.efficientnet_v2_l(pretrained=True)
125131
regnet_y_400mf = models.regnet_y_400mf(pretrained=True)
126132
regnet_y_800mf = models.regnet_y_800mf(pretrained=True)
127133
regnet_y_1_6gf = models.regnet_y_1_6gf(pretrained=True)
@@ -238,6 +244,7 @@ EfficientNet-B4 83.384 96.594
238244
EfficientNet-B5 83.444 96.628
239245
EfficientNet-B6 84.008 96.916
240246
EfficientNet-B7 84.122 96.908
247+
EfficientNetV2-s 84.228 96.878
241248
regnet_x_400mf 72.834 90.950
242249
regnet_x_800mf 75.212 92.348
243250
regnet_x_1_6gf 77.040 93.440
@@ -439,6 +446,9 @@ EfficientNet
439446
efficientnet_b5
440447
efficientnet_b6
441448
efficientnet_b7
449+
efficientnet_v2_s
450+
efficientnet_v2_m
451+
efficientnet_v2_l
442452

443453
RegNet
444454
------------

hubconf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
efficientnet_b5,
1414
efficientnet_b6,
1515
efficientnet_b7,
16+
efficientnet_v2_s,
17+
efficientnet_v2_m,
18+
efficientnet_v2_l,
1619
)
1720
from torchvision.models.googlenet import googlenet
1821
from torchvision.models.inception import inception_v3

references/classification/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Then we averaged the parameters of the last 3 checkpoints that improved the Acc@
8888
and [#3354](https://github.com/pytorch/vision/pull/3354) for details.
8989

9090

91-
### EfficientNet
91+
### EfficientNet-V1
9292

9393
The weights of the B0-B4 variants are ported from Ross Wightman's [timm repo](https://github.com/rwightman/pytorch-image-models/blob/01cb46a9a50e3ba4be167965b5764e9702f09b30/timm/models/efficientnet.py#L95-L108).
9494

@@ -114,6 +114,24 @@ torchrun --nproc_per_node=8 train.py --model efficientnet_b7 --interpolation bic
114114
--val-resize-size 600 --val-crop-size 600 --train-crop-size 600 --test-only --pretrained
115115
```
116116

117+
118+
### EfficientNet-V2
119+
```
120+
torchrun --nproc_per_node=8 train.py \
121+
--model $MODEL --batch-size 128 --lr 0.5 --lr-scheduler cosineannealinglr \
122+
--lr-warmup-epochs 5 --lr-warmup-method linear --auto-augment ta_wide --epochs 600 --random-erase 0.1 \
123+
--label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 --weight-decay 0.00002 --norm-weight-decay 0.0 \
124+
--train-crop-size $TRAIN_SIZE --model-ema --val-crop-size $EVAL_SIZE --val-resize-size $EVAL_SIZE \
125+
--ra-sampler --ra-reps 4
126+
```
127+
Here `$MODEL` is one of `efficientnet_v2_s`, `efficientnet_v2_m` and `efficientnet_v2_l`.
128+
Note that the Small variant had a `$TRAIN_SIZE` of `300` and a `$EVAL_SIZE` of `384`, while the other variants `384` and `480` respectively.
129+
130+
Note that the above command corresponds to training on a single node with 8 GPUs.
131+
For generatring the pre-trained weights, we trained with 8 nodes, each with 8 GPUs (for a total of 64 GPUs),
132+
and `--batch_size 16`.
133+
134+
117135
### RegNet
118136

119137
#### Small models

torchvision/models/efficientnet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"efficientnet_b5": "https://download.pytorch.org/models/efficientnet_b5_lukemelas-b6417697.pth",
4343
"efficientnet_b6": "https://download.pytorch.org/models/efficientnet_b6_lukemelas-c76e70fd.pth",
4444
"efficientnet_b7": "https://download.pytorch.org/models/efficientnet_b7_lukemelas-dcc49843.pth",
45-
# Temporary TF weights
46-
"efficientnet_v2_s": "https://download.pytorch.org/models/efficientnet_v2_s-tmp.pth",
45+
# Weights trained with TorchVision
46+
"efficientnet_v2_s": "https://download.pytorch.org/models/efficientnet_v2_s-dd5fe13b.pth",
4747
}
4848

4949

torchvision/prototype/models/efficientnet.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def _efficientnet(
6060
_COMMON_META = {
6161
"task": "image_classification",
6262
"categories": _IMAGENET_CATEGORIES,
63-
"interpolation": InterpolationMode.BICUBIC,
6463
"recipe": "https://github.com/pytorch/vision/tree/main/references/classification#efficientnet",
6564
}
6665

@@ -69,6 +68,7 @@ def _efficientnet(
6968
**_COMMON_META,
7069
"architecture": "EfficientNet",
7170
"publication_year": 2019,
71+
"interpolation": InterpolationMode.BICUBIC,
7272
"min_size": (1, 1),
7373
}
7474

@@ -77,6 +77,7 @@ def _efficientnet(
7777
**_COMMON_META,
7878
"architecture": "EfficientNetV2",
7979
"publication_year": 2021,
80+
"interpolation": InterpolationMode.BILINEAR,
8081
"min_size": (33, 33),
8182
}
8283

@@ -216,21 +217,19 @@ class EfficientNet_B7_Weights(WeightsEnum):
216217

217218
class EfficientNet_V2_S_Weights(WeightsEnum):
218219
IMAGENET1K_V1 = Weights(
219-
url="https://download.pytorch.org/models/efficientnet_v2_s-tmp.pth",
220+
url="https://download.pytorch.org/models/efficientnet_v2_s-dd5fe13b.pth",
220221
transforms=partial(
221222
ImageNetEval,
222223
crop_size=384,
223224
resize_size=384,
224-
interpolation=InterpolationMode.BICUBIC,
225-
mean=(0.5, 0.5, 0.5),
226-
std=(0.5, 0.5, 0.5),
225+
interpolation=InterpolationMode.BILINEAR,
227226
),
228227
meta={
229228
**_COMMON_META_V2,
230229
"num_params": 21458488,
231230
"size": (384, 384),
232-
"acc@1": 83.152,
233-
"acc@5": 96.400,
231+
"acc@1": 84.228,
232+
"acc@5": 96.878,
234233
},
235234
)
236235
DEFAULT = IMAGENET1K_V1

0 commit comments

Comments
 (0)