Skip to content

Commit 0c60867

Browse files
YosuaMichaelfacebook-github-bot
authored andcommitted
[fbsync] Document all pre-trained Classification weights (#6036)
Summary: * Improving the auto-gen doc. * Adding details for AlexNet, ConvNext, DenseNet, EfficientNets, GoogLeNet and InceptionV3. * Fixing location of `_docs` * Adding docs in the remaining classification models. * Fix linter Reviewed By: NicolasHug Differential Revision: D36760936 fbshipit-source-id: 9764bdcec0d53eff2f63396f25a99b4c2a275707
1 parent 0aae00d commit 0c60867

18 files changed

+291
-20
lines changed

docs/source/conf.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ def inject_weight_metadata(app, what, name, obj, options, lines):
335335

336336
for field in obj:
337337
lines += [f"**{str(field)}**:", ""]
338-
if field == obj.DEFAULT:
339-
lines += [f"This weight is also available as ``{obj.__name__}.DEFAULT``.", ""]
340338

341339
table = []
342340

@@ -349,7 +347,12 @@ def inject_weight_metadata(app, what, name, obj, options, lines):
349347

350348
custom_docs = meta_with_metrics.pop("_docs", None) # Custom per-Weights docs
351349
if custom_docs is not None:
352-
lines += [custom_docs, ""]
350+
lines += [custom_docs]
351+
352+
if field == obj.DEFAULT:
353+
lines += [f"Also available as ``{obj.__name__}.DEFAULT``."]
354+
355+
lines += [""]
353356

354357
for k, v in meta_with_metrics.items():
355358
if k in {"recipe", "license"}:
@@ -367,8 +370,8 @@ def inject_weight_metadata(app, what, name, obj, options, lines):
367370
lines += textwrap.indent(table, " " * 4).split("\n")
368371
lines.append("")
369372
lines.append(
370-
f"The preprocessing/inference transforms are available at ``{str(field)}.transforms`` and "
371-
f"perform the following operations: {field.transforms().describe()}"
373+
f"The inference transforms are available at ``{str(field)}.transforms`` and "
374+
f"perform the following preprocessing operations: {field.transforms().describe()}"
372375
)
373376
lines.append("")
374377

test/test_extended_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_schema_meta_validation(model_fn):
9696
classification_fields = {"categories", ("metrics", "acc@1"), ("metrics", "acc@5")}
9797
defaults = {
9898
"all": {"metrics", "min_size", "num_params", "recipe"},
99-
"models": classification_fields,
99+
"models": classification_fields | {"_docs"},
100100
"detection": {"categories", ("metrics", "box_map")},
101101
"quantization": classification_fields | {"backend", "unquantized"},
102102
"segmentation": {"categories", ("metrics", "miou"), ("metrics", "pixel_acc")},

torchvision/models/alexnet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class AlexNet_Weights(WeightsEnum):
6565
"acc@1": 56.522,
6666
"acc@5": 79.066,
6767
},
68+
"_docs": """
69+
These weights reproduce closely the results of the paper using a simplified training recipe.
70+
""",
6871
},
6972
)
7073
DEFAULT = IMAGENET1K_V1

torchvision/models/convnext.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ def _convnext(
207207
"min_size": (32, 32),
208208
"categories": _IMAGENET_CATEGORIES,
209209
"recipe": "https://github.com/pytorch/vision/tree/main/references/classification#convnext",
210+
"_docs": """
211+
These weights improve upon the results of the original paper by using a modified version of TorchVision's
212+
`new training recipe
213+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
214+
""",
210215
}
211216

212217

torchvision/models/densenet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def _densenet(
261261
"min_size": (29, 29),
262262
"categories": _IMAGENET_CATEGORIES,
263263
"recipe": "https://github.com/pytorch/vision/pull/116",
264+
"_docs": """These weights are ported from LuaTorch.""",
264265
}
265266

266267

