Closed SunWeimiao closed 1 year ago
@SunWeimiao Could you provide the link of this config you use? train_cfg.max_epochs
seems to be wrong, it should be train_cfg["max_epochs"]
@SunWeimiao Could you provide the link of this config you use?
train_cfg.max_epochs
seems to be wrong, it should betrain_cfg["max_epochs"]
thanks for your help, the link is https://github.com/open-mmlab/mmpose/blob/main/demo/MMPose_Tutorial.ipynb
the train_cfg.max_epochs
is in the section Create a config file
and i encountered another error, what's the correct key: Traceback (most recent call last): File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\runner\runner.py", line 1783, in call_hook getattr(hook, fn_name)(self, **kwargs) File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\hooks\checkpoint_hook.py", line 329, in after_val_epoch self._save_best_checkpoint(runner, metrics) File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\hooks\checkpoint_hook.py", line 458, in _save_best_checkpoint key_score = metrics[key_indicator] KeyError: 'coco/AP'
@SunWeimiao Could you provide the link of this config you use?
train_cfg.max_epochs
seems to be wrong, it should betrain_cfg["max_epochs"]
thanks for your help, the link is https://github.com/open-mmlab/mmpose/blob/main/demo/MMPose_Tutorial.ipynb
the
train_cfg.max_epochs
is in the section Create a config fileand i encountered another error, what's the correct key: Traceback (most recent call last): File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\runner\runner.py", line 1783, in call_hook getattr(hook, fn_name)(self, **kwargs) File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\hooks\checkpoint_hook.py", line 329, in after_val_epoch self._save_best_checkpoint(runner, metrics) File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\hooks\checkpoint_hook.py", line 458, in _save_best_checkpoint key_score = metrics[key_indicator] KeyError: 'coco/AP'
After modifying coco/AP
to PCK
, I re executed the training command and the command was successfully executed.
@Tau-J
In the same section Create a config file, there is another error:
coco/AP
should be changed to PCK
Prerequisite
Environment
mmaction 0.5.0 mmcv 2.0.0 mmdet 3.0.0 mmengine 0.7.3 mmpose 1.0.0
Reproduces the problem - code sample
I'm the beginner of mmpose. I follow the tutorial at https://github.com/open-mmlab/mmpose/blob/main/demo/MMPose_Tutorial.ipynb However, I encountered an error.I wonder where i made the mistake and how to solve it.
My steps are as follows:
1. create the dataset class like follow:
import json import os.path as osp from typing import Callable, List, Optional, Sequence, Union import numpy as np from mmengine.utils import check_file_exist from mmpose.registry import DATASETS from mmpose.datasets.datasets.base import BaseCocoStyleDataset
@DATASETS.register_module() class TinyCocoDataset(BaseCocoStyleDataset): METAINFO: dict = dict(from_file='configs/base/datasets/coco.py')
2.register this dataset class
from .aic_dataset import AicDataset from .coco_dataset import CocoDataset from .crowdpose_dataset import CrowdPoseDataset from .jhmdb_dataset import JhmdbDataset from .mhp_dataset import MhpDataset from .mpii_dataset import MpiiDataset from .mpii_trb_dataset import MpiiTrbDataset from .ochuman_dataset import OCHumanDataset from .posetrack18_dataset import PoseTrack18Dataset from .posetrack18_video_dataset import PoseTrack18VideoDataset from .tinycocodataset import TinyCocoDataset
all = [ 'CocoDataset', 'MpiiDataset', 'MpiiTrbDataset', 'AicDataset', 'CrowdPoseDataset', 'OCHumanDataset', 'MhpDataset', 'PoseTrack18Dataset', 'JhmdbDataset', 'PoseTrack18VideoDataset', 'TinyCocoDataset' ]
3.create config file(hrnet_w32_coco_tiny_256x192.py) like follow
base = ['../../../base/default_runtime.py']
runtime
train_cfg = dict(max_epochs=40, val_interval=1)
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=train_cfg.max_epochs, milestones=[17, 35], gamma=0.1, by_epoch=True) ]
automatically scaling LR based on the actual training batch size
auto_scale_lr = dict(base_batch_size=512)
codec settings
codec = dict( type='MSRAHeatmap', input_size=(192, 256), heatmap_size=(48, 64), sigma=2)
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='HRNet', in_channels=3, extra=dict( stage1=dict( num_modules=1, num_branches=1, block='BOTTLENECK', num_blocks=(4, ), num_channels=(64, )), stage2=dict( num_modules=1, num_branches=2, block='BASIC', num_blocks=(4, 4), num_channels=(32, 64)), stage3=dict( num_modules=4, num_branches=3, block='BASIC', num_blocks=(4, 4, 4), num_channels=(32, 64, 128)), stage4=dict( num_modules=3, num_branches=4, block='BASIC', num_blocks=(4, 4, 4, 4), num_channels=(32, 64, 128, 256))), init_cfg=dict( type='Pretrained', checkpoint='configs/body_2d_keypoint/topdown_heatmap/coco/hrnet_w32-36af842e.pth'), ), head=dict( type='HeatmapHead', in_channels=32, out_channels=17, deconv_out_channels=None, 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 = 'TinyCocoDataset' data_mode = 'topdown' data_root = 'data/coco_tiny' work_dir = 'work_dirs/hrnet_w32_tiny_coco_256x192' randomness = dict(seed=0)
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') ] test_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=16, 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='train.json', data_prefix=dict(img='images/'), pipeline=train_pipeline, )) val_dataloader = dict( batch_size=16, 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='val.json', data_prefix=dict(img='images/'), test_mode=True, pipeline=test_pipeline, )) test_dataloader = val_dataloader
evaluators
val_evaluator = dict( type='PCKAccuracy') test_evaluator = val_evaluator
hooks
default_hooks = dict(checkpoint=dict(save_best='coco/AP', rule='greater'))
Reproduces the problem - command or script
python tools/train.py configs/body_2d_keypoint/topdown_heatmap/coco/hrnet_w32_coco_tiny_256x192.py
Reproduces the problem - error message
Traceback (most recent call last): File "tools/train.py", line 160, in
main()
File "tools/train.py", line 142, in main
cfg = Config.fromfile(args.config)
File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\config\config.py", line 178, in fromfile
cfg_dict, cfg_text, env_variables = Config._file2dict(
File "D:\Anaconda3\envs\openmmlab\lib\site-packages\mmengine\config\config.py", line 522, in _file2dict
eval(codeobj, global_locals_var, global_locals_var)
File "", line 20, in
AttributeError: 'dict' object has no attribute 'max_epochs'
Additional information
No response