We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Improve the accuracy of Classification models by using SOTA recipes and primitives
## 🚀 Feature
Update the weights of all pre-trained models to improve their accuracy.

## Motivation

<h4 id="new-recipe-with-fixres">New Recipe + FixRes mitigations</h4>

```
torchrun --nproc_per_node=8 train.py --model $MODEL_NAME --batch-size 128 --lr 0.5 \
--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \
--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.00002 \
--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \
--train-crop-size 176 --model-ema --val-resize-size 232
```

Using a recipe which includes Warmup, Cosine Annealing, Label Smoothing, Mixup, Cutmix, Random Erasing, TrivialAugment, No BN weight decay, EMA and long training cycles and optional FixRes mitigations we are able to improve the `resnet50` accuracy by over 4.5 points. For more information on the training recipe, check [here](https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/):
```
Old ResNet50:
Acc@1 76.130 Acc@5 92.862

New ResNet50:
Acc@1 80.674 Acc@5 95.166
```

Running other models through the same recipe, achieves the following improved accuracies:
```
ResNet101:
Acc@1 81.728 Acc@5 95.670

ResNet152:
Acc@1 82.042 Acc@5 95.926

ResNeXt50_32x4d:
Acc@1 81.116 Acc@5 95.478

ResNeXt101_32x8d:
Acc@1 82.834 Acc@5 96.228

MobileNetV3 Large:
Acc@1 74.938 Acc@5 92.496

Wide ResNet50 2:
Acc@1 81.602 Acc@5 95.758 (@prabhat00155)

Wide ResNet101 2:
Acc@1 82.492 Acc@5 96.110 (@prabhat00155)

regnet_x_400mf:
Acc@1 74.864 Acc@5 92.322 (@kazhang)

regnet_x_800mf:
Acc@1 77.522 Acc@5 93.826 (@kazhang)

regnet_x_1_6gf:
Acc@1 79.668 Acc@5 94.922 (@kazhang)
```

<h4 id="new-recipe">New Recipe (without FixRes mitigations)</h4>

```
torchrun --nproc_per_node=8 train.py --model $MODEL_NAME --batch-size 128 --lr 0.5 \
--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \
--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.00002 \
--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \
--model-ema --val-resize-size 232
```

Removing the optional FixRes mitigations seems to yield better results for some deeper architectures and variants with larger receptive fields:
```
ResNet101:
Acc@1 81.886 Acc@5 95.780

ResNet152:
Acc@1 82.284 Acc@5 96.002

ResNeXt50_32x4d:
Acc@1 81.198 Acc@5 95.340

ResNeXt101_32x8d:
Acc@1 82.812 Acc@5 96.226

MobileNetV3 Large:
Acc@1 75.152 Acc@5 92.634

Wide ResNet50_2:
Acc@1 81.452 Acc@5 95.544 (@prabhat00155)

Wide ResNet101_2:
Acc@1 82.510 Acc@5 96.020 (@prabhat00155)

regnet_x_3_2gf:
Acc@1 81.196 Acc@5 95.430

regnet_x_8gf:
Acc@1 81.682 Acc@5 95.678

regnet_x_16g:
Acc@1 82.716 Acc@5 96.196

regnet_x_32gf:
Acc@1 83.014 Acc@5 96.288

regnet_y_400mf:
Acc@1 75.804 Acc@5 92.742

regnet_y_800mf:
Acc@1 78.828 Acc@5 94.502

regnet_y_1_6gf:
Acc@1 80.876 Acc@5 95.444

regnet_y_3_2gf:
Acc@1 81.982 Acc@5 95.972

regnet_y_8gf:
Acc@1 82.828 Acc@5 96.330

regnet_y_16gf:
Acc@1 82.886 Acc@5 96.328

regnet_y_32gf:
Acc@1 83.368 Acc@5 96.498
```

<h4 id="new-recipe-with-reg-tuning">New Recipe + Regularization tuning</h4>

```
torchrun --nproc_per_node=8 train.py --model $MODEL_NAME --batch-size 128 --lr 0.5 \
--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \
--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.00001 \
--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \
--model-ema --val-resize-size 232
```