torchvision/models/efficientnet.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,24 +431,26 @@ def _efficientnet_conf(
431431

432432
_COMMON_META: Dict[str, Any] = {
433433
"categories": _IMAGENET_CATEGORIES,
434-
"recipe": "https://github.com/pytorch/vision/tree/main/references/classification#efficientnet",
435434
}
436435

437436

438437
_COMMON_META_V1 = {
439438
**_COMMON_META,
440439
"min_size": (1, 1),
440+
"recipe": "https://github.com/pytorch/vision/tree/main/references/classification#efficientnet-v1",
441441
}
442442

443443

444444
_COMMON_META_V2 = {
445445
**_COMMON_META,
446446
"min_size": (33, 33),
447+
"recipe": "https://github.com/pytorch/vision/tree/main/references/classification#efficientnet-v2",
447448
}
448449

449450

450451
class EfficientNet_B0_Weights(WeightsEnum):
451452
IMAGENET1K_V1 = Weights(
453+
# Weights ported from https://github.com/rwightman/pytorch-image-models/
452454
url="https://download.pytorch.org/models/efficientnet_b0_rwightman-3dd342df.pth",
453455
transforms=partial(
454456
ImageClassification, crop_size=224, resize_size=256, interpolation=InterpolationMode.BICUBIC
@@ -460,13 +462,15 @@ class EfficientNet_B0_Weights(WeightsEnum):
460462
"acc@1": 77.692,
461463
"acc@5": 93.532,
462464
},
465+
"_docs": """These weights are ported from the original paper.""",
463466
},
464467
)
465468
DEFAULT = IMAGENET1K_V1
466469

467470

468471
class EfficientNet_B1_Weights(WeightsEnum):
469472
IMAGENET1K_V1 = Weights(
473+
# Weights ported from https://github.com/rwightman/pytorch-image-models/
470474
url="https://download.pytorch.org/models/efficientnet_b1_rwightman-533bc792.pth",
471475
transforms=partial(
472476
ImageClassification, crop_size=240, resize_size=256, interpolation=InterpolationMode.BICUBIC
@@ -478,6 +482,7 @@ class EfficientNet_B1_Weights(WeightsEnum):
478482
"acc@1": 78.642,
479483
"acc@5": 94.186,
480484
},
485+
"_docs": """These weights are ported from the original paper.""",
481486
},
482487
)
483488
IMAGENET1K_V2 = Weights(
@@ -493,13 +498,19 @@ class EfficientNet_B1_Weights(WeightsEnum):
493498
"acc@1": 79.838,
494499
"acc@5": 94.934,
495500
},
501+
"_docs": """
502+
These weights improve upon the results of the original paper by using a modified version of TorchVision's
503+
`new training recipe
504+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
505+
""",
496506
},
497507
)
498508
DEFAULT = IMAGENET1K_V2
499509

500510

501511
class EfficientNet_B2_Weights(WeightsEnum):
502512
IMAGENET1K_V1 = Weights(
513+
# Weights ported from https://github.com/rwightman/pytorch-image-models/
503514
url="https://download.pytorch.org/models/efficientnet_b2_rwightman-bcdf34b7.pth",
504515
transforms=partial(
505516
ImageClassification, crop_size=288, resize_size=288, interpolation=InterpolationMode.BICUBIC
@@ -511,13 +522,15 @@ class EfficientNet_B2_Weights(WeightsEnum):
511522
"acc@1": 80.608,
512523
"acc@5": 95.310,
513524
},
525+
"_docs": """These weights are ported from the original paper.""",
514526
},
515527
)
516528
DEFAULT = IMAGENET1K_V1
517529

518530

519531
class EfficientNet_B3_Weights(WeightsEnum):
520532
IMAGENET1K_V1 = Weights(
533+
# Weights ported from https://github.com/rwightman/pytorch-image-models/
521534
url="https://download.pytorch.org/models/efficientnet_b3_rwightman-cf984f9c.pth",
522535
transforms=partial(
523536
ImageClassification, crop_size=300, resize_size=320, interpolation=InterpolationMode.BICUBIC
@@ -529,13 +542,15 @@ class EfficientNet_B3_Weights(WeightsEnum):
529542
"acc@1": 82.008,
530543
"acc@5": 96.054,
531544
},
545+
"_docs": """These weights are ported from the original paper.""",
532546
},
533547
)
534548
DEFAULT = IMAGENET1K_V1
535549

536550

537551
class EfficientNet_B4_Weights(WeightsEnum):
538552
IMAGENET1K_V1 = Weights(
553+
# Weights ported from https://github.com/rwightman/pytorch-image-models/
539554
url="https://download.pytorch.org/models/efficientnet_b4_rwightman-7eb33cd5.pth",
540555
transforms=partial(
541556
ImageClassification, crop_size=380, resize_size=384, interpolation=InterpolationMode.BICUBIC
@@ -547,13 +562,15 @@ class EfficientNet_B4_Weights(WeightsEnum):
547562
"acc@1": 83.384,
548563
"acc@5": 96.594,
549564
},
565+
"_docs": """These weights are ported from the original paper.""",
550566
},
551567
)
552568
DEFAULT = IMAGENET1K_V1
553569

554570

