From e23d2084b40822452c284d26c11f2af1d8ece2a3 Mon Sep 17 00:00:00 2001 From: luminxu Date: Tue, 9 Nov 2021 15:25:30 +0800 Subject: [PATCH 1/4] fix typo in mobilenet_v3 --- mmpose/models/backbones/mobilenet_v3.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mmpose/models/backbones/mobilenet_v3.py b/mmpose/models/backbones/mobilenet_v3.py index f38aeb4d41..b434a12417 100644 --- a/mmpose/models/backbones/mobilenet_v3.py +++ b/mmpose/models/backbones/mobilenet_v3.py @@ -77,7 +77,7 @@ def __init__(self, super().__init__() assert arch in self.arch_settings for index in out_indices: - if index not in range(0, len(self.arch_settings[arch])): + if index not in range(-1, len(self.arch_settings[arch])): raise ValueError('the item in out_indices must in ' f'range(0, {len(self.arch_settings[arch])}). ' f'But received {index}') @@ -86,8 +86,6 @@ def __init__(self, raise ValueError('frozen_stages must be in range(-1, ' f'{len(self.arch_settings[arch])}). ' f'But received {frozen_stages}') - self.out_indices = out_indices - self.frozen_stages = frozen_stages self.arch = arch self.conv_cfg = conv_cfg self.norm_cfg = norm_cfg From 9c99389504d4569a1e2d100afbc79fd610671834 Mon Sep 17 00:00:00 2001 From: luminxu Date: Tue, 9 Nov 2021 15:35:46 +0800 Subject: [PATCH 2/4] fix typo in mobilenet_v3 --- mmpose/models/backbones/mobilenet_v3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmpose/models/backbones/mobilenet_v3.py b/mmpose/models/backbones/mobilenet_v3.py index b434a12417..b8925edc9a 100644 --- a/mmpose/models/backbones/mobilenet_v3.py +++ b/mmpose/models/backbones/mobilenet_v3.py @@ -23,7 +23,7 @@ class MobileNetV3(BaseBackbone): norm_cfg (dict): Config dict for normalization layer. Default: dict(type='BN'). out_indices (None or Sequence[int]): Output from which stages. - Default: (10, ), which means output tensors from final stage. + Default: (-1, ), which means output tensors from final stage. frozen_stages (int): Stages to be frozen (all param fixed). Default: -1, which means not freezing any parameters. norm_eval (bool): Whether to set norm layers to eval mode, namely, @@ -68,7 +68,7 @@ def __init__(self, arch='small', conv_cfg=None, norm_cfg=dict(type='BN'), - out_indices=(10, ), + out_indices=(-1, ), frozen_stages=-1, norm_eval=False, with_cp=False): From d6d83ebe70f62ce33c0e8b83d9970a7d5e7c093d Mon Sep 17 00:00:00 2001 From: luminxu Date: Tue, 9 Nov 2021 15:48:13 +0800 Subject: [PATCH 3/4] use -1 to indicate output tensors from final stage --- mmpose/models/backbones/mobilenet_v3.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mmpose/models/backbones/mobilenet_v3.py b/mmpose/models/backbones/mobilenet_v3.py index b8925edc9a..4da3c336e1 100644 --- a/mmpose/models/backbones/mobilenet_v3.py +++ b/mmpose/models/backbones/mobilenet_v3.py @@ -162,6 +162,8 @@ def forward(self, x): x = layer(x) if i in self.out_indices: outs.append(x) + elif i == (len(self.layers) - 1) and -1 in self.out_indices: + outs.append(x) if len(outs) == 1: return outs[0] From 6d186bcd57a7bbcc970f753b9be222de81686ecc Mon Sep 17 00:00:00 2001 From: luminxu Date: Wed, 10 Nov 2021 14:28:38 +0800 Subject: [PATCH 4/4] support negative out_indices --- mmpose/models/backbones/mobilenet_v3.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mmpose/models/backbones/mobilenet_v3.py b/mmpose/models/backbones/mobilenet_v3.py index 4da3c336e1..d640abec79 100644 --- a/mmpose/models/backbones/mobilenet_v3.py +++ b/mmpose/models/backbones/mobilenet_v3.py @@ -77,7 +77,8 @@ def __init__(self, super().__init__() assert arch in self.arch_settings for index in out_indices: - if index not in range(-1, len(self.arch_settings[arch])): + if index not in range(-len(self.arch_settings[arch]), + len(self.arch_settings[arch])): raise ValueError('the item in out_indices must in ' f'range(0, {len(self.arch_settings[arch])}). ' f'But received {index}') @@ -160,9 +161,8 @@ def forward(self, x): for i, layer_name in enumerate(self.layers): layer = getattr(self, layer_name) x = layer(x) - if i in self.out_indices: - outs.append(x) - elif i == (len(self.layers) - 1) and -1 in self.out_indices: + if i in self.out_indices or \ + i - len(self.layers) in self.out_indices: outs.append(x) if len(outs) == 1: