open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.59k stars 9.46k forks source link

ValueError: class `EpochBasedTrainLoop` in mmengine/runner/loops.py: class `CocoDataset` in mmdet/datasets/coco.py: need at least one array to concatenate #10294

Open Caishen-git opened 1 year ago

Caishen-git commented 1 year ago

Thanks for your error report and we appreciate it a lot.

Checklist

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

Describe the bug A clear and concise description of what the bug is. ValueError: class CocoDataset in mmdet/datasets/coco.py: need at least one array to concatenate Reproduction

  1. What command or script did you run? I try to run /home/ubuntu18/cyq/mmdetection/mmdetection-main/tools/train.py

    A placeholder for the command.
  2. Did you make any modifications on the code or config? Did you understand what you have modified? [I changed /home/ubuntu18/cyq/mmdetection/mmdetection-main/mmdet/datasets/coco.py 'classes': ('Panstar algae', 'Scenedesmus', 'Asterella', 'Bent algae', '0ocysys', 'Microcystis'), # (This is the type of my own data set)

  3. What dataset did you use? my own data set. And I provide my generated ones in the appendix instances_val2017.json and instances_train2017.json

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment information and paste it here.
  2. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.) I followed your setup tutorial python demo/image_demo.py demo/demo.jpg rtmdet_tiny_8xb32-300e_coco.py --weights rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth --device cpu Finally, the demo.jpg is generated. So I think there is no problem with my environment. Error traceback If applicable, paste the error trackback here. During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "train.py", line 133, in main() File "train.py", line 129, in main runner.train() File "/home/ubuntu18/.conda/envs/cyq/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1672, in train self._train_loop = self.build_train_loop( File "/home/ubuntu18/.conda/envs/cyq/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1464, in build_train_loop loop = LOOPS.build( File "/home/ubuntu18/.conda/envs/cyq/lib/python3.8/site-packages/mmengine/registry/registry.py", line 545, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "/home/ubuntu18/.conda/envs/cyq/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 135, in build_from_cfg raise type(e)( ValueError: class EpochBasedTrainLoop in mmengine/runner/loops.py: class CocoDataset in mmdet/datasets/coco.py: need at least one array to concatenate

A placeholder for trackback.

Bug fix If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

WuChengbin commented 1 year ago

I also occurred this problem when I tried to train the model using a customized dataset in COCO format. I modified the model configuration file and added the following option, however, it didn't work. METAINFO = {'classes':('label1', 'label2')} or metainfo = {'classes':('label1', 'label2')}

Finally, I directly modified the METAINFO in coco.py, and it worked.

WuChengbin commented 1 year ago

I also occurred this problem when I tried to train the model using a customized dataset in COCO format. I modified the model configuration file and added the following option, however, it didn't work. METAINFO = {'classes':('label1', 'label2')} or metainfo = {'classes':('label1', 'label2')}

Finally, I directly modified the METAINFO in coco.py, and it worked.

I realized that I didn't pass the parameter - metainfo into the dataset in train_loader and val_loader, which is why I occurred this problem.

Caishen-git commented 1 year ago

Thank you very much for answering my question, but I have another question. What specifically did you modify the coco.py file? I have changed the category of the data set in it, but has not solved my problem? By the way, are you Chinese? I hope I can add your QQ or wechat to consult you about this problem. This is my QQ2398904958 and my wechat 15273115280.

------------------ 原始邮件 ------------------ 发件人: "open-mmlab/mmdetection" @.>; 发送时间: 2023年5月9日(星期二) 晚上7:59 @.>; @.**@.>; 主题: Re: [open-mmlab/mmdetection] ValueError: class EpochBasedTrainLoop in mmengine/runner/loops.py: class CocoDataset in mmdet/datasets/coco.py: need at least one array to concatenate (Issue #10294)

I also occurred this problem when I tried to train the model using a customized dataset in COCO format. I modified the model configuration file and added the following option, however, it didn't work. METAINFO = {'classes':('label1', 'label2')} or metainfo = {'classes':('label1', 'label2')}

Finally, I directly modified the METAINFO in coco.py, and it worked.

I realized that I didn't pass the parameter - metainfo into the dataset in train_loader and val_loader, which is why I occurred this problem.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

WuChengbin commented 1 year ago

Thank you very much for answering my question, but I have another question. What specifically did you modify the coco.py file? I have changed the category of the data set in it, but has not solved my problem? By the way, are you Chinese? I hope I can add your QQ or wechat to consult you about this problem. This is my QQ2398904958 and my wechat 15273115280.

I modified the coco.py file at line 17, but I found it is not the correct way. METAINFO = {'classes':('label1', 'label2'), 'palette':..}

It can be overridden in the model configuration file as follows,

metainfo = { 'classes': ('Type1', 'Type2'), 'palette': [ (255, 0, 0), (0, 255, 255) ] }

train_dataloader = dict( batch_size=2, num_workers=2, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), batch_sampler=dict(type='AspectRatioBatchSampler'), dataset=dict( metainfo = metainfo, type=dataset_type, data_root=data_root, ann_file='train.json', data_prefix=dict(img=''), filter_cfg=dict(filter_empty_gt=True, min_size=32), pipeline=train_pipeline, backend_args=backend_args))

You need to check whether the classes and coco format are correctly loaded, I set breakpoints in the coco.py file and tracked the code execution process. The function 'filter_data' will return an empty data_list when the data is not correctly loaded(e.g., not existing classes name and index), and finally result in the problem of 'ValueEorror: … need at least one array to concatenate'.

Caishen-git commented 1 year ago

Thank you for your answer.I modified the metainfo of the coco.py file, but there are still problems. Maybe there are other problems with my program, but I still appreciate your advice.

------------------ 原始邮件 ------------------ 发件人: "open-mmlab/mmdetection" @.>; 发送时间: 2023年5月10日(星期三) 中午12:49 @.>; @.**@.>; 主题: Re: [open-mmlab/mmdetection] ValueError: class EpochBasedTrainLoop in mmengine/runner/loops.py: class CocoDataset in mmdet/datasets/coco.py: need at least one array to concatenate (Issue #10294)

Thank you very much for answering my question, but I have another question. What specifically did you modify the coco.py file? I have changed the category of the data set in it, but has not solved my problem? By the way, are you Chinese? I hope I can add your QQ or wechat to consult you about this problem. This is my QQ2398904958 and my wechat 15273115280. …

I modified the coco.py file at line 17, but I found it is not the correct way. METAINFO = {'classes':('label1', 'label2'), 'palette':..}

It can be overridden in the model configuration file as follows,

metainfo = { 'classes': ('Type1', 'Type2'), 'palette': [ (255, 0, 0), (0, 255, 255) ] }

train_dataloader = dict( batch_size=2, num_workers=2, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), batch_sampler=dict(type='AspectRatioBatchSampler'), dataset=dict( metainfo = metainfo, type=dataset_type, data_root=data_root, ann_file='train.json', data_prefix=dict(img=''), filter_cfg=dict(filter_empty_gt=True, min_size=32), pipeline=train_pipeline, backend_args=backend_args))

You need to check whether the classes and coco format are correctly loaded, I set breakpoints in the coco.py file and tracked the code execution process. The function 'filter_data' will return an empty data_list when the data is not correctly loaded(e.g., not existing classes name and index), and finally result in the problem of 'ValueEorror: … need at least one array to concatenate'.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

willcray commented 1 year ago

I'm in the same boat. I can't get the train loop to run despite the suggested changes from @WuChengbin. This was never a problem in mmdet < 3.0.0

WuChengbin commented 1 year ago

@Caishen-git @willcray

Today, I reconfigured this project, and I again met this problem. And I hope my workflow can help you guys.

This problem occurred when loading the dataset, I checked the codes and found that there are many strict steps for the dataset format and class checking to ensure the dataset is aligned with the correct format(e.g., COCO). If you use a customized dataset, you should double-check the classes in the config file and update the 'metainfo' parameter of the dataset. If there are any mistakes in the COCO format dataset, a filter function will drop the sample, such as if no corresponding category is found in the annotation, and finally raise the error 'need at least one array to concatenate' when all samples are dropped.

When you use the tools\dataset_convertors\pascal_voc.py to convert your dataset to COCO, you should replace the voc_classe() function with a class list like classes = ['A', 'B',' C'] to build a correct COCO dataset.