555571
class EfficientNet_B5_Weights(WeightsEnum):
556572
IMAGENET1K_V1 = Weights(
573+
# Weights ported from https://github.com/lukemelas/EfficientNet-PyTorch/
557574
url="https://download.pytorch.org/models/efficientnet_b5_lukemelas-b6417697.pth",
558575
transforms=partial(
559576
ImageClassification, crop_size=456, resize_size=456, interpolation=InterpolationMode.BICUBIC
@@ -565,13 +582,15 @@ class EfficientNet_B5_Weights(WeightsEnum):
565582
"acc@1": 83.444,
566583
"acc@5": 96.628,
567584
},
585+
"_docs": """These weights are ported from the original paper.""",
568586
},
569587
)
570588
DEFAULT = IMAGENET1K_V1
571589

572590

573591
class EfficientNet_B6_Weights(WeightsEnum):
574592
IMAGENET1K_V1 = Weights(
593+
# Weights ported from https://github.com/lukemelas/EfficientNet-PyTorch/
575594
url="https://download.pytorch.org/models/efficientnet_b6_lukemelas-c76e70fd.pth",
576595
transforms=partial(
577596
ImageClassification, crop_size=528, resize_size=528, interpolation=InterpolationMode.BICUBIC
@@ -583,13 +602,15 @@ class EfficientNet_B6_Weights(WeightsEnum):
583602
"acc@1": 84.008,
584603
"acc@5": 96.916,
585604
},
605+
"_docs": """These weights are ported from the original paper.""",
586606
},
587607
)
588608
DEFAULT = IMAGENET1K_V1
589609

590610

591611
class EfficientNet_B7_Weights(WeightsEnum):
592612
IMAGENET1K_V1 = Weights(
613+
# Weights ported from https://github.com/lukemelas/EfficientNet-PyTorch/
593614
url="https://download.pytorch.org/models/efficientnet_b7_lukemelas-dcc49843.pth",
594615
transforms=partial(
595616
ImageClassification, crop_size=600, resize_size=600, interpolation=InterpolationMode.BICUBIC
@@ -601,6 +622,7 @@ class EfficientNet_B7_Weights(WeightsEnum):
601622
"acc@1": 84.122,
602623
"acc@5": 96.908,
603624
},
625+
"_docs": """These weights are ported from the original paper.""",
604626
},
605627
)
606628
DEFAULT = IMAGENET1K_V1
@@ -622,6 +644,11 @@ class EfficientNet_V2_S_Weights(WeightsEnum):
622644
"acc@1": 84.228,
623645
"acc@5": 96.878,
624646
},
647+
"_docs": """
648+
These weights improve upon the results of the original paper by using a modified version of TorchVision's
649+
`new training recipe
650+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
651+
""",
625652
},
626653
)
627654
DEFAULT = IMAGENET1K_V1
@@ -643,12 +670,18 @@ class EfficientNet_V2_M_Weights(WeightsEnum):
643670
"acc@1": 85.112,
644671
"acc@5": 97.156,
645672
},
673+
"_docs": """
674+
These weights improve upon the results of the original paper by using a modified version of TorchVision's
675+
`new training recipe
676+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
677+
""",
646678
},
647679
)
648680
DEFAULT = IMAGENET1K_V1
649681

650682

651683
class EfficientNet_V2_L_Weights(WeightsEnum):
684+
# Weights ported from https://github.com/google/automl/tree/master/efficientnetv2
652685
IMAGENET1K_V1 = Weights(
653686
url="https://download.pytorch.org/models/efficientnet_v2_l-59c71312.pth",
654687
transforms=partial(
@@ -666,6 +699,7 @@ class EfficientNet_V2_L_Weights(WeightsEnum):
666699
"acc@1": 85.808,
667700
"acc@5": 97.788,
668701
},
702+
"_docs": """These weights are ported from the original paper.""",
669703
},
670704
)
671705
DEFAULT = IMAGENET1K_V1
@@ -1036,13 +1070,11 @@ def efficientnet_v2_l(
10361070

10371071
model_urls = _ModelURLs(
10381072
{
1039-
# Weights ported from https://github.com/rwightman/pytorch-image-models/
10401073
"efficientnet_b0": EfficientNet_B0_Weights.IMAGENET1K_V1.url,
10411074
"efficientnet_b1": EfficientNet_B1_Weights.IMAGENET1K_V1.url,
10421075
"efficientnet_b2": EfficientNet_B2_Weights.IMAGENET1K_V1.url,
10431076
"efficientnet_b3": EfficientNet_B3_Weights.IMAGENET1K_V1.url,
10441077
"efficientnet_b4": EfficientNet_B4_Weights.IMAGENET1K_V1.url,
1045-
# Weights ported from https://github.com/lukemelas/EfficientNet-PyTorch/
10461078
"efficientnet_b5": EfficientNet_B5_Weights.IMAGENET1K_V1.url,
10471079
"efficientnet_b6": EfficientNet_B6_Weights.IMAGENET1K_V1.url,
10481080
"efficientnet_b7": EfficientNet_B7_Weights.IMAGENET1K_V1.url,

torchvision/models/googlenet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class GoogLeNet_Weights(WeightsEnum):
288288
"acc@1": 69.778,
289289
"acc@5": 89.530,
290290
},
291+
"_docs": """These weights are ported from the original paper.""",
291292
},
292293
)
293294
DEFAULT = IMAGENET1K_V1

