Skip to content

Commit 12fa4d2

Browse files
committed
Add weights.
1 parent 4fc26bc commit 12fa4d2

File tree

2 files changed

+91
-6
lines changed

2 files changed

+91
-6
lines changed

references/classification/train.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def load_data(traindir, valdir, args):
8989
resize_size, crop_size = 342, 299
9090
elif args.model.startswith('efficientnet_'):
9191
sizes = {
92-
'B0': 224, 'B1': 240, 'B2': 260, 'B3': 300,
93-
'B4': 380, 'B5': 456, 'B6': 528, 'B7': 600,
92+
'b0': 224, 'b1': 240, 'b2': 260, 'b3': 300,
93+
'b4': 380, 'b5': 456, 'b6': 528, 'b7': 600,
9494
}
95-
e_type = args.model.replace('efficientnet_', '').upper()
95+
e_type = args.model.replace('efficientnet_', '')
9696
resize_size = crop_size = sizes[e_type]
9797
interpolation = InterpolationMode.BICUBIC
9898

torchvision/models/efficientnet.py

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
from torchvision.models.mobilenetv2 import ConvBNActivation, _make_divisible
1515

1616

17-
__all__ = ["EfficientNet", "efficientnet_b0", "efficientnet_b3"]
17+
__all__ = ["EfficientNet", "efficientnet_b0", "efficientnet_b1", "efficientnet_b2", "efficientnet_b3",
18+
"efficientnet_b4", "efficientnet_b5", "efficientnet_b6", "efficientnet_b7"]
1819

1920

2021
model_urls = { # TODO: Add weights
21-
"efficientnet_b0": None,
22-
"efficientnet_b3": None,
22+
"efficientnet_b0": "https://download.pytorch.org/models/efficientnet_b0-lukemelas.pth",
23+
"efficientnet_b1": "https://download.pytorch.org/models/efficientnet_b1-lukemelas.pth",
24+
"efficientnet_b2": "https://download.pytorch.org/models/efficientnet_b2-lukemelas.pth",
25+
"efficientnet_b3": "https://download.pytorch.org/models/efficientnet_b3-lukemelas.pth",
26+
"efficientnet_b4": "https://download.pytorch.org/models/efficientnet_b4-lukemelas.pth",
27+
"efficientnet_b5": "https://download.pytorch.org/models/efficientnet_b5-lukemelas.pth",
28+
"efficientnet_b6": "https://download.pytorch.org/models/efficientnet_b6-lukemelas.pth",
29+
"efficientnet_b7": "https://download.pytorch.org/models/efficientnet_b7-lukemelas.pth",
2330
}
2431

2532

@@ -256,6 +263,32 @@ def efficientnet_b0(pretrained: bool = False, progress: bool = True, **kwargs: A
256263
return _efficientnet_model("efficientnet_b0", inverted_residual_setting, 0.2, pretrained, progress, **kwargs)
257264

258265

266+
def efficientnet_b1(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> EfficientNet:
267+
"""
268+
Constructs a EfficientNet B1 architecture from
269+
`"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" <https://arxiv.org/abs/1905.11946>`_.
270+
271+
Args:
272+
pretrained (bool): If True, returns a model pre-trained on ImageNet
273+
progress (bool): If True, displays a progress bar of the download to stderr
274+
"""
275+
inverted_residual_setting = _efficientnet_conf(width_mult=1.0, depth_mult=1.1, **kwargs)
276+
return _efficientnet_model("efficientnet_b1", inverted_residual_setting, 0.2, pretrained, progress, **kwargs)
277+
278+
279+
def efficientnet_b2(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> EfficientNet:
280+
"""
281+
Constructs a EfficientNet B2 architecture from
282+
`"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" <https://arxiv.org/abs/1905.11946>`_.
283+
284+
Args:
285+
pretrained (bool): If True, returns a model pre-trained on ImageNet
286+
progress (bool): If True, displays a progress bar of the download to stderr
287+
"""
288+
inverted_residual_setting = _efficientnet_conf(width_mult=1.1, depth_mult=1.2, **kwargs)
289+
return _efficientnet_model("efficientnet_b2", inverted_residual_setting, 0.3, pretrained, progress, **kwargs)
290+
291+
259292
def efficientnet_b3(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> EfficientNet:
260293
"""
261294
Constructs a EfficientNet B3 architecture from
@@ -267,3 +300,55 @@ def efficientnet_b3(pretrained: bool = False, progress: bool = True, **kwargs: A
267300
"""
268301
inverted_residual_setting = _efficientnet_conf(width_mult=1.2, depth_mult=1.4, **kwargs)
269302
return _efficientnet_model("efficientnet_b3", inverted_residual_setting, 0.3, pretrained, progress, **kwargs)
303+
304+
305+
def efficientnet_b4(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> EfficientNet:
306+
"""
307+
Constructs a EfficientNet B4 architecture from
308+
`"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" <https://arxiv.org/abs/1905.11946>`_.
309+
310+
Args:
311+
pretrained (bool): If True, returns a model pre-trained on ImageNet
312+
progress (bool): If True, displays a progress bar of the download to stderr
313+
"""
314+
inverted_residual_setting = _efficientnet_conf(width_mult=1.4, depth_mult=1.8, **kwargs)
315+
return _efficientnet_model("efficientnet_b4", inverted_residual_setting, 0.4, pretrained, progress, **kwargs)
316+
317+
318+
def efficientnet_b5(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> EfficientNet:
319+
"""
320+
Constructs a EfficientNet B5 architecture from
321+
`"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" <https://arxiv.org/abs/1905.11946>`_.
322+
323+
Args:
324+
pretrained (bool): If True, returns a model pre-trained on ImageNet
325+
progress (bool): If True, displays a progress bar of the download to stderr
326+
"""
327+
inverted_residual_setting = _efficientnet_conf(width_mult=1.6, depth_mult=2.2, **kwargs)
328+
return _efficientnet_model("efficientnet_b5", inverted_residual_setting, 0.4, pretrained, progress, **kwargs)
329+
330+
331+
def efficientnet_b6(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> EfficientNet:
332+
"""
333+
Constructs a EfficientNet B6 architecture from
334+
`"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" <https://arxiv.org/abs/1905.11946>`_.
335+
336+
Args:
337+
pretrained (bool): If True, returns a model pre-trained on ImageNet
338+
progress (bool): If True, displays a progress bar of the download to stderr
339+
"""
340+
inverted_residual_setting = _efficientnet_conf(width_mult=1.8, depth_mult=2.6, **kwargs)
341+
return _efficientnet_model("efficientnet_b6", inverted_residual_setting, 0.5, pretrained, progress, **kwargs)
342+
343+
344+
def efficientnet_b7(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> EfficientNet:
345+
"""
346+
Constructs a EfficientNet B7 architecture from
347+
`"EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks" <https://arxiv.org/abs/1905.11946>`_.
348+
349+
Args:
350+
pretrained (bool): If True, returns a model pre-trained on ImageNet
351+
progress (bool): If True, displays a progress bar of the download to stderr
352+
"""
353+
inverted_residual_setting = _efficientnet_conf(width_mult=2.0, depth_mult=3.1, **kwargs)
354+
return _efficientnet_model("efficientnet_b7", inverted_residual_setting, 0.5, pretrained, progress, **kwargs)

0 commit comments

Comments
 (0)