Adjusting slightly the regularization can help us improve the following:
```
MobileNetV3 Large:
Acc@1 75.274 Acc@5 92.566
```
In addition to regularization adjustment we can also apply the Repeated Augmentation trick ` --ra-sampler --ra-reps 4`:

```
MobileNetV2:
Acc@1 72.154 Acc@5 90.822
```

<h4 id="ptq-models">Post-Training Quantized models</h4>

```
ResNet50:
Acc@1 80.282 Acc@5 94.976

ResNeXt101_32x8d:
Acc@1 82.574 Acc@5 96.132
```

<h4 id="new-recipe-with-lr-wd-crop-tuning">New Recipe (LR+weight_decay+train_crop_size tuning)</h4>

```
torchrun --ngpus 8 --nodes 1 --model $MODEL_NAME --batch-size 128 --lr 1 \
--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \
--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.000002 \
--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \
--train-crop-size 208 --model-ema --val-crop-size 240 --val-resize-size 255
```

```
EfficientNet-B1:
Acc@1 79.838 Acc@5 94.934
```

## Pitch

To be able to improve the pre-trained model accuracy, we need to complete the "Batteries Included" work as #3911. Moreover we will need to extend our existing model builders to support multiple weights as described at #4611. Then we will be able to:
- Update our reference scripts for classification to support the new primitives added by the "Batteries Included" initiative.
- Find a good training recipe for the most important pre-trained models and re-train them. Note that different training configuration might be required for different types of models (for example mobile models are less likely to overfit comparing to bigger models and thus make use of different recipes/primitives)
- Update the weights of the models in the library.

cc @datumbox @vfdev-5

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torchvision/prototype/models/mobilenetv2.py`
Content:
```
1 from functools import partial
2 from typing import Any, Optional
3 
4 from torchvision.prototype.transforms import ImageNetEval
5 from torchvision.transforms.functional import InterpolationMode
6 
7 from ...models.mobilenetv2 import MobileNetV2
8 from ._api import WeightsEnum, Weights
9 from ._meta import _IMAGENET_CATEGORIES
10 from ._utils import handle_legacy_interface, _ovewrite_named_param
11 
12 
13 __all__ = ["MobileNetV2", "MobileNet_V2_Weights", "mobilenet_v2"]
14 
15 
16 class MobileNet_V2_Weights(WeightsEnum):
17     IMAGENET1K_V1 = Weights(
18         url="https://download.pytorch.org/models/mobilenet_v2-b0353104.pth",
19         transforms=partial(ImageNetEval, crop_size=224),
20         meta={
21             "task": "image_classification",
22             "architecture": "MobileNetV2",
23             "publication_year": 2018,
24             "num_params": 3504872,
25             "size": (224, 224),
26             "min_size": (1, 1),
27             "categories": _IMAGENET_CATEGORIES,
28             "interpolation": InterpolationMode.BILINEAR,
29             "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#mobilenetv2",
30             "acc@1": 71.878,
31             "acc@5": 90.286,
32         },
33     )
34     DEFAULT = IMAGENET1K_V1
35 
36 
37 @handle_legacy_interface(weights=("pretrained", MobileNet_V2_Weights.IMAGENET1K_V1))
38 def mobilenet_v2(
39     *, weights: Optional[MobileNet_V2_Weights] = None, progress: bool = True, **kwargs: Any
40 ) -> MobileNetV2:
41     weights = MobileNet_V2_Weights.verify(weights)
42 
43     if weights is not None:
44         _ovewrite_named_param(kwargs, "num_classes", len(weights.meta["categories"]))
45 
46     model = MobileNetV2(**kwargs)
47 
48     if weights is not None:
49         model.load_state_dict(weights.get_state_dict(progress=progress))
50 
51     return model
52
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torchvision/prototype/models/mobilenetv2.py b/torchvision/prototype/models/mobilenetv2.py
--- a/torchvision/prototype/models/mobilenetv2.py
+++ b/torchvision/prototype/models/mobilenetv2.py
@@ -13,25 +13,40 @@
 __all__ = ["MobileNetV2", "MobileNet_V2_Weights", "mobilenet_v2"]
 
 