torchvision/models/inception.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ class Inception_V3_Weights(WeightsEnum):
420420
"acc@1": 77.294,
421421
"acc@5": 93.450,
422422
},
423+
"_docs": """These weights are ported from the original paper.""",
423424
},
424425
)
425426
DEFAULT = IMAGENET1K_V1

torchvision/models/mnasnet.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class MNASNet0_5_Weights(WeightsEnum):
229229
"acc@1": 67.734,
230230
"acc@5": 87.490,
231231
},
232+
"_docs": """These weights reproduce closely the results of the paper.""",
232233
},
233234
)
234235
DEFAULT = IMAGENET1K_V1
@@ -246,6 +247,10 @@ class MNASNet0_75_Weights(WeightsEnum):
246247
"acc@1": 71.180,
247248
"acc@5": 90.496,
248249
},
250+
"_docs": """
251+
These weights were trained from scratch by using TorchVision's `new training recipe
252+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
253+
""",
249254
},
250255
)
251256
DEFAULT = IMAGENET1K_V1
@@ -262,6 +267,7 @@ class MNASNet1_0_Weights(WeightsEnum):
262267
"acc@1": 73.456,
263268
"acc@5": 91.510,
264269
},
270+
"_docs": """These weights reproduce closely the results of the paper.""",
265271
},
266272
)
267273
DEFAULT = IMAGENET1K_V1
@@ -279,6 +285,10 @@ class MNASNet1_3_Weights(WeightsEnum):
279285
"acc@1": 76.506,
280286
"acc@5": 93.522,
281287
},
288+
"_docs": """
289+
These weights were trained from scratch by using TorchVision's `new training recipe
290+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
291+
""",
282292
},
283293
)
284294
DEFAULT = IMAGENET1K_V1

torchvision/models/mobilenetv2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class MobileNet_V2_Weights(WeightsEnum):
212212
"acc@1": 71.878,
213213
"acc@5": 90.286,
214214
},
215+
"_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
215216
},
216217
)
217218
IMAGENET1K_V2 = Weights(
@@ -224,6 +225,11 @@ class MobileNet_V2_Weights(WeightsEnum):
224225
"acc@1": 72.154,
225226
"acc@5": 90.822,
226227
},
228+
"_docs": """
229+
These weights improve upon the results of the original paper by using a modified version of TorchVision's
230+
`new training recipe
231+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
232+
""",
227233
},
228234
)
229235
DEFAULT = IMAGENET1K_V2

torchvision/models/mobilenetv3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class MobileNet_V3_Large_Weights(WeightsEnum):
321321
"acc@1": 74.042,
322322
"acc@5": 91.340,
323323
},
324+
"_docs": """These weights were trained from scratch by using a simple training recipe.""",
324325
},
325326
)
326327
IMAGENET1K_V2 = Weights(
@@ -334,6 +335,11 @@ class MobileNet_V3_Large_Weights(WeightsEnum):
334335
"acc@1": 75.274,
335336
"acc@5": 92.566,
336337
},
338+
"_docs": """
339+
These weights improve marginally upon the results of the original paper by using a modified version of
340+
TorchVision's `new training recipe
341+
<https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
342+
""",
337343
},
338344
)
339345
DEFAULT = IMAGENET1K_V2
@@ -351,6 +357,9 @@ class MobileNet_V3_Small_Weights(WeightsEnum):
351357
"acc@1": 67.668,
352358
"acc@5": 87.402,
353359
},
360+
"_docs": """
361+
These weights improve upon the results of the original paper by using a simple training recipe.
362+
""",
354363
},
355364
)
356365
DEFAULT = IMAGENET1K_V1

0 commit comments

Comments
 (0)