open-mmlab / mmpose

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

error of raise type(e)(f'{obj_cls.__name__}: {e}') and TypeError: Excavator2Dataset: string indices must be integers #2021

Open alaa-shubbak opened 1 year ago

alaa-shubbak commented 1 year ago

Checklist

  1. I have searched related issues but cannot get the expected help. yes
  2. The bug has not been fixed in the latest version. yes

I try to train my model on my custom dataset , and i got this error message :

TypeError: Excavator2Dataset: string indices must be integers error new

A clear and concise description of what the bug is.

Reproduction


- What config did you run?
my config file was as bellow 

base = [ '../base/default_runtime.py', '../base/datasets/coco_ex.py' ] evaluation = dict(interval=10, metric='mAP', save_best='AP')

optimizer = dict( type='Adam', lr=5e-4, ) optimizer_config = dict(grad_clip=None)

learning policy

lr_config = dict( policy='step', warmup='linear', warmup_iters=500, warmup_ratio=0.001, step=[170, 200]) total_epochs = 210 log_config = dict( interval=1, hooks=[ dict(type='TextLoggerHook'),

dict(type='TensorboardLoggerHook')

])

channel_cfg = dict( num_output_channels=4, dataset_joints=4, dataset_channel=[ [0, 1, 2, 3], ], inference_channel=[ 0, 1, 2, 3 ])

model settings

model = dict( type='TopDown', pretrained='https://download.openmmlab.com/mmpose/' 'pretrain_models/hrnet_w32-36af842e.pth', 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))), ), keypoint_head=dict( type='TopdownHeatmapSimpleHead', in_channels=32, out_channels=channel_cfg['num_output_channels'], num_deconv_layers=0, extra=dict(final_conv_kernel=1, ), loss_keypoint=dict(type='JointsMSELoss', use_target_weight=True)), train_cfg=dict(), test_cfg=dict( flip_test=True, post_process='default', shift_heatmap=True, modulate_kernel=11))

data_cfg = dict( image_size=[256, 256], heatmap_size=[64, 64], num_output_channels=channel_cfg['num_output_channels'], num_joints=channel_cfg['dataset_joints'], dataset_channel=channel_cfg['dataset_channel'], inference_channel=channel_cfg['inference_channel'], soft_nms=False, nms_thr=1.0, oks_thr=0.9, vis_thr=0.2, use_gt_bbox=True, det_bbox_thr=0.0, bbox_file='', )

train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='TopDownGetBboxCenterScale', padding=1.25), dict(type='TopDownRandomShiftBboxCenter', shift_factor=0.16, prob=0.3), dict(type='TopDownRandomFlip', flip_prob=0.5), dict( type='TopDownHalfBodyTransform', num_joints_half_body=8, prob_half_body=0.3), dict( type='TopDownGetRandomScaleRotation', rot_factor=40, scale_factor=0.5), dict(type='TopDownAffine'), dict(type='ToTensor'), dict( type='NormalizeTensor', mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), dict(type='TopDownGenerateTarget', sigma=2), dict( type='Collect', keys=['img', 'target', 'target_weight'], meta_keys=[ 'image_file', 'joints_3d', 'joints_3d_visible', 'center', 'scale', 'rotation', 'bbox_score', 'flip_pairs' ]), ]

val_pipeline = [ dict(type='LoadImageFromFile'), dict(type='TopDownGetBboxCenterScale', padding=1.25), dict(type='TopDownAffine'), dict(type='ToTensor'), dict( type='NormalizeTensor', mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), dict( type='Collect', keys=['img'], meta_keys=[ 'image_file', 'center', 'scale', 'rotation', 'bbox_score', 'flip_pairs' ]), ]

test_pipeline = val_pipeline

data_root = 'dataset/exc' data = dict( samples_per_gpu=64, workers_per_gpu=2, val_dataloader=dict(samples_per_gpu=32), test_dataloader=dict(samples_per_gpu=32), train=dict( type='Excavator2Dataset', ann_file=f'{data_root}/annotations/annotation_train.json', img_prefix=f'{data_root}/images/', data_cfg=data_cfg, pipeline=train_pipeline, dataset_info={{base.dataset_info}}), val=dict( type='Excavator2Dataset', ann_file=f'{data_root}/annotations/annotation_test.json', img_prefix=f'{data_root}/images/', data_cfg=data_cfg, pipeline=val_pipeline, dataset_info={{base.dataset_info}}), test=dict( type='Excavator2Dataset', ann_file=f'{data_root}/annotations/annotation_test.json', img_prefix=f'{data_root}/images/', data_cfg=data_cfg, pipeline=test_pipeline, dataset_info={{base.dataset_info}}), )



- Did you make any modifications on the code or config? Did you understand what you have modified?
yes , as my dataset has 4 keypoints and 3 joints. i modified the config according to this, 

i did change in the following lines : 
`channel_cfg = dict(
    num_output_channels=4,
    dataset_joints=4,
    dataset_channel=[
        [0, 1, 2, 3],
    ],
    inference_channel=[
        0, 1, 2, 3
    ])`
