From 064e1f9fc580592fa607572873836975e8a4a984 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 03:31:54 +0800 Subject: [PATCH 01/17] add TIMMBackbone and unittests --- mmseg/models/backbones/__init__.py | 3 +- mmseg/models/backbones/timm_backbone.py | 63 ++++++ .../test_backbones/test_timm_backbone.py | 181 ++++++++++++++++++ 3 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 mmseg/models/backbones/timm_backbone.py create mode 100644 tests/test_models/test_backbones/test_timm_backbone.py diff --git a/mmseg/models/backbones/__init__.py b/mmseg/models/backbones/__init__.py index 6d320323b8..408d3981dd 100644 --- a/mmseg/models/backbones/__init__.py +++ b/mmseg/models/backbones/__init__.py @@ -12,6 +12,7 @@ from .resnet import ResNet, ResNetV1c, ResNetV1d from .resnext import ResNeXt from .swin import SwinTransformer +from .timm_backbone import TIMMBackbone from .unet import UNet from .vit import VisionTransformer @@ -19,5 +20,5 @@ 'ResNet', 'ResNetV1c', 'ResNetV1d', 'ResNeXt', 'HRNet', 'FastSCNN', 'ResNeSt', 'MobileNetV2', 'UNet', 'CGNet', 'MobileNetV3', 'VisionTransformer', 'SwinTransformer', 'MixVisionTransformer', - 'BiSeNetV1', 'BiSeNetV2', 'ICNet' + 'BiSeNetV1', 'BiSeNetV2', 'ICNet', 'TIMMBackbone' ] diff --git a/mmseg/models/backbones/timm_backbone.py b/mmseg/models/backbones/timm_backbone.py new file mode 100644 index 0000000000..01b29fc5ed --- /dev/null +++ b/mmseg/models/backbones/timm_backbone.py @@ -0,0 +1,63 @@ +# Copyright (c) OpenMMLab. All rights reserved. +try: + import timm +except ImportError: + timm = None + +from mmcv.cnn.bricks.registry import NORM_LAYERS +from mmcv.runner import BaseModule + +from ..builder import BACKBONES + + +@BACKBONES.register_module() +class TIMMBackbone(BaseModule): + """Wrapper to use backbones from timm library. More details can be found in + `timm `_ . + + Args: + model_name (str): Name of timm model to instantiate. + pretrained (bool): Load pretrained weights if True. + checkpoint_path (str): Path of checkpoint to load after + model is initialized. + in_channels (int): Number of input image channels. Default: 3. + init_cfg (dict, optional): Initialization config dict + **kwargs: Other timm & model specific arguments. + """ + + def __init__( + self, + model_name, + features_only=True, + pretrained=True, + checkpoint_path='', + in_channels=3, + init_cfg=None, + **kwargs, + ): + if timm is None: + raise RuntimeError('timm is not installed') + super(TIMMBackbone, self).__init__(init_cfg) + if 'norm_layer' in kwargs: + kwargs['norm_layer'] = NORM_LAYERS.get(kwargs['norm_layer']) + self.timm_model = timm.create_model( + model_name=model_name, + features_only=features_only, + pretrained=pretrained, + in_chans=in_channels, + checkpoint_path=checkpoint_path, + **kwargs, + ) + + # Make unused parameters None + self.timm_model.global_pool = None + self.timm_model.fc = None + self.timm_model.classifier = None + + # Hack to use pretrained weights from timm + if pretrained or checkpoint_path: + self._is_init = True + + def forward(self, x): + features = self.timm_model(x) + return features diff --git a/tests/test_models/test_backbones/test_timm_backbone.py b/tests/test_models/test_backbones/test_timm_backbone.py new file mode 100644 index 0000000000..8cfd752a89 --- /dev/null +++ b/tests/test_models/test_backbones/test_timm_backbone.py @@ -0,0 +1,181 @@ +# Copyright (c) OpenMMLab. All rights reserved. +import pytest +import torch + +from mmseg.models.backbones import TIMMBackbone +from .utils import check_norm_state + + +def test_timm_backbone(): + with pytest.raises(TypeError): + # pretrained must be a string path + model = TIMMBackbone() + model.init_weights(pretrained=0) + + # Test different norm_layer, can be: 'SyncBN', 'BN2d', 'GN', 'LN', 'IN' + # Test resnet18 from timm, norm_layer='BN2d' + model = TIMMBackbone( + model_name='resnet18', + features_only=True, + pretrained=False, + output_stride=32, + norm_layer='BN2d') + + # Test resnet18 from timm, norm_layer='SyncBN' + model = TIMMBackbone( + model_name='resnet18', + features_only=True, + pretrained=False, + output_stride=32, + norm_layer='SyncBN') + + # Test resnet18 from timm, features_only=True, output_stride=32 + model = TIMMBackbone( + model_name='resnet18', + features_only=True, + pretrained=False, + output_stride=32) + model.init_weights() + model.train() + assert check_norm_state(model.modules(), True) + + imgs = torch.randn(1, 3, 224, 224) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 64, 112, 112)) + assert feats[1] == torch.Size((1, 64, 56, 56)) + assert feats[2] == torch.Size((1, 128, 28, 28)) + assert feats[3] == torch.Size((1, 256, 14, 14)) + assert feats[4] == torch.Size((1, 512, 7, 7)) + + # Test resnet18 from timm, features_only=True, output_stride=16 + model = TIMMBackbone( + model_name='resnet18', + features_only=True, + pretrained=False, + output_stride=16) + imgs = torch.randn(1, 3, 224, 224) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 64, 112, 112)) + assert feats[1] == torch.Size((1, 64, 56, 56)) + assert feats[2] == torch.Size((1, 128, 28, 28)) + assert feats[3] == torch.Size((1, 256, 14, 14)) + assert feats[4] == torch.Size((1, 512, 14, 14)) + + # Test resnet18 from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnet18', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 224, 224) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 64, 112, 112)) + assert feats[1] == torch.Size((1, 64, 56, 56)) + assert feats[2] == torch.Size((1, 128, 28, 28)) + assert feats[3] == torch.Size((1, 256, 28, 28)) + assert feats[4] == torch.Size((1, 512, 28, 28)) + + # Test efficientnet_b1 with pretrained weights + model = TIMMBackbone(model_name='efficientnet_b1', pretrained=True) + + # Test resnetv2_50x1_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_50x1_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 32, 32) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 64, 16, 16)) + assert feats[1] == torch.Size((1, 256, 8, 8)) + assert feats[2] == torch.Size((1, 512, 4, 4)) + assert feats[3] == torch.Size((1, 1024, 4, 4)) + assert feats[4] == torch.Size((1, 2048, 4, 4)) + + # Test resnetv2_50x3_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_50x3_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 32, 32) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 192, 16, 16)) + assert feats[1] == torch.Size((1, 768, 8, 8)) + assert feats[2] == torch.Size((1, 1536, 4, 4)) + assert feats[3] == torch.Size((1, 3072, 4, 4)) + assert feats[4] == torch.Size((1, 6144, 4, 4)) + + # Test resnetv2_101x1_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_101x1_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 32, 32) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 64, 16, 16)) + assert feats[1] == torch.Size((1, 256, 8, 8)) + assert feats[2] == torch.Size((1, 512, 4, 4)) + assert feats[3] == torch.Size((1, 1024, 4, 4)) + assert feats[4] == torch.Size((1, 2048, 4, 4)) + + # Test resnetv2_101x3_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_101x3_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 32, 32) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 192, 16, 16)) + assert feats[1] == torch.Size((1, 768, 8, 8)) + assert feats[2] == torch.Size((1, 1536, 4, 4)) + assert feats[3] == torch.Size((1, 3072, 4, 4)) + assert feats[4] == torch.Size((1, 6144, 4, 4)) + + # Test resnetv2_152x2_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_152x2_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 32, 32) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 128, 16, 16)) + assert feats[1] == torch.Size((1, 512, 8, 8)) + assert feats[2] == torch.Size((1, 1024, 4, 4)) + assert feats[3] == torch.Size((1, 2048, 4, 4)) + assert feats[4] == torch.Size((1, 4096, 4, 4)) + + # Test resnetv2_152x4_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_152x4_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 32, 32) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 256, 16, 16)) + assert feats[1] == torch.Size((1, 1024, 8, 8)) + assert feats[2] == torch.Size((1, 2048, 4, 4)) + assert feats[3] == torch.Size((1, 4096, 4, 4)) + assert feats[4] == torch.Size((1, 8192, 4, 4)) From ec8ffae6a7664a4713b0339fab7a001763eebcef Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 03:46:16 +0800 Subject: [PATCH 02/17] add timm to tests requirements --- requirements/tests.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/tests.txt b/requirements/tests.txt index 991fd711d4..cc4c36c326 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -3,5 +3,6 @@ flake8 interrogate isort==4.3.21 pytest +timm xdoctest>=0.10.0 yapf From 57e398346aa7e1f047dd2240139792775b78ef56 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 04:18:01 +0800 Subject: [PATCH 03/17] deprecate pt1.3.1 --- .github/workflows/build.yml | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dbb08b48ed..cf7dc692db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,11 +27,8 @@ jobs: strategy: matrix: python-version: [3.7] - torch: [1.3.1, 1.5.1, 1.6.0, 1.7.0, 1.8.0, 1.9.0] + torch: [1.5.1, 1.6.0, 1.7.0, 1.8.0, 1.9.0] include: - - torch: 1.3.1 - torchvision: 0.4.2 - mmcv: "latest+torch1.3.0+cpu" - torch: 1.5.1 torchvision: 0.6.1 mmcv: "latest+torch1.5.0+cpu" @@ -83,19 +80,8 @@ jobs: strategy: matrix: python-version: [3.7] - torch: - [ - 1.3.1, - 1.5.1+cu101, - 1.6.0+cu101, - 1.7.0+cu101, - 1.8.0+cu101 - ] + torch: [1.5.1+cu101, 1.6.0+cu101, 1.7.0+cu101, 1.8.0+cu101] include: - - torch: 1.3.1 - torch_version: torch1.3.1 - torchvision: 0.4.2 - mmcv_link: "torch1.3.0" - torch: 1.5.1+cu101 torch_version: torch1.5.1 torchvision: 0.6.1+cu101 From 3fa7650dc816a4153a1fc659f0b72a4a7402c9e6 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 04:37:19 +0800 Subject: [PATCH 04/17] reduce the unittests input of timm backbone --- .../test_backbones/test_timm_backbone.py | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/test_models/test_backbones/test_timm_backbone.py b/tests/test_models/test_backbones/test_timm_backbone.py index 8cfd752a89..d549e36f85 100644 --- a/tests/test_models/test_backbones/test_timm_backbone.py +++ b/tests/test_models/test_backbones/test_timm_backbone.py @@ -106,15 +106,15 @@ def test_timm_backbone(): features_only=True, pretrained=False, output_stride=8) - imgs = torch.randn(1, 3, 32, 32) + imgs = torch.randn(1, 3, 16, 16) feats = model(imgs) feats = [feat.shape for feat in feats] assert len(feats) == 5 - assert feats[0] == torch.Size((1, 192, 16, 16)) - assert feats[1] == torch.Size((1, 768, 8, 8)) - assert feats[2] == torch.Size((1, 1536, 4, 4)) - assert feats[3] == torch.Size((1, 3072, 4, 4)) - assert feats[4] == torch.Size((1, 6144, 4, 4)) + assert feats[0] == torch.Size((1, 192, 8, 8)) + assert feats[1] == torch.Size((1, 768, 4, 4)) + assert feats[2] == torch.Size((1, 1536, 2, 2)) + assert feats[3] == torch.Size((1, 3072, 2, 2)) + assert feats[4] == torch.Size((1, 6144, 2, 2)) # Test resnetv2_101x1_bitm from timm, features_only=True, output_stride=8 model = TIMMBackbone( @@ -122,15 +122,15 @@ def test_timm_backbone(): features_only=True, pretrained=False, output_stride=8) - imgs = torch.randn(1, 3, 32, 32) + imgs = torch.randn(1, 3, 16, 16) feats = model(imgs) feats = [feat.shape for feat in feats] assert len(feats) == 5 - assert feats[0] == torch.Size((1, 64, 16, 16)) - assert feats[1] == torch.Size((1, 256, 8, 8)) - assert feats[2] == torch.Size((1, 512, 4, 4)) - assert feats[3] == torch.Size((1, 1024, 4, 4)) - assert feats[4] == torch.Size((1, 2048, 4, 4)) + assert feats[0] == torch.Size((1, 64, 8, 8)) + assert feats[1] == torch.Size((1, 256, 4, 4)) + assert feats[2] == torch.Size((1, 512, 2, 2)) + assert feats[3] == torch.Size((1, 1024, 2, 2)) + assert feats[4] == torch.Size((1, 2048, 2, 2)) # Test resnetv2_101x3_bitm from timm, features_only=True, output_stride=8 model = TIMMBackbone( @@ -138,15 +138,15 @@ def test_timm_backbone(): features_only=True, pretrained=False, output_stride=8) - imgs = torch.randn(1, 3, 32, 32) + imgs = torch.randn(1, 3, 16, 16) feats = model(imgs) feats = [feat.shape for feat in feats] assert len(feats) == 5 - assert feats[0] == torch.Size((1, 192, 16, 16)) - assert feats[1] == torch.Size((1, 768, 8, 8)) - assert feats[2] == torch.Size((1, 1536, 4, 4)) - assert feats[3] == torch.Size((1, 3072, 4, 4)) - assert feats[4] == torch.Size((1, 6144, 4, 4)) + assert feats[0] == torch.Size((1, 192, 8, 8)) + assert feats[1] == torch.Size((1, 768, 4, 4)) + assert feats[2] == torch.Size((1, 1536, 2, 2)) + assert feats[3] == torch.Size((1, 3072, 2, 2)) + assert feats[4] == torch.Size((1, 6144, 2, 2)) # Test resnetv2_152x2_bitm from timm, features_only=True, output_stride=8 model = TIMMBackbone( @@ -154,15 +154,15 @@ def test_timm_backbone(): features_only=True, pretrained=False, output_stride=8) - imgs = torch.randn(1, 3, 32, 32) + imgs = torch.randn(1, 3, 16, 16) feats = model(imgs) feats = [feat.shape for feat in feats] assert len(feats) == 5 - assert feats[0] == torch.Size((1, 128, 16, 16)) - assert feats[1] == torch.Size((1, 512, 8, 8)) - assert feats[2] == torch.Size((1, 1024, 4, 4)) - assert feats[3] == torch.Size((1, 2048, 4, 4)) - assert feats[4] == torch.Size((1, 4096, 4, 4)) + assert feats[0] == torch.Size((1, 128, 8, 8)) + assert feats[1] == torch.Size((1, 512, 4, 4)) + assert feats[2] == torch.Size((1, 1024, 2, 2)) + assert feats[3] == torch.Size((1, 2048, 2, 2)) + assert feats[4] == torch.Size((1, 4096, 2, 2)) # Test resnetv2_152x4_bitm from timm, features_only=True, output_stride=8 model = TIMMBackbone( @@ -170,12 +170,12 @@ def test_timm_backbone(): features_only=True, pretrained=False, output_stride=8) - imgs = torch.randn(1, 3, 32, 32) + imgs = torch.randn(1, 3, 16, 16) feats = model(imgs) feats = [feat.shape for feat in feats] assert len(feats) == 5 - assert feats[0] == torch.Size((1, 256, 16, 16)) - assert feats[1] == torch.Size((1, 1024, 8, 8)) - assert feats[2] == torch.Size((1, 2048, 4, 4)) - assert feats[3] == torch.Size((1, 4096, 4, 4)) - assert feats[4] == torch.Size((1, 8192, 4, 4)) + assert feats[0] == torch.Size((1, 256, 8, 8)) + assert feats[1] == torch.Size((1, 1024, 4, 4)) + assert feats[2] == torch.Size((1, 2048, 2, 2)) + assert feats[3] == torch.Size((1, 4096, 2, 2)) + assert feats[4] == torch.Size((1, 8192, 2, 2)) From 2a8503ccae19ddc4fbb40d88bcf8d1071b243c5b Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 04:55:58 +0800 Subject: [PATCH 05/17] fix ci --- .github/workflows/build.yml | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cf7dc692db..17a2c8840c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,8 +27,11 @@ jobs: strategy: matrix: python-version: [3.7] - torch: [1.5.1, 1.6.0, 1.7.0, 1.8.0, 1.9.0] + torch: [1.3.1, 1.5.1, 1.6.0, 1.7.0, 1.8.0, 1.9.0] include: + - torch: 1.3.1 + torchvision: 0.4.2 + mmcv: "latest+torch1.3.0+cpu" - torch: 1.5.1 torchvision: 0.6.1 mmcv: "latest+torch1.5.0+cpu" @@ -71,6 +74,13 @@ jobs: coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m + if: ${{matrix.torch >= '1.6.0'}} + - name: Run unittests and generate coverage report and skip timm unittests + run: | + coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py + coverage xml + coverage report -m + if: ${{matrix.torch < '1.6.0'}} build_cuda101: runs-on: ubuntu-18.04 @@ -80,8 +90,19 @@ jobs: strategy: matrix: python-version: [3.7] - torch: [1.5.1+cu101, 1.6.0+cu101, 1.7.0+cu101, 1.8.0+cu101] + torch: + [ + 1.3.1, + 1.5.1+cu101, + 1.6.0+cu101, + 1.7.0+cu101, + 1.8.0+cu101 + ] include: + - torch: 1.3.1 + torch_version: torch1.3.1 + torchvision: 0.4.2 + mmcv_link: "torch1.3.0" - torch: 1.5.1+cu101 torch_version: torch1.5.1 torchvision: 0.6.1+cu101 @@ -131,6 +152,13 @@ jobs: coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m + if: ${{matrix.torch >= '1.6.0'}} + - name: Run unittests and generate coverage report and skip timm unittests + run: | + coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py + coverage xml + coverage report -m + if: ${{matrix.torch < '1.6.0'}} - name: Upload coverage to Codecov uses: codecov/codecov-action@v1.0.10 with: From eeca97a9a310074aee5459218f710415c76763a4 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 05:08:16 +0800 Subject: [PATCH 06/17] fix ci --- .github/workflows/build.yml | 2 ++ requirements/tests.txt | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17a2c8840c..fe2db0027a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,6 +71,7 @@ jobs: run: rm -rf .eggs && pip install -e . - name: Run unittests and generate coverage report run: | + pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m @@ -149,6 +150,7 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | + pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m diff --git a/requirements/tests.txt b/requirements/tests.txt index cc4c36c326..991fd711d4 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -3,6 +3,5 @@ flake8 interrogate isort==4.3.21 pytest -timm xdoctest>=0.10.0 yapf From 831f6ef485e74608579da0c4da6d808f86171ce4 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 05:30:45 +0800 Subject: [PATCH 07/17] fix ci --- .github/workflows/build.yml | 14 ++++---------- requirements/tests.txt | 1 + 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe2db0027a..cc7a5e56d3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,16 +71,13 @@ jobs: run: rm -rf .eggs && pip install -e . - name: Run unittests and generate coverage report run: | - pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m if: ${{matrix.torch >= '1.6.0'}} - - name: Run unittests and generate coverage report and skip timm unittests + - name: Run unittests and skip timm unittests run: | - coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - coverage xml - coverage report -m + pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py if: ${{matrix.torch < '1.6.0'}} build_cuda101: @@ -150,16 +147,13 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | - pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m if: ${{matrix.torch >= '1.6.0'}} - - name: Run unittests and generate coverage report and skip timm unittests + - name: Run unittests and skip timm unittests run: | - coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - coverage xml - coverage report -m + pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py if: ${{matrix.torch < '1.6.0'}} - name: Upload coverage to Codecov uses: codecov/codecov-action@v1.0.10 diff --git a/requirements/tests.txt b/requirements/tests.txt index 991fd711d4..cc4c36c326 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -3,5 +3,6 @@ flake8 interrogate isort==4.3.21 pytest +timm xdoctest>=0.10.0 yapf From e4b2cb08451b97a2fc90fde1d958356cbd0c8ba0 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 05:56:10 +0800 Subject: [PATCH 08/17] fix ci --- .github/workflows/build.yml | 2 ++ requirements/tests.txt | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc7a5e56d3..b3e4248653 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,6 +71,7 @@ jobs: run: rm -rf .eggs && pip install -e . - name: Run unittests and generate coverage report run: | + pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m @@ -147,6 +148,7 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | + pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m diff --git a/requirements/tests.txt b/requirements/tests.txt index cc4c36c326..991fd711d4 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -3,6 +3,5 @@ flake8 interrogate isort==4.3.21 pytest -timm xdoctest>=0.10.0 yapf From f25eea57d4d64746bb0a60c94fbc59dad208a9c8 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 06:22:51 +0800 Subject: [PATCH 09/17] fix ci --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b3e4248653..99bc044106 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -210,6 +210,7 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | + pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m From b75c201f1d6d51894fd107776681007ef9d313a7 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 06:38:16 +0800 Subject: [PATCH 10/17] fix ci --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 99bc044106..e9b65599ab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -148,7 +148,7 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | - pip install timm + python -m pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m @@ -210,7 +210,7 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | - pip install timm + python -m pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m From bc7e80ed7f292f4b0b217293114f76f7602c03ac Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 06:39:57 +0800 Subject: [PATCH 11/17] fix ci --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9b65599ab..3e312a92fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,11 +75,11 @@ jobs: coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m - if: ${{matrix.torch >= '1.6.0'}} + if: ${{matrix.torch >= '1.5.0'}} - name: Run unittests and skip timm unittests run: | pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - if: ${{matrix.torch < '1.6.0'}} + if: ${{matrix.torch < '1.5.0'}} build_cuda101: runs-on: ubuntu-18.04 @@ -152,11 +152,11 @@ jobs: coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m - if: ${{matrix.torch >= '1.6.0'}} + if: ${{matrix.torch >= '1.5.0'}} - name: Run unittests and skip timm unittests run: | pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - if: ${{matrix.torch < '1.6.0'}} + if: ${{matrix.torch < '1.5.0'}} - name: Upload coverage to Codecov uses: codecov/codecov-action@v1.0.10 with: From c4cbe44d3ba3893de728927559040231b2f62e3f Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 07:00:24 +0800 Subject: [PATCH 12/17] fix ci --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3e312a92fd..68400e8d7c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -148,6 +148,7 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | + python -m pip install --upgrade pip python -m pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml From a09d9485a05e0053f2644ab97764ce871113e09d Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 07:18:44 +0800 Subject: [PATCH 13/17] fix ci --- .github/workflows/build.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68400e8d7c..e9b65599ab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,11 +75,11 @@ jobs: coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m - if: ${{matrix.torch >= '1.5.0'}} + if: ${{matrix.torch >= '1.6.0'}} - name: Run unittests and skip timm unittests run: | pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - if: ${{matrix.torch < '1.5.0'}} + if: ${{matrix.torch < '1.6.0'}} build_cuda101: runs-on: ubuntu-18.04 @@ -148,16 +148,15 @@ jobs: TORCH_CUDA_ARCH_LIST=7.0 pip install . - name: Run unittests and generate coverage report run: | - python -m pip install --upgrade pip python -m pip install timm coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m - if: ${{matrix.torch >= '1.5.0'}} + if: ${{matrix.torch >= '1.6.0'}} - name: Run unittests and skip timm unittests run: | pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - if: ${{matrix.torch < '1.5.0'}} + if: ${{matrix.torch < '1.6.0'}} - name: Upload coverage to Codecov uses: codecov/codecov-action@v1.0.10 with: From 68bf65f3e38af5ec4925dfe2403d9d7bbda8fe97 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 16:28:28 +0800 Subject: [PATCH 14/17] remove unittests of large models of timm backbone --- .github/workflows/build.yml | 8 +- model-index.yml | 74 ++++++++--------- .../test_backbones/test_timm_backbone.py | 80 ------------------- 3 files changed, 41 insertions(+), 121 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9b65599ab..3e312a92fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,11 +75,11 @@ jobs: coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m - if: ${{matrix.torch >= '1.6.0'}} + if: ${{matrix.torch >= '1.5.0'}} - name: Run unittests and skip timm unittests run: | pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - if: ${{matrix.torch < '1.6.0'}} + if: ${{matrix.torch < '1.5.0'}} build_cuda101: runs-on: ubuntu-18.04 @@ -152,11 +152,11 @@ jobs: coverage run --branch --source mmseg -m pytest tests/ coverage xml coverage report -m - if: ${{matrix.torch >= '1.6.0'}} + if: ${{matrix.torch >= '1.5.0'}} - name: Run unittests and skip timm unittests run: | pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py - if: ${{matrix.torch < '1.6.0'}} + if: ${{matrix.torch < '1.5.0'}} - name: Upload coverage to Codecov uses: codecov/codecov-action@v1.0.10 with: diff --git a/model-index.yml b/model-index.yml index 00da8d6a2a..d3ade7aebd 100644 --- a/model-index.yml +++ b/model-index.yml @@ -1,38 +1,38 @@ Import: -- configs/ann/ann.yml -- configs/apcnet/apcnet.yml -- configs/bisenetv1/bisenetv1.yml -- configs/bisenetv2/bisenetv2.yml -- configs/ccnet/ccnet.yml -- configs/cgnet/cgnet.yml -- configs/danet/danet.yml -- configs/deeplabv3/deeplabv3.yml -- configs/deeplabv3plus/deeplabv3plus.yml -- configs/dmnet/dmnet.yml -- configs/dnlnet/dnlnet.yml -- configs/dpt/dpt.yml -- configs/emanet/emanet.yml -- configs/encnet/encnet.yml -- configs/fastfcn/fastfcn.yml -- configs/fastscnn/fastscnn.yml -- configs/fcn/fcn.yml -- configs/fp16/fp16.yml -- configs/gcnet/gcnet.yml -- configs/hrnet/hrnet.yml -- configs/icnet/icnet.yml -- configs/isanet/isanet.yml -- configs/mobilenet_v2/mobilenet_v2.yml -- configs/mobilenet_v3/mobilenet_v3.yml -- configs/nonlocal_net/nonlocal_net.yml -- configs/ocrnet/ocrnet.yml -- configs/point_rend/point_rend.yml -- configs/psanet/psanet.yml -- configs/pspnet/pspnet.yml -- configs/resnest/resnest.yml -- configs/segformer/segformer.yml -- configs/sem_fpn/sem_fpn.yml -- configs/setr/setr.yml -- configs/swin/swin.yml -- configs/unet/unet.yml -- configs/upernet/upernet.yml -- configs/vit/vit.yml +- configs\ann\ann.yml +- configs\apcnet\apcnet.yml +- configs\bisenetv1\bisenetv1.yml +- configs\bisenetv2\bisenetv2.yml +- configs\ccnet\ccnet.yml +- configs\cgnet\cgnet.yml +- configs\danet\danet.yml +- configs\deeplabv3\deeplabv3.yml +- configs\deeplabv3plus\deeplabv3plus.yml +- configs\dmnet\dmnet.yml +- configs\dnlnet\dnlnet.yml +- configs\dpt\dpt.yml +- configs\emanet\emanet.yml +- configs\encnet\encnet.yml +- configs\fastfcn\fastfcn.yml +- configs\fastscnn\fastscnn.yml +- configs\fcn\fcn.yml +- configs\fp16\fp16.yml +- configs\gcnet\gcnet.yml +- configs\hrnet\hrnet.yml +- configs\icnet\icnet.yml +- configs\isanet\isanet.yml +- configs\mobilenet_v2\mobilenet_v2.yml +- configs\mobilenet_v3\mobilenet_v3.yml +- configs\nonlocal_net\nonlocal_net.yml +- configs\ocrnet\ocrnet.yml +- configs\point_rend\point_rend.yml +- configs\psanet\psanet.yml +- configs\pspnet\pspnet.yml +- configs\resnest\resnest.yml +- configs\segformer\segformer.yml +- configs\sem_fpn\sem_fpn.yml +- configs\setr\setr.yml +- configs\swin\swin.yml +- configs\unet\unet.yml +- configs\upernet\upernet.yml +- configs\vit\vit.yml diff --git a/tests/test_models/test_backbones/test_timm_backbone.py b/tests/test_models/test_backbones/test_timm_backbone.py index d549e36f85..fe79d01a1f 100644 --- a/tests/test_models/test_backbones/test_timm_backbone.py +++ b/tests/test_models/test_backbones/test_timm_backbone.py @@ -99,83 +99,3 @@ def test_timm_backbone(): assert feats[2] == torch.Size((1, 512, 4, 4)) assert feats[3] == torch.Size((1, 1024, 4, 4)) assert feats[4] == torch.Size((1, 2048, 4, 4)) - - # Test resnetv2_50x3_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_50x3_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 16, 16) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 192, 8, 8)) - assert feats[1] == torch.Size((1, 768, 4, 4)) - assert feats[2] == torch.Size((1, 1536, 2, 2)) - assert feats[3] == torch.Size((1, 3072, 2, 2)) - assert feats[4] == torch.Size((1, 6144, 2, 2)) - - # Test resnetv2_101x1_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_101x1_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 16, 16) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 64, 8, 8)) - assert feats[1] == torch.Size((1, 256, 4, 4)) - assert feats[2] == torch.Size((1, 512, 2, 2)) - assert feats[3] == torch.Size((1, 1024, 2, 2)) - assert feats[4] == torch.Size((1, 2048, 2, 2)) - - # Test resnetv2_101x3_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_101x3_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 16, 16) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 192, 8, 8)) - assert feats[1] == torch.Size((1, 768, 4, 4)) - assert feats[2] == torch.Size((1, 1536, 2, 2)) - assert feats[3] == torch.Size((1, 3072, 2, 2)) - assert feats[4] == torch.Size((1, 6144, 2, 2)) - - # Test resnetv2_152x2_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_152x2_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 16, 16) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 128, 8, 8)) - assert feats[1] == torch.Size((1, 512, 4, 4)) - assert feats[2] == torch.Size((1, 1024, 2, 2)) - assert feats[3] == torch.Size((1, 2048, 2, 2)) - assert feats[4] == torch.Size((1, 4096, 2, 2)) - - # Test resnetv2_152x4_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_152x4_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 16, 16) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 256, 8, 8)) - assert feats[1] == torch.Size((1, 1024, 4, 4)) - assert feats[2] == torch.Size((1, 2048, 2, 2)) - assert feats[3] == torch.Size((1, 4096, 2, 2)) - assert feats[4] == torch.Size((1, 8192, 2, 2)) From 5eced882357ff19aed491570e575f3c93da65302 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 17:15:12 +0800 Subject: [PATCH 15/17] generate coverage report for all unittests env --- .github/workflows/build.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3e312a92fd..f41e4176cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -76,9 +76,11 @@ jobs: coverage xml coverage report -m if: ${{matrix.torch >= '1.5.0'}} - - name: Run unittests and skip timm unittests + - name: Skip timm unittests and generate coverage report run: | - pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py + coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py + coverage xml + coverage report -m if: ${{matrix.torch < '1.5.0'}} build_cuda101: @@ -153,9 +155,11 @@ jobs: coverage xml coverage report -m if: ${{matrix.torch >= '1.5.0'}} - - name: Run unittests and skip timm unittests + - name: Skip timm unittests and generate coverage report run: | - pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py + coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py + coverage xml + coverage report -m if: ${{matrix.torch < '1.5.0'}} - name: Upload coverage to Codecov uses: codecov/codecov-action@v1.0.10 From 500f22e9866b401afb97c35dce2a1f4b44e8b3c1 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 21:46:53 +0800 Subject: [PATCH 16/17] reduce the unittests input of timm backbone --- model-index.yml | 74 +++++++-------- .../test_backbones/test_timm_backbone.py | 92 +++++++++++++++++-- 2 files changed, 123 insertions(+), 43 deletions(-) diff --git a/model-index.yml b/model-index.yml index d3ade7aebd..00da8d6a2a 100644 --- a/model-index.yml +++ b/model-index.yml @@ -1,38 +1,38 @@ Import: -- configs\ann\ann.yml -- configs\apcnet\apcnet.yml -- configs\bisenetv1\bisenetv1.yml -- configs\bisenetv2\bisenetv2.yml -- configs\ccnet\ccnet.yml -- configs\cgnet\cgnet.yml -- configs\danet\danet.yml -- configs\deeplabv3\deeplabv3.yml -- configs\deeplabv3plus\deeplabv3plus.yml -- configs\dmnet\dmnet.yml -- configs\dnlnet\dnlnet.yml -- configs\dpt\dpt.yml -- configs\emanet\emanet.yml -- configs\encnet\encnet.yml -- configs\fastfcn\fastfcn.yml -- configs\fastscnn\fastscnn.yml -- configs\fcn\fcn.yml -- configs\fp16\fp16.yml -- configs\gcnet\gcnet.yml -- configs\hrnet\hrnet.yml -- configs\icnet\icnet.yml -- configs\isanet\isanet.yml -- configs\mobilenet_v2\mobilenet_v2.yml -- configs\mobilenet_v3\mobilenet_v3.yml -- configs\nonlocal_net\nonlocal_net.yml -- configs\ocrnet\ocrnet.yml -- configs\point_rend\point_rend.yml -- configs\psanet\psanet.yml -- configs\pspnet\pspnet.yml -- configs\resnest\resnest.yml -- configs\segformer\segformer.yml -- configs\sem_fpn\sem_fpn.yml -- configs\setr\setr.yml -- configs\swin\swin.yml -- configs\unet\unet.yml -- configs\upernet\upernet.yml -- configs\vit\vit.yml +- configs/ann/ann.yml +- configs/apcnet/apcnet.yml +- configs/bisenetv1/bisenetv1.yml +- configs/bisenetv2/bisenetv2.yml +- configs/ccnet/ccnet.yml +- configs/cgnet/cgnet.yml +- configs/danet/danet.yml +- configs/deeplabv3/deeplabv3.yml +- configs/deeplabv3plus/deeplabv3plus.yml +- configs/dmnet/dmnet.yml +- configs/dnlnet/dnlnet.yml +- configs/dpt/dpt.yml +- configs/emanet/emanet.yml +- configs/encnet/encnet.yml +- configs/fastfcn/fastfcn.yml +- configs/fastscnn/fastscnn.yml +- configs/fcn/fcn.yml +- configs/fp16/fp16.yml +- configs/gcnet/gcnet.yml +- configs/hrnet/hrnet.yml +- configs/icnet/icnet.yml +- configs/isanet/isanet.yml +- configs/mobilenet_v2/mobilenet_v2.yml +- configs/mobilenet_v3/mobilenet_v3.yml +- configs/nonlocal_net/nonlocal_net.yml +- configs/ocrnet/ocrnet.yml +- configs/point_rend/point_rend.yml +- configs/psanet/psanet.yml +- configs/pspnet/pspnet.yml +- configs/resnest/resnest.yml +- configs/segformer/segformer.yml +- configs/sem_fpn/sem_fpn.yml +- configs/setr/setr.yml +- configs/swin/swin.yml +- configs/unet/unet.yml +- configs/upernet/upernet.yml +- configs/vit/vit.yml diff --git a/tests/test_models/test_backbones/test_timm_backbone.py b/tests/test_models/test_backbones/test_timm_backbone.py index fe79d01a1f..2efd9be0a0 100644 --- a/tests/test_models/test_backbones/test_timm_backbone.py +++ b/tests/test_models/test_backbones/test_timm_backbone.py @@ -90,12 +90,92 @@ def test_timm_backbone(): features_only=True, pretrained=False, output_stride=8) - imgs = torch.randn(1, 3, 32, 32) + imgs = torch.randn(1, 3, 8, 8) feats = model(imgs) feats = [feat.shape for feat in feats] assert len(feats) == 5 - assert feats[0] == torch.Size((1, 64, 16, 16)) - assert feats[1] == torch.Size((1, 256, 8, 8)) - assert feats[2] == torch.Size((1, 512, 4, 4)) - assert feats[3] == torch.Size((1, 1024, 4, 4)) - assert feats[4] == torch.Size((1, 2048, 4, 4)) + assert feats[0] == torch.Size((1, 64, 4, 4)) + assert feats[1] == torch.Size((1, 256, 2, 2)) + assert feats[2] == torch.Size((1, 512, 1, 1)) + assert feats[3] == torch.Size((1, 1024, 1, 1)) + assert feats[4] == torch.Size((1, 2048, 1, 1)) + + # Test resnetv2_50x3_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_50x3_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 8, 8) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 192, 4, 4)) + assert feats[1] == torch.Size((1, 768, 2, 2)) + assert feats[2] == torch.Size((1, 1536, 1, 1)) + assert feats[3] == torch.Size((1, 3072, 1, 1)) + assert feats[4] == torch.Size((1, 6144, 1, 1)) + + # Test resnetv2_101x1_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_101x1_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 8, 8) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 64, 4, 4)) + assert feats[1] == torch.Size((1, 256, 2, 2)) + assert feats[2] == torch.Size((1, 512, 1, 1)) + assert feats[3] == torch.Size((1, 1024, 1, 1)) + assert feats[4] == torch.Size((1, 2048, 1, 1)) + + # Test resnetv2_101x3_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_101x3_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 8, 8) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 192, 4, 4)) + assert feats[1] == torch.Size((1, 768, 2, 2)) + assert feats[2] == torch.Size((1, 1536, 1, 1)) + assert feats[3] == torch.Size((1, 3072, 1, 1)) + assert feats[4] == torch.Size((1, 6144, 1, 1)) + + # Test resnetv2_152x2_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_152x2_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 8, 8) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 128, 4, 4)) + assert feats[1] == torch.Size((1, 512, 2, 2)) + assert feats[2] == torch.Size((1, 1024, 1, 1)) + assert feats[3] == torch.Size((1, 2048, 1, 1)) + assert feats[4] == torch.Size((1, 4096, 1, 1)) + + # Test resnetv2_152x4_bitm from timm, features_only=True, output_stride=8 + model = TIMMBackbone( + model_name='resnetv2_152x4_bitm', + features_only=True, + pretrained=False, + output_stride=8) + imgs = torch.randn(1, 3, 8, 8) + feats = model(imgs) + feats = [feat.shape for feat in feats] + assert len(feats) == 5 + assert feats[0] == torch.Size((1, 256, 4, 4)) + assert feats[1] == torch.Size((1, 1024, 2, 2)) + assert feats[2] == torch.Size((1, 2048, 1, 1)) + assert feats[3] == torch.Size((1, 4096, 1, 1)) + assert feats[4] == torch.Size((1, 8192, 1, 1)) From 0db1bd126235bd3d7396ea7f5f1ec518b50fb830 Mon Sep 17 00:00:00 2001 From: Junjun2016 Date: Wed, 27 Oct 2021 23:02:12 +0800 Subject: [PATCH 17/17] reduce the unittests input of timm backbone --- .../test_backbones/test_timm_backbone.py | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/tests/test_models/test_backbones/test_timm_backbone.py b/tests/test_models/test_backbones/test_timm_backbone.py index 2efd9be0a0..85ef9aa56f 100644 --- a/tests/test_models/test_backbones/test_timm_backbone.py +++ b/tests/test_models/test_backbones/test_timm_backbone.py @@ -131,51 +131,3 @@ def test_timm_backbone(): assert feats[2] == torch.Size((1, 512, 1, 1)) assert feats[3] == torch.Size((1, 1024, 1, 1)) assert feats[4] == torch.Size((1, 2048, 1, 1)) - - # Test resnetv2_101x3_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_101x3_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 8, 8) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 192, 4, 4)) - assert feats[1] == torch.Size((1, 768, 2, 2)) - assert feats[2] == torch.Size((1, 1536, 1, 1)) - assert feats[3] == torch.Size((1, 3072, 1, 1)) - assert feats[4] == torch.Size((1, 6144, 1, 1)) - - # Test resnetv2_152x2_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_152x2_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 8, 8) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 128, 4, 4)) - assert feats[1] == torch.Size((1, 512, 2, 2)) - assert feats[2] == torch.Size((1, 1024, 1, 1)) - assert feats[3] == torch.Size((1, 2048, 1, 1)) - assert feats[4] == torch.Size((1, 4096, 1, 1)) - - # Test resnetv2_152x4_bitm from timm, features_only=True, output_stride=8 - model = TIMMBackbone( - model_name='resnetv2_152x4_bitm', - features_only=True, - pretrained=False, - output_stride=8) - imgs = torch.randn(1, 3, 8, 8) - feats = model(imgs) - feats = [feat.shape for feat in feats] - assert len(feats) == 5 - assert feats[0] == torch.Size((1, 256, 4, 4)) - assert feats[1] == torch.Size((1, 1024, 2, 2)) - assert feats[2] == torch.Size((1, 2048, 1, 1)) - assert feats[3] == torch.Size((1, 4096, 1, 1)) - assert feats[4] == torch.Size((1, 8192, 1, 1))