Skip to content

Commit abeac10

Browse files
committed
Add Medium and Large weights
1 parent bf41dfb commit abeac10

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

references/classification/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ torchrun --nproc_per_node=8 train.py \
124124
--train-crop-size $TRAIN_SIZE --model-ema --val-crop-size $EVAL_SIZE --val-resize-size $EVAL_SIZE \
125125
--ra-sampler --ra-reps 4
126126
```
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.
127+
Here `$MODEL` is one of `efficientnet_v2_s` and `efficientnet_v2_m`.
128+
Note that the Small variant had a `$TRAIN_SIZE` of `300` and a `$EVAL_SIZE` of `384`, while the Medium `384` and `480` respectively.
129129

130130
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`.
131+
For generatring the pre-trained weights, we trained with 4 nodes, each with 8 GPUs (for a total of 32 GPUs),
132+
and `--batch_size 32`.
133+
134+
The weights of the Large variant are ported from the original paper rather than trained from scratch. See the `EfficientNet_V2_L_Weights` entry for their exact preprocessing transforms.
133135

134136

135137
### RegNet

torchvision/models/efficientnet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
"efficientnet_b7": "https://download.pytorch.org/models/efficientnet_b7_lukemelas-dcc49843.pth",
4545
# Weights trained with TorchVision
4646
"efficientnet_v2_s": "https://download.pytorch.org/models/efficientnet_v2_s-dd5fe13b.pth",
47+
"efficientnet_v2_m": "https://download.pytorch.org/models/efficientnet_v2_m-dc08266a.pth",
48+
# Weights ported from TF
49+
"efficientnet_v2_l": "https://download.pytorch.org/models/efficientnet_v2_l-59c71312.pth",
4750
}
4851

4952

torchvision/prototype/models/efficientnet.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,45 @@ class EfficientNet_V2_S_Weights(WeightsEnum):
236236

237237

238238
class EfficientNet_V2_M_Weights(WeightsEnum):
239-
pass
239+
IMAGENET1K_V1 = Weights(
240+
url="https://download.pytorch.org/models/efficientnet_v2_m-dc08266a.pth",
241+
transforms=partial(
242+
ImageNetEval,
243+
crop_size=480,
244+
resize_size=480,
245+
interpolation=InterpolationMode.BILINEAR,
246+
),
247+
meta={
248+
**_COMMON_META_V2,
249+
"num_params": 54139356,
250+
"size": (480, 480),
251+
"acc@1": 85.119,
252+
"acc@5": 97.151,
253+
},
254+
)
255+
DEFAULT = IMAGENET1K_V1
240256

241257

242258
class EfficientNet_V2_L_Weights(WeightsEnum):
243-
pass
259+
IMAGENET1K_V1 = Weights(
260+
url="https://download.pytorch.org/models/efficientnet_v2_l-59c71312.pth",
261+
transforms=partial(
262+
ImageNetEval,
263+
crop_size=480,
264+
resize_size=480,
265+
interpolation=InterpolationMode.BICUBIC,
266+
mean=(0.5, 0.5, 0.5),
267+
std=(0.5, 0.5, 0.5),
268+
),
269+
meta={
270+
**_COMMON_META_V2,
271+
"num_params": 118515272,
272+
"size": (480, 480),
273+
"acc@1": 85.808,
274+
"acc@5": 97.788,
275+
},
276+
)
277+
DEFAULT = IMAGENET1K_V1
244278

245279

246280
@handle_legacy_interface(weights=("pretrained", EfficientNet_B0_Weights.IMAGENET1K_V1))
@@ -365,7 +399,7 @@ def efficientnet_v2_s(
365399
)
366400

367401

368-
@handle_legacy_interface(weights=("pretrained", None))
402+
@handle_legacy_interface(weights=("pretrained", EfficientNet_V2_M_Weights.IMAGENET1K_V1))
369403
def efficientnet_v2_m(
370404
*, weights: Optional[EfficientNet_V2_M_Weights] = None, progress: bool = True, **kwargs: Any
371405
) -> EfficientNet:
@@ -383,7 +417,7 @@ def efficientnet_v2_m(
383417
)
384418

385419

386-
@handle_legacy_interface(weights=("pretrained", None))
420+
@handle_legacy_interface(weights=("pretrained", EfficientNet_V2_L_Weights.IMAGENET1K_V1))
387421
def efficientnet_v2_l(
388422
*, weights: Optional[EfficientNet_V2_L_Weights] = None, progress: bool = True, **kwargs: Any
389423
) -> EfficientNet:

0 commit comments

Comments
 (0)