and the root of the data. 
I make my own dataset file within configs/-base-/dataset/
here is the file: 
[coco_ex.txt](https://github.com/open-mmlab/mmpose/files/10899737/coco_ex.txt)

- What dataset did you use?
new dataset , has same format as coco , it has all info /part in coco annotation file  except the segmentation 
here a sample of my test dataset 
[annotation_test.txt](https://github.com/open-mmlab/mmpose/files/10899693/annotation_test.txt)

i did the registry of my custom dataset and follow this  [ repository](https://mmpose.readthedocs.io/en/v0.29.0/tutorials/2_new_dataset.html),but i still have the error. 
here is my dataset 
[excavator2_dataset.txt](https://github.com/open-mmlab/mmpose/files/10899763/excavator2_dataset.txt)
this has been defined  within mmpose/datasets/dataset/

**Environment**

1. Please run `PYTHONPATH=${PWD}:$PYTHONPATH python mmpose/utils/collect_env.py` to collect necessary environment information and paste it here.
`/home/lem/miniconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/__init__.py:20: UserWarning: On January 1, 2023, MMCV will release v2.0.0, in which it will remove components related to the training process and add a data transformation module. In addition, it will rename the package names mmcv to mmcv-lite and mmcv-full to mmcv. See https://github.com/open-mmlab/mmcv/blob/master/docs/en/compatibility.md for more details.
  warnings.warn(
sys.platform: linux
Python: 3.8.16 (default, Jan 17 2023, 23:13:24) [GCC 11.2.0]
CUDA available: True
GPU 0: NVIDIA GeForce RTX 3060
CUDA_HOME: /home/lem/miniconda3/envs/openmmlab
NVCC: Cuda compilation tools, release 11.7, V11.7.99
GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
PyTorch: 1.13.1+cu117
PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.6.0 (Git Hash 52b5f107dd9cf10910aaa19cb47f3abf9b349815)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.7
  - 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_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
  - CuDNN 8.5
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.13.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=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

TorchVision: 0.14.1+cu117
OpenCV: 4.7.0
MMCV: 1.7.1
MMCV Compiler: GCC 7.3
MMCV CUDA Compiler: not available
MMPose: 0.29.0+cbac880
`

3. You may add addition that may be helpful for locating the problem, such as

- How you installed PyTorch \[e.g., pip, conda, source\] conda 
- Other environment variables that may be related (such as `$PATH`, `$LD_LIBRARY_PATH`, `$PYTHONPATH`, etc.)
ly015 commented 1 year ago

The error information indicates that the cat here is a string, which should be a dict. Could you please verify that your annotation files follow the standard COCO format? Or would you like to share the annotation file so we can reproduce and fix this problem? image

alaa-shubbak commented 1 year ago

sure i can share the annotation file of my train dataset as bellow : annotation_train.txt the test dataset has the same format.

alaa-shubbak commented 1 year ago

here also the images and the test annotations. annotation_test.txt images.zip

please help.

ly015 commented 1 year ago

Hi, the reason seems to be that in your annotation file the 'categories' field is a dict, which should be a list of dict in COCO format. You can refer to the COCO offical site for details.

alaa-shubbak commented 1 year ago

Thanks . Now my model is being able to train.

and i got a results as .pth for different epochs.

I would like to ask about testing the result and show the keypoint and skeleton over the images. I used those two commands: first : python tools/test.py configs xx.pth --eval mAP --work-dir folder .

from this i got a file of results_keypoints.json

which i use it for the second command second:python demo/top_down_img_demo.py configs xxx.pth --img-root --json-file result_keypoints.json --out-img-root vis_results_exc

I am not sure if i am doing the right in extract test images with skeleton.

when running the second command , i got this error : AssertionError: annotation file format <class 'list'> not supported

image

can you please help

ly015 commented 1 year ago

The script tools/test.py is for quantitatively evaluating the trained model in metrics like 'AP'. It's output result_keypoints.json are not for visualization.

demo/top_down_image_demo.py can be used to visualize the inference results of a trained model. And the argument --json-file should be the annotation file, like the annotation_train.txt and annotation_test.txt attached above (whose content is actually in json format).

IssaIssa1 commented 1 year ago

@ly015 the test.py file saves the prediction into json file. is there a way to call evaluation in this file directly without rerunning and writing the file again?

alaa-shubbak commented 1 year ago

@ly015 I try to test my trained model on some images and want to visualize the results as skeleton. I use the same command: demo/top_down_image_demo.py with my config, .pth file ,and direction of the images. I did not use any json file

i got this error message: loading annotations into memory... Traceback (most recent call last): File "/home/shubbak/mmpose/demo/top_down_img_demo.py", line 130, in <module> main() File "/home/shubbak/mmpose/demo/top_down_img_demo.py", line 58, in main coco = COCO(args.json_file) File "/home/shubbak/env_pose/lib/python3.9/site-packages/xtcocotools/coco.py", line 93, in __init__ with open(annotation_file, 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: '' is there any method that i can test my trained model on a group of image without having annotation json file, and at same time visualize the results?