open-mmlab / mmdetection

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

[Bug] AssertionError: The `num_classes` (1) in SSDHead of MMDataParallel does not matches the length of `CLASSES` 80) in RepeatDataset #9606

Closed IECCLES4 closed 1 year ago

IECCLES4 commented 1 year ago

Prerequisite

Task

I have modified the scripts/configs, or I'm working on my own tasks/models/datasets.

Branch

master branch https://github.com/open-mmlab/mmdetection

Environment

sys.platform: linux Python: 3.8.13 (default, Oct 21 2022, 23:50:54) [GCC 11.2.0] CUDA available: True GPU 0: NVIDIA GeForce GTX 1070 CUDA_HOME: /home/dtl-admin/miniconda3/envs/mmdet NVCC: Cuda compilation tools, release 11.6, V11.6.124 GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 PyTorch: 1.11.0 PyTorch compiling details: PyTorch built with:

TorchVision: 0.12.0 OpenCV: 4.6.0 MMCV: 1.5.3 MMCV Compiler: GCC 7.3 MMCV CUDA Compiler: 11.3 MMDetection: 2.25.3+2b5504e

Reproduces the problem - code sample

This is my custom config that I am trying to use to train with. I have trained with these datasets before using faster_rcnn and it worked fine but now I am trying to use SSD to train and I keep getting this error.

base = '../ssd/ssd300_coco.py' model = dict( bbox_head=dict(num_classes=1)) dataset_type = 'COCODataset' classes = ('pantograph',) data = dict( train=dict( img_prefix='configs/pantograph/train/', classes=classes, ann_file='configs/pantograph/train/G-gauge_blackpool-trams_trainsim.json', dataset=dict( ann_file='configs/pantograph/train/G-gauge_blackpool-trams_trainsim.json', img_prefix='configs/pantograph/train')), val=dict( img_prefix='configs/pantograph/val/', classes=classes, ann_file='configs/pantograph/val/PantoVal.json'), test=dict( img_prefix='configs/pantograph/test/', classes=classes, ann_file='configs/pantograph/test/result.json'))

Reproduces the problem - command or script

python tools/train.py configs/pantograph/ssd_pantograph.py

Reproduces the problem - error message

Traceback (most recent call last): File "tools/train.py", line 244, in main() File "tools/train.py", line 233, in main train_detector( File "/home/dtl-admin/dev/repos/bitbucket/railsight/mmdetection-2.25.3/mmdet/apis/train.py", line 244, in train_detector runner.run(data_loaders, cfg.workflow) File "/home/dtl-admin/miniconda3/envs/mmdet/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 130, in run epoch_runner(data_loaders[i], **kwargs) File "/home/dtl-admin/miniconda3/envs/mmdet/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 45, in train self.call_hook('before_train_epoch') File "/home/dtl-admin/miniconda3/envs/mmdet/lib/python3.8/site-packages/mmcv/runner/base_runner.py", line 309, in call_hook getattr(hook, fn_name)(self) File "/home/dtl-admin/dev/repos/bitbucket/railsight/mmdetection-2.25.3/mmdet/datasets/utils.py", line 158, in before_train_epoch self._check_head(runner) File "/home/dtl-admin/dev/repos/bitbucket/railsight/mmdetection-2.25.3/mmdet/datasets/utils.py", line 144, in _check_head assert module.num_classes == len(dataset.CLASSES), \ AssertionError: The num_classes (1) in SSDHead of MMDataParallel does not matches the length of CLASSES 80) in RepeatDataset

Additional information

No response

hhaAndroid commented 1 year ago

@IECCLES4

base = '../ssd/ssd300_coco.py'
model = dict(bbox_head=dict(num_classes=1))
dataset_type = 'COCODataset'

classes = ('pantograph',)
data = dict(
train=dict(
  dataset=dict(
    classes=classes, # NOTE
    ann_file='configs/pantograph/train/G-gauge_blackpool-trams_trainsim.json',
    img_prefix='configs/pantograph/train')),

val=dict(
  img_prefix='configs/pantograph/val/',
  classes=classes,
  ann_file='configs/pantograph/val/PantoVal.json'),

test=dict(
  img_prefix='configs/pantograph/test/',
  classes=classes,
  ann_file='configs/pantograph/test/result.json'))
IECCLES4 commented 1 year ago

@IECCLES4

base = '../ssd/ssd300_coco.py'
model = dict(bbox_head=dict(num_classes=1))
dataset_type = 'COCODataset'

classes = ('pantograph',)
data = dict(
train=dict(
  dataset=dict(
    classes=classes, # NOTE
    ann_file='configs/pantograph/train/G-gauge_blackpool-trams_trainsim.json',
    img_prefix='configs/pantograph/train')),

val=dict(
  img_prefix='configs/pantograph/val/',
  classes=classes,
  ann_file='configs/pantograph/val/PantoVal.json'),

test=dict(
  img_prefix='configs/pantograph/test/',
  classes=classes,
  ann_file='configs/pantograph/test/result.json'))

Thank you but I fixed this issue a while ago I just forgot to close the issue. Thank you though

LuYang-2023 commented 1 year ago

@IECCLES4

base = '../ssd/ssd300_coco.py'
model = dict(bbox_head=dict(num_classes=1))
dataset_type = 'COCODataset'

classes = ('pantograph',)
data = dict(
train=dict(
  dataset=dict(
    classes=classes, # NOTE
    ann_file='configs/pantograph/train/G-gauge_blackpool-trams_trainsim.json',
    img_prefix='configs/pantograph/train')),

val=dict(
  img_prefix='configs/pantograph/val/',
  classes=classes,
  ann_file='configs/pantograph/val/PantoVal.json'),

test=dict(
  img_prefix='configs/pantograph/test/',
  classes=classes,
  ann_file='configs/pantograph/test/result.json'))

Thank you but I fixed this issue a while ago I just forgot to close the issue. Thank you though

I had a similar problem when I checked that there was no metainfo in the val_dataloader