open-mmlab / mmpose

OpenMMLab Pose Estimation Toolbox and Benchmark.
https://mmpose.readthedocs.io/en/latest/
Apache License 2.0
5.55k stars 1.21k forks source link

[Bug] got an unexpected keyword argument 'data_mode' #2492

Closed Rx2633 closed 1 year ago

Rx2633 commented 1 year ago

Prerequisite

Environment

OrderedDict([('sys.platform', 'win32'), ('Python', '3.8.16 (default, Jun 12 2023, 21:00:42) [MSC v.1916 64 bit (AMD64)]'), ('CUDA available', True), ('numpy_random_seed', 2147483648), ('GPU 0', 'NVIDIA GeForce RTX 4070 Laptop GPU'), ('CUDA_HOME', None), ('GCC', 'n/a'), ('PyTorch', '2.0.1+cu118'), ('PyTorch compiling details', 'PyTorch built with:\n - C++ Version: 199711\n - MSVC 193431937\n - Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications\n - Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)\n - OpenMP 2019\n - LAPACK is enabled (usually provided by MKL)\n - CPU capability u sage: AVX2\n - CUDA Runtime 11.8\n - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=comp ute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_90,code=sm_90;-gencode;arch=compute_37,code=compute_37\n - CuDNN 8.7\n - Mag ma 2.5.4\n - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.8, CUDNN_VERSION=8.7.0, CXX_COMPILER=C:/actions-runner/_work/pytorch/pytorch/builder/windows/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj /FS -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PE RF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=OFF, TORCH_VERSION=2.0.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=OFF, USE_OPENMP=ON, USE_ROCM=OFF, \n'), ('TorchVision', '0.15.2+cu118'), ('OpenCV', '4.7.0'), ('MMEngine', '0.7.4'), ('MMPose', '1.0.0+2c4a60e')])

Reproduces the problem - code sample

base = ['../../../base/default_runtime.py', '../../../base/datasets/custom.py']

runtime

train_cfg = dict(max_epochs=210, val_interval=10)

optimizer

optim_wrapper = dict(optimizer=dict( type='Adam', lr=5e-4, ))

learning policy

