From 423009c40319d86d7d26163ea1803a21396c8a24 Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Mon, 25 Apr 2022 22:45:21 +0100 Subject: [PATCH 01/12] Add resnext101_64x4d model definition --- torchvision/models/resnet.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/torchvision/models/resnet.py b/torchvision/models/resnet.py index 3c71938fa1d..9c1c4ff774f 100644 --- a/torchvision/models/resnet.py +++ b/torchvision/models/resnet.py @@ -491,6 +491,10 @@ class ResNeXt101_32X8D_Weights(WeightsEnum): DEFAULT = IMAGENET1K_V2 +class ResNeXt101_64X4D_Weights(WeightsEnum): + pass + + class Wide_ResNet50_2_Weights(WeightsEnum): IMAGENET1K_V1 = Weights( url="https://download.pytorch.org/models/wide_resnet50_2-95faca4d.pth", @@ -734,6 +738,34 @@ def resnext101_32x8d( return _resnet(Bottleneck, [3, 4, 23, 3], weights, progress, **kwargs) +def resnext101_64x4d( + *, weights: Optional[ResNeXt101_64X4D_Weights] = None, progress: bool = True, **kwargs: Any +) -> ResNet: + """ResNeXt-101 64x4d model from + `Aggregated Residual Transformation for Deep Neural Networks `_. + + Args: + weights (:class:`~torchvision.models.ResNeXt101_64X4D_Weights`, optional): The + pretrained weights to use. See + :class:`~torchvision.models.ResNeXt101_64X4D_Weights` below for + more details, and possible values. By default, no pre-trained + weights are used. + progress (bool, optional): If True, displays a progress bar of the + download to stderr. Default is True. + **kwargs: parameters passed to the ``torchvision.models.resnet.ResNet`` + base class. Please refer to the `source code + `_ + for more details about this class. + .. autoclass:: torchvision.models.ResNeXt101_64X4D_Weights + :members: + """ + weights = ResNeXt101_64X4D_Weights.verify(weights) + + _ovewrite_named_param(kwargs, "groups", 64) + _ovewrite_named_param(kwargs, "width_per_group", 4) + return _resnet(Bottleneck, [3, 4, 23, 3], weights, progress, **kwargs) + + @handle_legacy_interface(weights=("pretrained", Wide_ResNet50_2_Weights.IMAGENET1K_V1)) def wide_resnet50_2( *, weights: Optional[Wide_ResNet50_2_Weights] = None, progress: bool = True, **kwargs: Any From 7dbf5f667001aaf51ba6f21f178b49648b0e7a37 Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Mon, 25 Apr 2022 22:51:21 +0100 Subject: [PATCH 02/12] Add test for resnext101_64x4d --- .../ModelTester.test_resnext101_64x4d_expect.pkl | Bin 0 -> 939 bytes test/test_models.py | 1 + torchvision/models/resnet.py | 2 ++ 3 files changed, 3 insertions(+) create mode 100644 test/expect/ModelTester.test_resnext101_64x4d_expect.pkl diff --git a/test/expect/ModelTester.test_resnext101_64x4d_expect.pkl b/test/expect/ModelTester.test_resnext101_64x4d_expect.pkl new file mode 100644 index 0000000000000000000000000000000000000000..1a816e6d194048f8ac8cea9466c285427331ad71 GIT binary patch literal 939 zcmWIWW@cev;NW1u00Im`42ea_8JT6N`YDMeiFyUuIc`pT3{fbcfhoBpAE-(%zO*DW zr zf)S|3ppZF&8AvA=loqmh8ZvUemW=jY_4CYNO9=M{7L z7p0^YrKY%KCYNv(a%ct>a+VZw1r>7Z1$eV_Fj*X^nFTZrgadH;l#f9R#i#lPZcb`w z{zUOK5~ri(x3$mDuX|dKZ?^uh`k>7V0YU3&F(o#yIE?qMcHY0oW5Lfo9)=>epBK*C zT76RJo*maM_pp5Wxu>jq#U78w>$^JG=2!_eh1-1kFlUd* z^-!CQlQ--s@VBr!Alb2dU51g3W>4>)1JAGTGJ48v)9@gDcbp;eYzR1Ay-Hz#ul>i!MRpZGie3qz3t@Vp zVG!WW#-;;RB*&}^R}M2Ls$ literal 0 HcmV?d00001 diff --git a/test/test_models.py b/test/test_models.py index adbf7e2819e..717d7c3f04b 100644 --- a/test/test_models.py +++ b/test/test_models.py @@ -313,6 +313,7 @@ def _check_input_backprop(model, inputs): "convnext_base", "convnext_large", "resnext101_32x8d", + "resnext101_64x4d", "wide_resnet101_2", "efficientnet_b6", "efficientnet_b7", diff --git a/torchvision/models/resnet.py b/torchvision/models/resnet.py index 9c1c4ff774f..f3dc447efb6 100644 --- a/torchvision/models/resnet.py +++ b/torchvision/models/resnet.py @@ -21,6 +21,7 @@ "ResNet152_Weights", "ResNeXt50_32X4D_Weights", "ResNeXt101_32X8D_Weights", + "ResNeXt101_64X4D_Weights", "Wide_ResNet50_2_Weights", "Wide_ResNet101_2_Weights", "resnet18", @@ -30,6 +31,7 @@ "resnet152", "resnext50_32x4d", "resnext101_32x8d", + "resnext101_64x4d", "wide_resnet50_2", "wide_resnet101_2", ] From 4cfd9d1a882b8707c35543c9b2d90a2d4a33cd46 Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Tue, 3 May 2022 16:38:05 +0100 Subject: [PATCH 03/12] Add resnext101_64x4d weight --- torchvision/models/resnet.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/torchvision/models/resnet.py b/torchvision/models/resnet.py index f3dc447efb6..6a4606e474a 100644 --- a/torchvision/models/resnet.py +++ b/torchvision/models/resnet.py @@ -494,7 +494,21 @@ class ResNeXt101_32X8D_Weights(WeightsEnum): class ResNeXt101_64X4D_Weights(WeightsEnum): - pass + IMAGENET1K_V1 = Weights( + url="https://download.pytorch.org/models/resnext101_64x4d-c407fb41.pth", + transforms=partial(ImageClassification, crop_size=224, resize_size=232), + meta={ + **_COMMON_META, + "num_params": 83455272, + "recipe": "https://github.com/pytorch/vision/pull/5935", + "metrics": { + # Mock + "acc@1": 83.246, + "acc@5": 96.454, + }, + }, + ) + DEFAULT = IMAGENET1K_V1 class Wide_ResNet50_2_Weights(WeightsEnum): From 7df9b2ce384abca4fd344150496e09ba6412886a Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Tue, 3 May 2022 18:08:37 +0100 Subject: [PATCH 04/12] Update checkpoint to use EMA weigth --- torchvision/models/resnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/models/resnet.py b/torchvision/models/resnet.py index 6a4606e474a..cf6ca5c2f7b 100644 --- a/torchvision/models/resnet.py +++ b/torchvision/models/resnet.py @@ -495,7 +495,7 @@ class ResNeXt101_32X8D_Weights(WeightsEnum): class ResNeXt101_64X4D_Weights(WeightsEnum): IMAGENET1K_V1 = Weights( - url="https://download.pytorch.org/models/resnext101_64x4d-c407fb41.pth", + url="https://download.pytorch.org/models/resnext101_64x4d-173b62eb.pth", transforms=partial(ImageClassification, crop_size=224, resize_size=232), meta={ **_COMMON_META, From 54b4f633a2f6390994b77482254d07f21b07f292 Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Tue, 3 May 2022 18:04:51 +0000 Subject: [PATCH 05/12] Add quantization model signature for resnext101_64x4d --- torchvision/models/quantization/resnet.py | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/torchvision/models/quantization/resnet.py b/torchvision/models/quantization/resnet.py index 4c575adc0c9..8a9c7564aee 100644 --- a/torchvision/models/quantization/resnet.py +++ b/torchvision/models/quantization/resnet.py @@ -25,9 +25,11 @@ "ResNet18_QuantizedWeights", "ResNet50_QuantizedWeights", "ResNeXt101_32X8D_QuantizedWeights", + "ResNeXt101_64X4D_QuantizedWeights", "resnet18", "resnet50", "resnext101_32x8d", + "resnext101_64x4d", ] @@ -231,6 +233,25 @@ class ResNeXt101_32X8D_QuantizedWeights(WeightsEnum): DEFAULT = IMAGENET1K_FBGEMM_V2 +class ResNeXt101_32X8D_QuantizedWeights(WeightsEnum): + IMAGENET1K_FBGEMM_V1 = Weights( + # CHANGE + url="https://download.pytorch.org/models/quantized/resnext101_32x8_fbgemm-ee16d00c.pth", + transforms=partial(ImageClassification, crop_size=224, resize_size=232), + meta={ + **_COMMON_META, + "num_params": 83455272, + "unquantized": ResNeXt101_64X4D_Weights.IMAGENET1K_V1, + "metrics": { + # CHANGE + "acc@1": 82.574, + "acc@5": 96.132, + }, + }, + ) + DEFAULT = IMAGENET1K_FBGEMM_V2 + + @handle_legacy_interface( weights=( "pretrained", @@ -318,3 +339,26 @@ def resnext101_32x8d( _ovewrite_named_param(kwargs, "groups", 32) _ovewrite_named_param(kwargs, "width_per_group", 8) return _resnet(QuantizableBottleneck, [3, 4, 23, 3], weights, progress, quantize, **kwargs) + + +def resnext101_64x4d( + *, + weights: Optional[Union[ResNeXt101_64X4D_QuantizedWeights, ResNeXt101_64X4D_Weights]] = None, + progress: bool = True, + quantize: bool = False, + **kwargs: Any, +) -> QuantizableResNet: + r"""ResNeXt-101 64x4d model from + `"Aggregated Residual Transformation for Deep Neural Networks" `_ + + Args: + weights (ResNeXt101_64X4D_QuantizedWeights or ResNeXt101_64X4D_Weights, optional): The pretrained + weights for the model + progress (bool): If True, displays a progress bar of the download to stderr + quantize (bool): If True, return a quantized version of the model + """ + weights = (ResNeXt101_64X4D_QuantizedWeights if quantize else ResNeXt101_64X4D_Weights).verify(weights) + + _ovewrite_named_param(kwargs, "groups", 64) + _ovewrite_named_param(kwargs, "width_per_group", 4) + return _resnet(QuantizableBottleneck, [3, 4, 23, 3], weights, progress, quantize, **kwargs) From 411b7e2c167bfdc78967233f88adb4f0683ff5fe Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Tue, 3 May 2022 21:54:05 +0000 Subject: [PATCH 06/12] Fix class name and update accuracy using 1 gpu and batch_size=1 --- torchvision/models/quantization/resnet.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/torchvision/models/quantization/resnet.py b/torchvision/models/quantization/resnet.py index 8a9c7564aee..d5f8ebfcf10 100644 --- a/torchvision/models/quantization/resnet.py +++ b/torchvision/models/quantization/resnet.py @@ -11,6 +11,7 @@ ResNet18_Weights, ResNet50_Weights, ResNeXt101_32X8D_Weights, + ResNeXt101_64X4D_Weights, ) from ...transforms._presets import ImageClassification @@ -233,23 +234,21 @@ class ResNeXt101_32X8D_QuantizedWeights(WeightsEnum): DEFAULT = IMAGENET1K_FBGEMM_V2 -class ResNeXt101_32X8D_QuantizedWeights(WeightsEnum): +class ResNeXt101_64X4D_QuantizedWeights(WeightsEnum): IMAGENET1K_FBGEMM_V1 = Weights( - # CHANGE - url="https://download.pytorch.org/models/quantized/resnext101_32x8_fbgemm-ee16d00c.pth", + url="https://download.pytorch.org/models/quantized/resnext101_64x4d_fbgemm-4af4b262.pth", transforms=partial(ImageClassification, crop_size=224, resize_size=232), meta={ **_COMMON_META, "num_params": 83455272, "unquantized": ResNeXt101_64X4D_Weights.IMAGENET1K_V1, "metrics": { - # CHANGE - "acc@1": 82.574, - "acc@5": 96.132, + "acc@1": 82.832, + "acc@5": 96.344, }, }, ) - DEFAULT = IMAGENET1K_FBGEMM_V2 + DEFAULT = IMAGENET1K_FBGEMM_V1 @handle_legacy_interface( From c72ad6cbc80314e2af0f70093c2a08c1dbb6ed22 Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Tue, 3 May 2022 23:01:44 +0100 Subject: [PATCH 07/12] Apply ufmt --- torchvision/models/quantization/resnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/models/quantization/resnet.py b/torchvision/models/quantization/resnet.py index d5f8ebfcf10..3a6c90fc645 100644 --- a/torchvision/models/quantization/resnet.py +++ b/torchvision/models/quantization/resnet.py @@ -250,7 +250,7 @@ class ResNeXt101_64X4D_QuantizedWeights(WeightsEnum): ) DEFAULT = IMAGENET1K_FBGEMM_V1 - + @handle_legacy_interface( weights=( "pretrained", From 032015780886bacac09e77b221a92af797dae6dd Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Wed, 4 May 2022 09:36:33 +0000 Subject: [PATCH 08/12] Update the quantized weight and accuracy that we still keep the training log --- torchvision/models/quantization/resnet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torchvision/models/quantization/resnet.py b/torchvision/models/quantization/resnet.py index 3a6c90fc645..648138bc28d 100644 --- a/torchvision/models/quantization/resnet.py +++ b/torchvision/models/quantization/resnet.py @@ -236,15 +236,15 @@ class ResNeXt101_32X8D_QuantizedWeights(WeightsEnum): class ResNeXt101_64X4D_QuantizedWeights(WeightsEnum): IMAGENET1K_FBGEMM_V1 = Weights( - url="https://download.pytorch.org/models/quantized/resnext101_64x4d_fbgemm-4af4b262.pth", + url="https://download.pytorch.org/models/quantized/resnext101_64x4d_fbgemm-605a1cb3.pth", transforms=partial(ImageClassification, crop_size=224, resize_size=232), meta={ **_COMMON_META, "num_params": 83455272, "unquantized": ResNeXt101_64X4D_Weights.IMAGENET1K_V1, "metrics": { - "acc@1": 82.832, - "acc@5": 96.344, + "acc@1": 82.8982, + "acc@5": 96.326, }, }, ) From 87918b3cbeba510fc5f473b506383147581d23ec Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Wed, 4 May 2022 10:15:58 +0000 Subject: [PATCH 09/12] Add quantized expect file --- ...ModelTester.test_resnext101_64x4d_expect.pkl | Bin 939 -> 939 bytes ...r.test_resnext101_64x4d_quantized_expect.pkl | Bin 0 -> 747 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/expect/ModelTester.test_resnext101_64x4d_quantized_expect.pkl diff --git a/test/expect/ModelTester.test_resnext101_64x4d_expect.pkl b/test/expect/ModelTester.test_resnext101_64x4d_expect.pkl index 1a816e6d194048f8ac8cea9466c285427331ad71..baf3c135f166c71d6958ef7904dc55b6bccd64d8 100644 GIT binary patch delta 230 zcmV6tHC@}5fM9uTy#7H2{XO1L%+OQp!vL9 zF%&)Vp`N^6u(rJS8Rk51cJI6h*q^%e>Fv6&-2^?*s0%z+4#qq<*|I#h?SQ;KH?6y3 zb1OYqTC+T<_DVg_hnqcunDsk4l2yF=*Ezf^^7*`ui>SOnf!9&G$OfD`A%a&t1o51_ zSJzcMy_2xKAXGRy@EM4^=V&rKI*g6H#OK$#Y~=$y2;pbD$}md2f#CN%d`ek8?C>Ew g5Q6}_ZFjl6P)i30q(InalMn*X1f)RNW|QOs$Kefgm;e9( delta 230 zcmVFv6x-2^?qs0%zu4#qqs*|I#q?SQ;QH?6x) zb1OYgTC+Tn_DVgyhnqbZnDsj+l2yF8*Ezfd^7*`Wi>SOvf!9&Ghz6WG5`tGe^6;Fz z6xUTev6Ha8a8Ecoz!`|Uu4pnmDU6N0z~|SxGUWq2fZ%7lZZJx`XyEreVoF&(Jn$hq g*nP)i30BgMG?lMn*X1S7?`|C8hb$2ib*CjbBd diff --git a/test/expect/ModelTester.test_resnext101_64x4d_quantized_expect.pkl b/test/expect/ModelTester.test_resnext101_64x4d_quantized_expect.pkl new file mode 100644 index 0000000000000000000000000000000000000000..92b753e34c4fc868c707a9da2348691e552b6d92 GIT binary patch literal 747 zcmWIWW@cev;NW1u00Im`42ea_8JT6N`YDMeiFyUuIc`pT3{fbcfhoBpAE-(%zO*DW zr zf)S|3ppZF&8AvA=loqmhvz8RH26{7iGkUYO6|#A=dNZ~avUesY=jY_4CYNO9=M{7L z7p0^YrKY%KCYNv(a%ct>a+VZw1r>7Z1$eV_^toR=F$-uK2nXQwDIbFticj?o+?>?V z{E6aeB#!12X`2d%r#74Um+lem?cDR@I=3yz<|#9KPl*6+1!3Ga^E2qfZ7xeKDhB$< z%}JX`tHG`?<^tJvab9{T6VN6Q4)A6KQSdlL4g&#@1PVZpVRYTd{@_E=`3lHG)~#=V zt{2%={3v=;fKd(83-xz^HyfJ{RFNFBE?hY%F@OM!-VWh1Tmq#QAOPwEr7ea|u%{Uq TK*9mutZX1LW*`Kqho}Vr8m*n1 literal 0 HcmV?d00001 From 874855541b62b854d210c4885f3c95c5444f389e Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Wed, 4 May 2022 11:14:48 +0000 Subject: [PATCH 10/12] Update docs and fix acc1 --- docs/source/models.rst | 6 ++++++ torchvision/models/quantization/resnet.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/models.rst b/docs/source/models.rst index 919ab1d37e4..438f335ae0f 100644 --- a/docs/source/models.rst +++ b/docs/source/models.rst @@ -185,6 +185,7 @@ MobileNet V3 Large 74.042 91.340 MobileNet V3 Small 67.668 87.402 ResNeXt-50-32x4d 77.618 93.698 ResNeXt-101-32x8d 79.312 94.526 +ResNeXt-101-64x4d 83.246 96.454 Wide ResNet-50-2 78.468 94.086 Wide ResNet-101-2 78.848 94.284 MNASNet 1.0 73.456 91.510 @@ -366,6 +367,7 @@ ResNext resnext50_32x4d resnext101_32x8d + resnext101_64x4d Wide ResNet ----------- @@ -481,8 +483,11 @@ a model with random weights by calling its constructor: resnet18 = models.quantization.resnet18() resnet50 = models.quantization.resnet50() resnext101_32x8d = models.quantization.resnext101_32x8d() + resnext101_64x4d = models.quantization.resnext101_64x4d() shufflenet_v2_x0_5 = models.quantization.shufflenet_v2_x0_5() shufflenet_v2_x1_0 = models.quantization.shufflenet_v2_x1_0() + shufflenet_v2_x1_5 = models.quantization.shufflenet_v2_x1_5() + shufflenet_v2_x2_0 = models.quantization.shufflenet_v2_x2_0() Obtaining a pre-trained quantized model can be done with a few lines of code: @@ -508,6 +513,7 @@ ShuffleNet V2 x2.0 75.354 92.488 ResNet 18 69.494 88.882 ResNet 50 75.920 92.814 ResNext 101 32x8d 78.986 94.480 +ResNext 101 64x4d 82.898 96.326 Inception V3 77.176 93.354 GoogleNet 69.826 89.404 ================================ ============= ============= diff --git a/torchvision/models/quantization/resnet.py b/torchvision/models/quantization/resnet.py index 648138bc28d..e5c9e3afe17 100644 --- a/torchvision/models/quantization/resnet.py +++ b/torchvision/models/quantization/resnet.py @@ -243,7 +243,7 @@ class ResNeXt101_64X4D_QuantizedWeights(WeightsEnum): "num_params": 83455272, "unquantized": ResNeXt101_64X4D_Weights.IMAGENET1K_V1, "metrics": { - "acc@1": 82.8982, + "acc@1": 82.898, "acc@5": 96.326, }, }, From e70397cc0d32f1dffa3ca234f210912085f30ae2 Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Wed, 4 May 2022 13:05:37 +0100 Subject: [PATCH 11/12] Add recipe for quantized to PR --- torchvision/models/quantization/resnet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torchvision/models/quantization/resnet.py b/torchvision/models/quantization/resnet.py index e5c9e3afe17..23df64c86c0 100644 --- a/torchvision/models/quantization/resnet.py +++ b/torchvision/models/quantization/resnet.py @@ -241,6 +241,7 @@ class ResNeXt101_64X4D_QuantizedWeights(WeightsEnum): meta={ **_COMMON_META, "num_params": 83455272, + "recipe": "https://github.com/pytorch/vision/pull/5935", "unquantized": ResNeXt101_64X4D_Weights.IMAGENET1K_V1, "metrics": { "acc@1": 82.898, From 0300fe06386fdd6e4373d1e01f01787f3a62ce40 Mon Sep 17 00:00:00 2001 From: Yosua Michael Maranatha Date: Mon, 9 May 2022 10:16:16 +0100 Subject: [PATCH 12/12] Update models.rst --- docs/source/models.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/models.rst b/docs/source/models.rst index 438f335ae0f..91e0c4fa8cb 100644 --- a/docs/source/models.rst +++ b/docs/source/models.rst @@ -61,6 +61,8 @@ You can construct a model with random weights by calling its constructor: mobilenet_v3_large = models.mobilenet_v3_large() mobilenet_v3_small = models.mobilenet_v3_small() resnext50_32x4d = models.resnext50_32x4d() + resnext101_32x8d = models.resnext101_32x8d() + resnext101_64x4d = models.resnext101_64x4d() wide_resnet50_2 = models.wide_resnet50_2() mnasnet = models.mnasnet1_0() efficientnet_b0 = models.efficientnet_b0()