+_COMMON_META = {
+    "task": "image_classification",
+    "architecture": "MobileNetV2",
+    "publication_year": 2018,
+    "num_params": 3504872,
+    "size": (224, 224),
+    "min_size": (1, 1),
+    "categories": _IMAGENET_CATEGORIES,
+    "interpolation": InterpolationMode.BILINEAR,
+}
+
+
 class MobileNet_V2_Weights(WeightsEnum):
     IMAGENET1K_V1 = Weights(
         url="https://download.pytorch.org/models/mobilenet_v2-b0353104.pth",
         transforms=partial(ImageNetEval, crop_size=224),
         meta={
-            "task": "image_classification",
-            "architecture": "MobileNetV2",
-            "publication_year": 2018,
-            "num_params": 3504872,
-            "size": (224, 224),
-            "min_size": (1, 1),
-            "categories": _IMAGENET_CATEGORIES,
-            "interpolation": InterpolationMode.BILINEAR,
+            **_COMMON_META,
             "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#mobilenetv2",
             "acc@1": 71.878,
             "acc@5": 90.286,
         },
     )
-    DEFAULT = IMAGENET1K_V1
+    IMAGENET1K_V2 = Weights(
+        url="https://download.pytorch.org/models/mobilenet_v2-7ebf99e0.pth",
+        transforms=partial(ImageNetEval, crop_size=224, resize_size=232),
+        meta={
+            **_COMMON_META,
+            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe-with-reg-tuning",
+            "acc@1": 72.154,
+            "acc@5": 90.822,
+        },
+    )
+    DEFAULT = IMAGENET1K_V2
 
 
 @handle_legacy_interface(weights=("pretrained", MobileNet_V2_Weights.IMAGENET1K_V1))

{"golden_diff": "diff --git a/torchvision/prototype/models/mobilenetv2.py b/torchvision/prototype/models/mobilenetv2.py\n--- a/torchvision/prototype/models/mobilenetv2.py\n+++ b/torchvision/prototype/models/mobilenetv2.py\n@@ -13,25 +13,40 @@\n __all__ = [\"MobileNetV2\", \"MobileNet_V2_Weights\", \"mobilenet_v2\"]\n \n \n+_COMMON_META = {\n+    \"task\": \"image_classification\",\n+    \"architecture\": \"MobileNetV2\",\n+    \"publication_year\": 2018,\n+    \"num_params\": 3504872,\n+    \"size\": (224, 224),\n+    \"min_size\": (1, 1),\n+    \"categories\": _IMAGENET_CATEGORIES,\n+    \"interpolation\": InterpolationMode.BILINEAR,\n+}\n+\n+\n class MobileNet_V2_Weights(WeightsEnum):\n     IMAGENET1K_V1 = Weights(\n         url=\"https://download.pytorch.org/models/mobilenet_v2-b0353104.pth\",\n         transforms=partial(ImageNetEval, crop_size=224),\n         meta={\n-            \"task\": \"image_classification\",\n-            \"architecture\": \"MobileNetV2\",\n-            \"publication_year\": 2018,\n-            \"num_params\": 3504872,\n-            \"size\": (224, 224),\n-            \"min_size\": (1, 1),\n-            \"categories\": _IMAGENET_CATEGORIES,\n-            \"interpolation\": InterpolationMode.BILINEAR,\n+            **_COMMON_META,\n             \"recipe\": \"https://github.com/pytorch/vision/tree/main/references/classification#mobilenetv2\",\n             \"acc@1\": 71.878,\n             \"acc@5\": 90.286,\n         },\n     )\n-    DEFAULT = IMAGENET1K_V1\n+    IMAGENET1K_V2 = Weights(\n+        url=\"https://download.pytorch.org/models/mobilenet_v2-7ebf99e0.pth\",\n+        transforms=partial(ImageNetEval, crop_size=224, resize_size=232),\n+        meta={\n+            **_COMMON_META,\n+            \"recipe\": \"https://github.com/pytorch/vision/issues/3995#new-recipe-with-reg-tuning\",\n+            \"acc@1\": 72.154,\n+            \"acc@5\": 90.822,\n+        },\n+    )\n+    DEFAULT = IMAGENET1K_V2\n \n \n @handle_legacy_interface(weights=(\"pretrained\", MobileNet_V2_Weights.IMAGENET1K_V1))\n", "issue": "Improve the accuracy of Classification models by using SOTA recipes and primitives\n## \ud83d\ude80 Feature\r\nUpdate the weights of all pre-trained models to improve their accuracy.\r\n\r\n## Motivation\r\n\r\n<h4 id=\"new-recipe-with-fixres\">New Recipe + FixRes mitigations</h4>\r\n\r\n```\r\ntorchrun --nproc_per_node=8 train.py --model $MODEL_NAME --batch-size 128 --lr 0.5 \\\r\n--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \\\r\n--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.00002 \\\r\n--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \\\r\n--train-crop-size 176 --model-ema --val-resize-size 232\r\n```\r\n\r\nUsing a recipe which includes Warmup, Cosine Annealing, Label Smoothing, Mixup, Cutmix, Random Erasing, TrivialAugment, No BN weight decay, EMA and long training cycles and optional FixRes mitigations we are able to improve the `resnet50` accuracy by over 4.5 points. For more information on the training recipe, check [here](https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/):\r\n```\r\nOld ResNet50:\r\nAcc@1 76.130 Acc@5 92.862\r\n\r\nNew ResNet50:\r\nAcc@1 80.674 Acc@5 95.166\r\n```\r\n\r\nRunning other models through the same recipe, achieves the following improved accuracies:\r\n```\r\nResNet101:\r\nAcc@1 81.728 Acc@5 95.670\r\n\r\nResNet152:\r\nAcc@1 82.042 Acc@5 95.926\r\n\r\nResNeXt50_32x4d:\r\nAcc@1 81.116 Acc@5 95.478\r\n\r\nResNeXt101_32x8d:\r\nAcc@1 82.834 Acc@5 96.228\r\n\r\nMobileNetV3 Large:\r\nAcc@1 74.938 Acc@5 92.496\r\n\r\nWide ResNet50 2:\r\nAcc@1 81.602 Acc@5 95.758 (@prabhat00155)\r\n\r\nWide ResNet101 2:\r\nAcc@1 82.492 Acc@5 96.110 (@prabhat00155)\r\n\r\nregnet_x_400mf:\r\nAcc@1 74.864 Acc@5 92.322 (@kazhang)\r\n\r\nregnet_x_800mf:\r\nAcc@1 77.522 Acc@5 93.826 (@kazhang)\r\n\r\nregnet_x_1_6gf:\r\nAcc@1 79.668 Acc@5 94.922 (@kazhang)\r\n```\r\n\r\n<h4 id=\"new-recipe\">New Recipe (without FixRes mitigations)</h4>\r\n\r\n```\r\ntorchrun --nproc_per_node=8 train.py --model $MODEL_NAME --batch-size 128 --lr 0.5 \\\r\n--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \\\r\n--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.00002 \\\r\n--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \\\r\n--model-ema --val-resize-size 232\r\n```\r\n\r\nRemoving the optional FixRes mitigations seems to yield better results for some deeper architectures and variants with larger receptive fields:\r\n```\r\nResNet101:\r\nAcc@1 81.886 Acc@5 95.780\r\n\r\nResNet152:\r\nAcc@1 82.284 Acc@5 96.002\r\n\r\nResNeXt50_32x4d:\r\nAcc@1 81.198 Acc@5 95.340\r\n\r\nResNeXt101_32x8d:\r\nAcc@1 82.812 Acc@5 96.226\r\n\r\nMobileNetV3 Large:\r\nAcc@1 75.152 Acc@5 92.634\r\n\r\nWide ResNet50_2:\r\nAcc@1 81.452 Acc@5 95.544 (@prabhat00155)\r\n\r\nWide ResNet101_2:\r\nAcc@1 82.510 Acc@5 96.020 (@prabhat00155)\r\n\r\nregnet_x_3_2gf:\r\nAcc@1 81.196 Acc@5 95.430\r\n\r\nregnet_x_8gf:\r\nAcc@1 81.682 Acc@5 95.678\r\n\r\nregnet_x_16g:\r\nAcc@1 82.716 Acc@5 96.196\r\n\r\nregnet_x_32gf:\r\nAcc@1 83.014 Acc@5 96.288\r\n\r\nregnet_y_400mf:\r\nAcc@1 75.804 Acc@5 92.742\r\n\r\nregnet_y_800mf:\r\nAcc@1 78.828 Acc@5 94.502\r\n\r\nregnet_y_1_6gf:\r\nAcc@1 80.876 Acc@5 95.444\r\n\r\nregnet_y_3_2gf:\r\nAcc@1 81.982 Acc@5 95.972\r\n\r\nregnet_y_8gf:\r\nAcc@1 82.828 Acc@5 96.330\r\n\r\nregnet_y_16gf:\r\nAcc@1 82.886 Acc@5 96.328\r\n\r\nregnet_y_32gf:\r\nAcc@1 83.368 Acc@5 96.498\r\n```\r\n\r\n<h4 id=\"new-recipe-with-reg-tuning\">New Recipe + Regularization tuning</h4>\r\n\r\n```\r\ntorchrun --nproc_per_node=8 train.py --model $MODEL_NAME --batch-size 128 --lr 0.5 \\\r\n--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \\\r\n--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.00001 \\\r\n--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \\\r\n--model-ema --val-resize-size 232\r\n```\r\n\r\nAdjusting slightly the regularization can help us improve the following:\r\n```\r\nMobileNetV3 Large:\r\nAcc@1 75.274 Acc@5 92.566\r\n```\r\nIn addition to regularization adjustment we can also apply the Repeated Augmentation trick ` --ra-sampler --ra-reps 4`:\r\n\r\n```\r\nMobileNetV2:\r\nAcc@1 72.154 Acc@5 90.822\r\n```\r\n\r\n<h4 id=\"ptq-models\">Post-Training Quantized models</h4>\r\n\r\n```\r\nResNet50:\r\nAcc@1 80.282 Acc@5 94.976\r\n\r\nResNeXt101_32x8d:\r\nAcc@1 82.574 Acc@5 96.132\r\n```\r\n\r\n<h4 id=\"new-recipe-with-lr-wd-crop-tuning\">New Recipe (LR+weight_decay+train_crop_size tuning)</h4>\r\n\r\n```\r\ntorchrun --ngpus 8 --nodes 1 --model $MODEL_NAME --batch-size 128 --lr 1 \\\r\n--lr-scheduler cosineannealinglr --lr-warmup-epochs 5 --lr-warmup-method linear \\\r\n--auto-augment ta_wide --epochs 600 --random-erase 0.1 --weight-decay 0.000002 \\\r\n--norm-weight-decay 0.0 --label-smoothing 0.1 --mixup-alpha 0.2 --cutmix-alpha 1.0 \\\r\n--train-crop-size 208 --model-ema --val-crop-size 240 --val-resize-size 255\r\n```\r\n\r\n```\r\nEfficientNet-B1:\r\nAcc@1 79.838 Acc@5 94.934\r\n```\r\n\r\n## Pitch\r\n\r\nTo be able to improve the pre-trained model accuracy, we need to complete the \"Batteries Included\" work as #3911. Moreover we will need to extend our existing model builders to support multiple weights as described at #4611. Then we will be able to:\r\n- Update our reference scripts for classification to support the new primitives added by the \"Batteries Included\" initiative.\r\n- Find a good training recipe for the most important pre-trained models and re-train them. Note that different training configuration might be required for different types of models (for example mobile models are less likely to overfit comparing to bigger models and thus make use of different recipes/primitives)\r\n- Update the weights of the models in the library.\r\n\r\ncc @datumbox @vfdev-5\n", "before_files": [{"content": "from functools import partial\nfrom typing import Any, Optional\n\nfrom torchvision.prototype.transforms import ImageNetEval\nfrom torchvision.transforms.functional import InterpolationMode\n\nfrom ...models.mobilenetv2 import MobileNetV2\nfrom ._api import WeightsEnum, Weights\nfrom ._meta import _IMAGENET_CATEGORIES\nfrom ._utils import handle_legacy_interface, _ovewrite_named_param\n\n\n__all__ = [\"MobileNetV2\", \"MobileNet_V2_Weights\", \"mobilenet_v2\"]\n\n\nclass MobileNet_V2_Weights(WeightsEnum):\n    IMAGENET1K_V1 = Weights(\n        url=\"https://download.pytorch.org/models/mobilenet_v2-b0353104.pth\",\n        transforms=partial(ImageNetEval, crop_size=224),\n        meta={\n            \"task\": \"image_classification\",\n            \"architecture\": \"MobileNetV2\",\n            \"publication_year\": 2018,\n            \"num_params\": 3504872,\n            \"size\": (224, 224),\n            \"min_size\": (1, 1),\n            \"categories\": _IMAGENET_CATEGORIES,\n            \"interpolation\": InterpolationMode.BILINEAR,\n            \"recipe\": \"https://github.com/pytorch/vision/tree/main/references/classification#mobilenetv2\",\n            \"acc@1\": 71.878,\n            \"acc@5\": 90.286,\n        },\n    )\n    DEFAULT = IMAGENET1K_V1\n\n\n@handle_legacy_interface(weights=(\"pretrained\", MobileNet_V2_Weights.IMAGENET1K_V1))\ndef mobilenet_v2(\n    *, weights: Optional[MobileNet_V2_Weights] = None, progress: bool = True, **kwargs: Any\n) -> MobileNetV2:\n    weights = MobileNet_V2_Weights.verify(weights)\n\n    if weights is not None:\n        _ovewrite_named_param(kwargs, \"num_classes\", len(weights.meta[\"categories\"]))\n\n    model = MobileNetV2(**kwargs)\n\n    if weights is not None:\n        model.load_state_dict(weights.get_state_dict(progress=progress))\n\n    return model\n", "path": "torchvision/prototype/models/mobilenetv2.py"}], "after_files": [{"content": "from functools import partial\nfrom typing import Any, Optional\n\nfrom torchvision.prototype.transforms import ImageNetEval\nfrom torchvision.transforms.functional import InterpolationMode\n\nfrom ...models.mobilenetv2 import MobileNetV2\nfrom ._api import WeightsEnum, Weights\nfrom ._meta import _IMAGENET_CATEGORIES\nfrom ._utils import handle_legacy_interface, _ovewrite_named_param\n\n\n__all__ = [\"MobileNetV2\", \"MobileNet_V2_Weights\", \"mobilenet_v2\"]\n\n\n_COMMON_META = {\n    \"task\": \"image_classification\",\n    \"architecture\": \"MobileNetV2\",\n    \"publication_year\": 2018,\n    \"num_params\": 3504872,\n    \"size\": (224, 224),\n    \"min_size\": (1, 1),\n    \"categories\": _IMAGENET_CATEGORIES,\n    \"interpolation\": InterpolationMode.BILINEAR,\n}\n\n\nclass MobileNet_V2_Weights(WeightsEnum):\n    IMAGENET1K_V1 = Weights(\n        url=\"https://download.pytorch.org/models/mobilenet_v2-b0353104.pth\",\n        transforms=partial(ImageNetEval, crop_size=224),\n        meta={\n            **_COMMON_META,\n            \"recipe\": \"https://github.com/pytorch/vision/tree/main/references/classification#mobilenetv2\",\n            \"acc@1\": 71.878,\n            \"acc@5\": 90.286,\n        },\n    )\n    IMAGENET1K_V2 = Weights(\n        url=\"https://download.pytorch.org/models/mobilenet_v2-7ebf99e0.pth\",\n        transforms=partial(ImageNetEval, crop_size=224, resize_size=232),\n        meta={\n            **_COMMON_META,\n            \"recipe\": \"https://github.com/pytorch/vision/issues/3995#new-recipe-with-reg-tuning\",\n            \"acc@1\": 72.154,\n            \"acc@5\": 90.822,\n        },\n    )\n    DEFAULT = IMAGENET1K_V2\n\n\n@handle_legacy_interface(weights=(\"pretrained\", MobileNet_V2_Weights.IMAGENET1K_V1))\ndef mobilenet_v2(\n    *, weights: Optional[MobileNet_V2_Weights] = None, progress: bool = True, **kwargs: Any\n) -> MobileNetV2:\n    weights = MobileNet_V2_Weights.verify(weights)\n\n    if weights is not None:\n        _ovewrite_named_param(kwargs, \"num_classes\", len(weights.meta[\"categories\"]))\n\n    model = MobileNetV2(**kwargs)\n\n    if weights is not None:\n        model.load_state_dict(weights.get_state_dict(progress=progress))\n\n    return model\n", "path": "torchvision/prototype/models/mobilenetv2.py"}]}