From 4097b99a049574fc2a6250d774777a72b0231a6b Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Mon, 7 Mar 2022 14:09:00 +0000 Subject: [PATCH 1/3] Adding improved MobileNetV2 weights --- torchvision/prototype/models/mobilenetv2.py | 33 +++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/torchvision/prototype/models/mobilenetv2.py b/torchvision/prototype/models/mobilenetv2.py index 3531394acc8..6b2594e3697 100644 --- 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), + meta={ + **_COMMON_META, + "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe-with-reg-tuning", + "acc@1": 72.144, + "acc@5": 90.818, + }, + ) + DEFAULT = IMAGENET1K_V2 @handle_legacy_interface(weights=("pretrained", MobileNet_V2_Weights.IMAGENET1K_V1)) From 2f07c68615660a243c54f5fb69bfd31ffa076cae Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Mon, 7 Mar 2022 14:17:27 +0000 Subject: [PATCH 2/3] Fix eval sizes. --- torchvision/prototype/models/mobilenetv2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/prototype/models/mobilenetv2.py b/torchvision/prototype/models/mobilenetv2.py index 6b2594e3697..9cb5cd84706 100644 --- a/torchvision/prototype/models/mobilenetv2.py +++ b/torchvision/prototype/models/mobilenetv2.py @@ -38,7 +38,7 @@ class MobileNet_V2_Weights(WeightsEnum): ) IMAGENET1K_V2 = Weights( url="https://download.pytorch.org/models/mobilenet_v2-7ebf99e0.pth", - transforms=partial(ImageNetEval, crop_size=224), + 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", From 43657d1765353a90dee981773e0626f8c51f875c Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Mon, 7 Mar 2022 14:34:48 +0000 Subject: [PATCH 3/3] Update accuracy with batch-size 1 run --- torchvision/prototype/models/mobilenetv2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torchvision/prototype/models/mobilenetv2.py b/torchvision/prototype/models/mobilenetv2.py index 9cb5cd84706..7176252111a 100644 --- a/torchvision/prototype/models/mobilenetv2.py +++ b/torchvision/prototype/models/mobilenetv2.py @@ -42,8 +42,8 @@ class MobileNet_V2_Weights(WeightsEnum): meta={ **_COMMON_META, "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe-with-reg-tuning", - "acc@1": 72.144, - "acc@5": 90.818, + "acc@1": 72.154, + "acc@5": 90.822, }, ) DEFAULT = IMAGENET1K_V2