|
1 | | -_base_ = ['../../../_base_/default_runtime.py'] |
| 1 | +# Copyright (c) OpenMMLab. All rights reserved. |
| 2 | +from mmengine.config import read_base |
| 3 | + |
| 4 | +with read_base(): |
| 5 | + from mmpose.configs._base_.default_runtime import * # noqa |
| 6 | + |
| 7 | +from mmcv.transforms import RandomChoice, RandomChoiceResize |
| 8 | +from mmengine.dataset import DefaultSampler |
| 9 | +from mmengine.model import PretrainedInit |
| 10 | +from mmengine.optim import LinearLR, MultiStepLR |
| 11 | +from torch.nn import GroupNorm |
| 12 | +from torch.optim import Adam |
| 13 | + |
| 14 | +from mmpose.codecs import EDPoseLabel |
| 15 | +from mmpose.datasets import (BottomupRandomChoiceResize, BottomupRandomCrop, |
| 16 | + CocoDataset, LoadImage, PackPoseInputs, |
| 17 | + RandomFlip) |
| 18 | +from mmpose.evaluation import CocoMetric |
| 19 | +from mmpose.models import (BottomupPoseEstimator, ChannelMapper, EDPoseHead, |
| 20 | + PoseDataPreprocessor, ResNet) |
| 21 | +from mmpose.models.utils import FrozenBatchNorm2d |
2 | 22 |
|
3 | 23 | # runtime |
4 | | -train_cfg = dict(max_epochs=50, val_interval=10) |
| 24 | +train_cfg.update(max_epochs=50, val_interval=10) # noqa |
5 | 25 |
|
6 | 26 | # optimizer |
7 | 27 | optim_wrapper = dict(optimizer=dict( |
8 | | - type='Adam', |
| 28 | + type=Adam, |
9 | 29 | lr=1e-3, |
10 | 30 | )) |
11 | 31 |
|
12 | 32 | # learning policy |
13 | 33 | param_scheduler = [ |
| 34 | + dict(type=LinearLR, begin=0, end=500, start_factor=0.001, |
| 35 | + by_epoch=False), # warm-up |
14 | 36 | dict( |
15 | | - type='LinearLR', begin=0, end=500, start_factor=0.001, |
16 | | - by_epoch=False), # warm-up |
17 | | - dict( |
18 | | - type='MultiStepLR', |
| 37 | + type=MultiStepLR, |
19 | 38 | begin=0, |
20 | 39 | end=140, |
21 | 40 | milestones=[33, 45], |
|
27 | 46 | auto_scale_lr = dict(base_batch_size=80) |
28 | 47 |
|
29 | 48 | # hooks |
30 | | -default_hooks = dict(checkpoint=dict(save_best='coco/AP', rule='greater')) |
| 49 | +default_hooks.update( # noqa |
| 50 | + checkpoint=dict(save_best='coco/AP', rule='greater')) |
31 | 51 |
|
32 | 52 | # codec settings |
33 | | -codec = dict(type='EDPoseLabel', num_select=50, num_keypoints=17) |
| 53 | +codec = dict(type=EDPoseLabel, num_select=50, num_keypoints=17) |
34 | 54 |
|
35 | 55 | # model settings |
36 | 56 | model = dict( |
37 | | - type='BottomupPoseEstimator', |
| 57 | + type=BottomupPoseEstimator, |
38 | 58 | data_preprocessor=dict( |
39 | | - type='PoseDataPreprocessor', |
| 59 | + type=PoseDataPreprocessor, |
40 | 60 | mean=[123.675, 116.28, 103.53], |
41 | 61 | std=[58.395, 57.12, 57.375], |
42 | 62 | bgr_to_rgb=True, |
43 | 63 | pad_size_divisor=1), |
44 | 64 | backbone=dict( |
45 | | - type='ResNet', |
| 65 | + type=ResNet, |
46 | 66 | depth=50, |
47 | 67 | num_stages=4, |
48 | 68 | out_indices=(1, 2, 3), |
49 | 69 | frozen_stages=1, |
50 | | - norm_cfg=dict(type='FrozenBatchNorm2d', requires_grad=False), |
| 70 | + norm_cfg=dict(type=FrozenBatchNorm2d, requires_grad=False), |
51 | 71 | norm_eval=True, |
52 | 72 | style='pytorch', |
53 | | - init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')), |
| 73 | + init_cfg=dict( |
| 74 | + type=PretrainedInit, checkpoint='torchvision://resnet50')), |
54 | 75 | neck=dict( |
55 | | - type='ChannelMapper', |
| 76 | + type=ChannelMapper, |
56 | 77 | in_channels=[512, 1024, 2048], |
57 | 78 | kernel_size=1, |
58 | 79 | out_channels=256, |
59 | 80 | act_cfg=None, |
60 | | - norm_cfg=dict(type='GN', num_groups=32), |
| 81 | + norm_cfg=dict(type=GroupNorm, num_groups=32), |
61 | 82 | num_outs=4), |
62 | 83 | head=dict( |
63 | | - type='EDPoseHead', |
| 84 | + type=EDPoseHead, |
64 | 85 | num_queries=900, |
65 | 86 | num_feature_levels=4, |
66 | 87 | num_keypoints=17, |
|
117 | 138 | find_unused_parameters = True |
118 | 139 |
|
119 | 140 | # base dataset settings |
120 | | -dataset_type = 'CocoDataset' |
| 141 | +dataset_type = CocoDataset |
121 | 142 | data_mode = 'bottomup' |
122 | 143 | data_root = 'data/coco/' |
123 | 144 |
|
124 | 145 | # pipelines |
125 | 146 | train_pipeline = [ |
126 | | - dict(type='LoadImage'), |
127 | | - dict(type='RandomFlip', direction='horizontal'), |
| 147 | + dict(type=LoadImage), |
| 148 | + dict(type=RandomFlip, direction='horizontal'), |
128 | 149 | dict( |
129 | | - type='RandomChoice', |
| 150 | + type=RandomChoice, |
130 | 151 | transforms=[ |
131 | 152 | [ |
132 | 153 | dict( |
133 | | - type='RandomChoiceResize', |
| 154 | + type=RandomChoiceResize, |
134 | 155 | scales=[(480, 1333), (512, 1333), (544, 1333), (576, 1333), |
135 | 156 | (608, 1333), (640, 1333), (672, 1333), (704, 1333), |
136 | 157 | (736, 1333), (768, 1333), (800, 1333)], |
137 | 158 | keep_ratio=True) |
138 | 159 | ], |
139 | 160 | [ |
140 | 161 | dict( |
141 | | - type='BottomupRandomChoiceResize', |
| 162 | + type=BottomupRandomChoiceResize, |
142 | 163 | # The radio of all image in train dataset < 7 |
143 | 164 | # follow the original implement |
144 | 165 | scales=[(400, 4200), (500, 4200), (600, 4200)], |
145 | 166 | keep_ratio=True), |
146 | 167 | dict( |
147 | | - type='BottomupRandomCrop', |
| 168 | + type=BottomupRandomCrop, |
148 | 169 | crop_type='absolute_range', |
149 | 170 | crop_size=(384, 600), |
150 | 171 | allow_negative_crop=True), |
151 | 172 | dict( |
152 | | - type='BottomupRandomChoiceResize', |
| 173 | + type=BottomupRandomChoiceResize, |
153 | 174 | scales=[(480, 1333), (512, 1333), (544, 1333), (576, 1333), |
154 | 175 | (608, 1333), (640, 1333), (672, 1333), (704, 1333), |
155 | 176 | (736, 1333), (768, 1333), (800, 1333)], |
156 | 177 | keep_ratio=True) |
157 | 178 | ] |
158 | 179 | ]), |
159 | | - dict(type='PackPoseInputs'), |
| 180 | + dict(type=PackPoseInputs), |
160 | 181 | ] |
161 | 182 |
|
162 | 183 | val_pipeline = [ |
163 | | - dict(type='LoadImage'), |
| 184 | + dict(type=LoadImage), |
164 | 185 | dict( |
165 | | - type='BottomupRandomChoiceResize', |
| 186 | + type=BottomupRandomChoiceResize, |
166 | 187 | scales=[(800, 1333)], |
167 | 188 | keep_ratio=True, |
168 | 189 | backend='pillow'), |
169 | 190 | dict( |
170 | | - type='PackPoseInputs', |
| 191 | + type=PackPoseInputs, |
171 | 192 | meta_keys=('id', 'img_id', 'img_path', 'crowd_index', 'ori_shape', |
172 | 193 | 'img_shape', 'input_size', 'input_center', 'input_scale', |
173 | 194 | 'flip', 'flip_direction', 'flip_indices', 'raw_ann_info', |
|
179 | 200 | batch_size=1, |
180 | 201 | num_workers=1, |
181 | 202 | persistent_workers=True, |
182 | | - sampler=dict(type='DefaultSampler', shuffle=False), |
| 203 | + sampler=dict(type=DefaultSampler, shuffle=False), |
183 | 204 | dataset=dict( |
184 | 205 | type=dataset_type, |
185 | 206 | data_root=data_root, |
|
194 | 215 | num_workers=8, |
195 | 216 | persistent_workers=True, |
196 | 217 | drop_last=False, |
197 | | - sampler=dict(type='DefaultSampler', shuffle=False, round_up=False), |
| 218 | + sampler=dict(type=DefaultSampler, shuffle=False, round_up=False), |
198 | 219 | dataset=dict( |
199 | 220 | type=dataset_type, |
200 | 221 | data_root=data_root, |
|
208 | 229 |
|
209 | 230 | # evaluators |
210 | 231 | val_evaluator = dict( |
211 | | - type='CocoMetric', |
212 | | - ann_file=data_root + 'annotations/person_keypoints_val2017.json', |
| 232 | + type=CocoMetric, |
213 | 233 | nms_mode='none', |
214 | 234 | score_mode='keypoint', |
215 | 235 | ) |
|
0 commit comments