param_scheduler = [ dict( type='LinearLR', begin=0, end=500, start_factor=0.001, by_epoch=False), # warm-up dict( type='MultiStepLR', begin=0, end=210, milestones=[170, 200], gamma=0.1, by_epoch=True) ]

automatically scaling LR based on the actual training batch size

auto_scale_lr = dict(base_batch_size=512)

hooks

default_hooks = dict(checkpoint=dict(save_best='coco/AP', rule='greater'))

codec settings

codec = dict( type='MSRAHeatmap', input_size=(288, 384), heatmap_size=(72, 96), sigma=3, unbiased=True)

channel_cfg = dict( num_output_channels = 14, dataset_joints = 14, dataset_channel=[ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

],
inference_channel=[
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

])

model settings

model = dict( type='TopdownPoseEstimator', data_preprocessor=dict( type='PoseDataPreprocessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True), backbone=dict( type='ResNet', depth=50, init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), ), head=dict( type='HeatmapHead', in_channels=2048, out_channels=21, loss=dict(type='KeypointMSELoss', use_target_weight=True), decoder=codec), test_cfg=dict( flip_test=True, flip_mode='heatmap', shift_heatmap=True, ))

base dataset settings

dataset_type = 'customdataset' data_mode = 'topdown' data_root = r'D:\mmpose\dataset\CrowdPose'

pipelines

train_pipeline = [ dict(type='LoadImage'),#================================== dict(type='GetBBoxCenterScale'), dict(type='RandomFlip', direction='horizontal'), dict(type='RandomHalfBody'), dict(type='RandomBBoxTransform'), dict(type='TopdownAffine', input_size=codec['input_size']), dict(type='GenerateTarget', target_type='heatmap', encoder=codec), dict(type='PackPoseInputs') ] val_pipeline = [ dict(type='LoadImage'),#=============================== dict(type='GetBBoxCenterScale'), dict(type='TopdownAffine', input_size=codec['input_size']), dict(type='PackPoseInputs') ]

data loaders

train_dataloader = dict( batch_size=64, num_workers=2, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), dataset=dict( type=dataset_type, data_root=data_root, data_mode=data_mode, ann_file='/annotations/mmpose_crowdpose_train.json', data_prefix=dict(img='images/'), pipeline=train_pipeline, ))

val_dataloader = None

val_dataloader = dict( batch_size=32, num_workers=2, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False, round_up=False), dataset=dict( type=dataset_type, data_root=data_root, data_mode=data_mode, ann_file='/annotations/mmpose_crowdpose_val.json',

bbox_file='data/coco/person_detection_results/'

    # 'COCO_val2017_detections_AP_H_56_person.json',
    data_prefix=dict(img='images/'),
    test_mode=True,
    pipeline=val_pipeline,
))

test_dataloader = val_dataloader

evaluators

val_evaluator = dict( type='CocoMetric', ann_file=data_root + 'training_json/training.json') test_evaluator = val_evaluator

D:\mmpose\config_github\config_github.py

python tools/train.py D:\mmpose\config_github\config_github.py

D:\mmpose\configs\body_2d_keypoint\topdown_heatmap\coco\custom_mode_rx.py

python tools/train.py configs/body_2d_keypoint/topdown_heatmap/coco/custom_model.py

Reproduces the problem - command or script

Traceback (most recent call last): File "D:\anconda\envs\open_action\lib\site-packages\mmengine\registry\build_functions.py", line 122, in build_from_cfg obj = obj_cls(**args) # type: ignore TypeError: init() got an unexpected keyword argument 'data_mode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "tools/train.py", line 160, in main() File "tools/train.py", line 156, in main runner.train() File "D:\anconda\envs\open_action\lib\site-packages\mmengine\runner\runner.py", line 1687, in train self._train_loop = self.build_train_loop( File "D:\anconda\envs\open_action\lib\site-packages\mmengine\runner\runner.py", line 1486, in build_train_loop loop = EpochBasedTrainLoop( File "D:\anconda\envs\open_action\lib\site-packages\mmengine\runner\loops.py", line 44, in init super().init(runner, dataloader) File "D:\anconda\envs\open_action\lib\site-packages\mmengine\runner\base_loop.py", line 26, in init self.dataloader = runner.build_dataloader( File "D:\anconda\envs\open_action\lib\site-packages\mmengine\runner\runner.py", line 1346, in build_dataloader dataset = DATASETS.build(dataset_cfg) File "D:\anconda\envs\open_action\lib\site-packages\mmengine\registry\registry.py", line 548, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "D:\anconda\envs\open_action\lib\site-packages\mmengine\registry\build_functions.py", line 144, in build_from_cfg raise type(e)( TypeError: class customdataset in mmpose/datasets/datasets/body/custom_dataset.py: init() got an unexpected keyword argument 'data_mode'

Reproduces the problem - error message

NO

Additional information

I looked at the ([Bug] Try to train custom datasets #2368) problem, and imitated him to write exactly the same, using (OoenDataLba's CrowdPose) dataset, and deleted (file_client_args) in (dict(type='LoadImage'))

I just started learning to use MMPOSE, and I want to try to train my own data set, but I don't know how to write config files, I hope to get your guidance.

Ben-Louis commented 1 year ago

Hi, thanks for using MMPose. If you want to train models on CrowdPose, you can simply use the off-the-shelf dataset class https://github.com/open-mmlab/mmpose/blob/main/mmpose/datasets/datasets/body/crowdpose_dataset.py

Rx2633 commented 1 year ago

Thanks for your help, I used the file you gave me. Train successfully. But an error is reported when generating the result.

metrics = self.evaluator.evaluate(len(self.dataloader.dataset)) File "D:\anconda\envs\open_action\lib\site-packages\mmengine\evaluator\evaluator.py", line 79, in evaluate _results = metric.evaluate(size) File "D:\anconda\envs\open_action\lib\site-packages\mmengine\evaluator\metric.py", line 133, in evaluate _metrics = self.compute_metrics(results) # type: ignore File "d:\mmpose\mmpose\evaluation\metrics\coco_metric.py", line 440, in compute_metrics info_str = self._do_python_keypoint_eval(outfile_prefix) File "d:\mmpose\mmpose\evaluation\metrics\coco_metric.py", line 497, in _do_python_keypoint_eval coco_det = self.coco.loadRes(res_file) File "D:\anconda\envs\open_action\lib\site-packages\xtcocotools\coco.py", line 360, in loadRes assert set(annsImgIds) == (set(annsImgIds) & set(self.getImgIds())), \ AssertionError: Results do not correspond to current coco set

Ben-Louis commented 1 year ago

You use an annotation file for training in evaluators, which is why you’re encountering this issue. To set the evaluators, please refer to this code snippet: https://github.com/open-mmlab/mmpose/blob/2c4a60e357c7f68f3388f0fc4ddcb404674b81ae/configs/body_2d_keypoint/topdown_heatmap/crowdpose/td-hm_hrnet-w32_8xb64-210e_crowdpose-256x192.py#L145-L152

Rx2633 commented 1 year ago

Thanks a for your help, I've done the testing. May I ask if the key point recognition model of MMpose trained by myself can be used in MMaction2?

Ben-Louis commented 1 year ago

Of course yes. You could refer to https://github.com/open-mmlab/mmaction2/blob/main/demo/README.md#skeleton-based-action-recognition-demo on how to extract skeleton using MMPose for action recognition