rtmpose-m_8xb64-120e_lapa-256x256.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. _base_ = ['../../../_base_/default_runtime.py']
  2. # runtime
  3. max_epochs = 120
  4. stage2_num_epochs = 10
  5. base_lr = 4e-3
  6. train_cfg = dict(max_epochs=max_epochs, val_interval=1)
  7. randomness = dict(seed=21)
  8. # optimizer
  9. optim_wrapper = dict(
  10. type='OptimWrapper',
  11. optimizer=dict(type='AdamW', lr=base_lr, weight_decay=0.05),
  12. paramwise_cfg=dict(
  13. norm_decay_mult=0, bias_decay_mult=0, bypass_duplicate=True))
  14. # learning rate
  15. param_scheduler = [
  16. dict(
  17. type='LinearLR',
  18. start_factor=1.0e-5,
  19. by_epoch=False,
  20. begin=0,
  21. end=1000),
  22. dict(
  23. # use cosine lr from 150 to 300 epoch
  24. type='CosineAnnealingLR',
  25. eta_min=base_lr * 0.05,
  26. begin=max_epochs // 2,
  27. end=max_epochs,
  28. T_max=max_epochs // 2,
  29. by_epoch=True,
  30. convert_to_iter_based=True),
  31. ]
  32. # automatically scaling LR based on the actual training batch size
  33. auto_scale_lr = dict(base_batch_size=512)
  34. # codec settings
  35. codec = dict(
  36. type='SimCCLabel',
  37. input_size=(256, 256),
  38. sigma=(5.66, 5.66),
  39. simcc_split_ratio=2.0,
  40. normalize=False,
  41. use_dark=False)
  42. # model settings
  43. model = dict(
  44. type='TopdownPoseEstimator',
  45. data_preprocessor=dict(
  46. type='PoseDataPreprocessor',
  47. mean=[123.675, 116.28, 103.53],
  48. std=[58.395, 57.12, 57.375],
  49. bgr_to_rgb=True),
  50. backbone=dict(
  51. _scope_='mmdet',
  52. type='CSPNeXt',
  53. arch='P5',
  54. expand_ratio=0.5,
  55. deepen_factor=0.67,
  56. widen_factor=0.75,
  57. out_indices=(4, ),
  58. channel_attention=True,
  59. norm_cfg=dict(type='SyncBN'),
  60. act_cfg=dict(type='SiLU'),
  61. init_cfg=dict(
  62. type='Pretrained',
  63. prefix='backbone.',
  64. checkpoint='https://download.openmmlab.com/mmpose/v1/projects/'
  65. 'rtmposev1/cspnext-m_udp-aic-coco_210e-256x192-f2f7d6f6_20230130.pth' # noqa
  66. )),
  67. head=dict(
  68. type='RTMCCHead',
  69. in_channels=768,
  70. out_channels=106,
  71. input_size=codec['input_size'],
  72. in_featuremap_size=(8, 8),
  73. simcc_split_ratio=codec['simcc_split_ratio'],
  74. final_layer_kernel_size=7,
  75. gau_cfg=dict(
  76. hidden_dims=256,
  77. s=128,
  78. expansion_factor=2,
  79. dropout_rate=0.,
  80. drop_path=0.,
  81. act_fn='SiLU',
  82. use_rel_bias=False,
  83. pos_enc=False),
  84. loss=dict(
  85. type='KLDiscretLoss',
  86. use_target_weight=True,
  87. beta=10.,
  88. label_softmax=True),
  89. decoder=codec),
  90. test_cfg=dict(flip_test=True, ))
  91. # base dataset settings
  92. dataset_type = 'LapaDataset'
  93. data_mode = 'topdown'
  94. data_root = 'data/LaPa/'
  95. backend_args = dict(backend='local')
  96. # backend_args = dict(
  97. # backend='petrel',
  98. # path_mapping=dict({
  99. # f'{data_root}': 's3://openmmlab/datasets/pose/LaPa/',
  100. # f'{data_root}': 's3://openmmlab/datasets/pose/LaPa/'
  101. # }))
  102. # pipelines
  103. train_pipeline = [
  104. dict(type='LoadImage', backend_args=backend_args),
  105. dict(type='GetBBoxCenterScale'),
  106. dict(type='RandomFlip', direction='horizontal'),
  107. dict(type='RandomHalfBody'),
  108. dict(
  109. type='RandomBBoxTransform', scale_factor=[0.5, 1.5], rotate_factor=80),
  110. dict(type='TopdownAffine', input_size=codec['input_size']),
  111. dict(type='mmdet.YOLOXHSVRandomAug'),
  112. dict(type='PhotometricDistortion'),
  113. dict(
  114. type='Albumentation',
  115. transforms=[
  116. dict(type='Blur', p=0.2),
  117. dict(type='MedianBlur', p=0.2),
  118. dict(
  119. type='CoarseDropout',
  120. max_holes=1,
  121. max_height=0.4,
  122. max_width=0.4,
  123. min_holes=1,
  124. min_height=0.2,
  125. min_width=0.2,
  126. p=1.0),
  127. ]),
  128. dict(type='GenerateTarget', encoder=codec),
  129. dict(type='PackPoseInputs')
  130. ]
  131. val_pipeline = [
  132. dict(type='LoadImage', backend_args=backend_args),
  133. dict(type='GetBBoxCenterScale'),
  134. dict(type='TopdownAffine', input_size=codec['input_size']),
  135. dict(type='PackPoseInputs')
  136. ]
  137. train_pipeline_stage2 = [
  138. dict(type='LoadImage', backend_args=backend_args),
  139. dict(type='GetBBoxCenterScale'),
  140. dict(type='RandomFlip', direction='horizontal'),
  141. # dict(type='RandomHalfBody'),
  142. dict(
  143. type='RandomBBoxTransform',
  144. shift_factor=0.,
  145. scale_factor=[0.75, 1.25],
  146. rotate_factor=60),
  147. dict(type='TopdownAffine', input_size=codec['input_size']),
  148. dict(type='mmdet.YOLOXHSVRandomAug'),
  149. dict(
  150. type='Albumentation',
  151. transforms=[
  152. dict(type='Blur', p=0.1),
  153. dict(type='MedianBlur', p=0.1),
  154. dict(
  155. type='CoarseDropout',
  156. max_holes=1,
  157. max_height=0.4,
  158. max_width=0.4,
  159. min_holes=1,
  160. min_height=0.2,
  161. min_width=0.2,
  162. p=0.5),
  163. ]),
  164. dict(type='GenerateTarget', encoder=codec),
  165. dict(type='PackPoseInputs')
  166. ]
  167. # data loaders
  168. train_dataloader = dict(
  169. batch_size=32,
  170. num_workers=10,
  171. persistent_workers=True,
  172. sampler=dict(type='DefaultSampler', shuffle=True),
  173. dataset=dict(
  174. type=dataset_type,
  175. data_root=data_root,
  176. data_mode=data_mode,
  177. ann_file='annotations/lapa_train.json',
  178. data_prefix=dict(img=''),
  179. pipeline=train_pipeline,
  180. ))
  181. val_dataloader = dict(
  182. batch_size=32,
  183. num_workers=10,
  184. persistent_workers=True,
  185. drop_last=False,
  186. sampler=dict(type='DefaultSampler', shuffle=False, round_up=False),
  187. dataset=dict(
  188. type=dataset_type,
  189. data_root=data_root,
  190. data_mode=data_mode,
  191. ann_file='annotations/lapa_val.json',
  192. data_prefix=dict(img=''),
  193. test_mode=True,
  194. pipeline=val_pipeline,
  195. ))
  196. test_dataloader = dict(
  197. batch_size=32,
  198. num_workers=10,
  199. persistent_workers=True,
  200. drop_last=False,
  201. sampler=dict(type='DefaultSampler', shuffle=False, round_up=False),
  202. dataset=dict(
  203. type=dataset_type,
  204. data_root=data_root,
  205. data_mode=data_mode,
  206. ann_file='annotations/lapa_test.json',
  207. data_prefix=dict(img=''),
  208. test_mode=True,
  209. pipeline=val_pipeline,
  210. ))
  211. # hooks
  212. default_hooks = dict(
  213. checkpoint=dict(
  214. save_best='NME', rule='less', max_keep_ckpts=1, interval=1))
  215. custom_hooks = [
  216. dict(
  217. type='EMAHook',
  218. ema_type='ExpMomentumEMA',
  219. momentum=0.0002,
  220. update_buffers=True,
  221. priority=49),
  222. dict(
  223. type='mmdet.PipelineSwitchHook',
  224. switch_epoch=max_epochs - stage2_num_epochs,
  225. switch_pipeline=train_pipeline_stage2)
  226. ]
  227. # evaluators
  228. val_evaluator = dict(
  229. type='NME',
  230. norm_mode='keypoint_distance',
  231. )
  232. test_evaluator = val_evaluator