AssertionError: The num_classes (3) in SSDHead of SingleStageDetector does not matches the length of classes 80) in CocoDataset
psantiago-lsbd opened this issue · 0 comments
psantiago-lsbd commented
Hello.
Checklist
- I have searched related issues but cannot get the expected help.
- I have read the FAQ documentation but cannot get the expected help.
- The bug has not been fixed in the latest version.
Describe the bug
I'm receiving the following error when trying to start training with the SSD512.
num_class_check_hook.py", line 44, in _check_head
assert module.num_classes == len(classes), \
AssertionError: The num_classes (3) in SSDHead of SingleStageDetector does not matches the length of classes 80) in CocoDataset
Reproduction
python mmdetection/tools/train.py my_ssd512_config.py
My config file:
auto_scale_lr = dict(base_batch_size=64, enable=False)
backend_args = None
cudnn_benchmark = True
custom_hooks = [
dict(type="NumClassCheckHook"),
dict(interval=50, priority="VERY_LOW", type="CheckInvalidLossHook"),
]
data_root = "/content/drive/Shareddrives/Research/Datasets/Vision/damage_detection/1.0.1/coco_data/images/"
default_hooks = dict(
checkpoint=dict(interval=1, save_best="auto", type="CheckpointHook"),
logger=dict(interval=50, type="LoggerHook"),
param_scheduler=dict(type="ParamSchedulerHook"),
sampler_seed=dict(type="DistSamplerSeedHook"),
timer=dict(type="IterTimerHook"),
visualization=dict(type="DetVisualizationHook"),
)
default_scope = "mmdet"
env_cfg = dict(
cudnn_benchmark=False,
dist_cfg=dict(backend="nccl"),
mp_cfg=dict(mp_start_method="fork", opencv_num_threads=0),
)
gpu_ids = range(0, 1)
input_size = 512
launcher = "none"
load_from = None
log_level = "INFO"
log_processor = dict(by_epoch=True, type="LogProcessor", window_size=50)
max_epochs = 150
metainfo = dict(
classes=(
"KD",
"BH",
"CD",
)
)
classes = (
"KD",
"BH",
"CD",
)
model = dict(
backbone=dict(
ceil_mode=True,
depth=16,
init_cfg=dict(checkpoint="open-mmlab://vgg16_caffe", type="Pretrained"),
out_feature_indices=(
22,
34,
),
out_indices=(
3,
4,
),
type="SSDVGG",
with_last_pool=False,
),
bbox_head=dict(
type="SSDHead",
in_channels=(512, 1024, 512, 256, 256, 256),
num_classes=3,
anchor_generator=dict(
type="SSDAnchorGenerator",
scale_major=False,
input_size=input_size,
basesize_ratio_range=(0.15, 0.9),
strides=[8, 16, 32, 64, 100, 300],
ratios=[[2], [2, 3], [2, 3], [2, 3], [2], [2]],
),
bbox_coder=dict(
type="DeltaXYWHBBoxCoder",
target_means=[0.0, 0.0, 0.0, 0.0],
target_stds=[0.1, 0.1, 0.2, 0.2],
),
),
data_preprocessor=dict(
bgr_to_rgb=True,
mean=[
123.675,
116.28,
103.53,
],
pad_size_divisor=1,
std=[
1,
1,
1,
],
type="DetDataPreprocessor",
),
neck=dict(
in_channels=(
512,
1024,
),
l2_norm_scale=20,
last_kernel_size=4,
level_paddings=(
1,
1,
1,
1,
1,
),
level_strides=(
2,
2,
2,
2,
1,
),
out_channels=(
512,
1024,
512,
256,
256,
256,
256,
),
type="SSDNeck",
),
test_cfg=dict(
max_per_img=200,
min_bbox_size=0,
nms=dict(iou_threshold=0.45, type="nms"),
nms_pre=1000,
score_thr=0.02,
),
train_cfg=dict(
allowed_border=-1,
assigner=dict(
gt_max_assign_all=False,
ignore_iof_thr=-1,
min_pos_iou=0.0,
neg_iou_thr=0.5,
pos_iou_thr=0.5,
type="MaxIoUAssigner",
),
debug=False,
neg_pos_ratio=3,
pos_weight=-1,
sampler=dict(type="PseudoSampler"),
smoothl1_beta=1.0,
),
type="SingleStageDetector",
)
optim_wrapper = dict(
optimizer=dict(lr=0.002, momentum=0.9, type="SGD", weight_decay=0.0005),
type="OptimWrapper",
)
param_scheduler = [
dict(begin=0, by_epoch=False, end=500, start_factor=0.001, type="LinearLR"),
dict(
begin=0,
by_epoch=True,
end=24,
gamma=0.1,
milestones=[
16,
22,
],
type="MultiStepLR",
),
]
resume = False
seed = 0
test_cfg = dict(type="TestLoop")
test_dataloader = dict(
batch_size=8,
dataset=dict(
ann_file="/content/test.json",
backend_args=None,
data_prefix=dict(
img="/content/drive/Shareddrives/Research/Datasets/Vision/damage_detection/1.0.1/coco_data/"
),
data_root="/content/drive/Shareddrives/Research/Datasets/Vision/damage_detection/1.0.1/coco_data/images",
metainfo=dict(
classes=(
"KD",
"BH",
"CD",
)
),
pipeline=[
dict(backend_args=None, type="LoadImageFromFile"),
dict(
keep_ratio=False,
scale=(
512,
512,
),
type="Resize",
),
dict(type="LoadAnnotations", with_bbox=True),
dict(
meta_keys=(
"img_id",
"img_path",
"ori_shape",
"img_shape",
"scale_factor",
),
type="PackDetInputs",
),
],
type="CocoDataset",
),
drop_last=False,
num_workers=2,
persistent_workers=True,
sampler=dict(shuffle=False, type="DefaultSampler"),
)
test_evaluator = dict(ann_file="/content/test.json")
test_pipeline = [
dict(backend_args=None, type="LoadImageFromFile"),
dict(
keep_ratio=False,
scale=(
512,
512,
),
type="Resize",
),
dict(type="LoadAnnotations", with_bbox=True),
dict(
meta_keys=(
"img_id",
"img_path",
"ori_shape",
"img_shape",
"scale_factor",
),
type="PackDetInputs",
),
]
train_cfg = dict(max_epochs=150, type="EpochBasedTrainLoop", val_interval=1)
train_dataloader = dict(
batch_size=8,
dataset=dict(
ann_file="/content/train.json",
data_prefix=dict(
img="/content/drive/Shareddrives/Research/Datasets/Vision/damage_detection/1.0.1/coco_data/"
),
data_root="/content/drive/Shareddrives/Research/Datasets/Vision/damage_detection/1.0.1/coco_data/images/",
type="CocoDataset",
),
)
train_pipeline = [
dict(backend_args=None, type="LoadImageFromFile"),
dict(type="LoadAnnotations", with_bbox=True),
dict(
mean=[
123.675,
116.28,
103.53,
],
ratio_range=(
1,
4,
),
to_rgb=True,
type="Expand",
),
dict(
min_crop_size=0.3,
min_ious=(
0.1,
0.3,
0.5,
0.7,
0.9,
),
type="MinIoURandomCrop",
),
dict(
keep_ratio=False,
scale=(
512,
512,
),
type="Resize",
),
dict(prob=0.5, type="RandomFlip"),
dict(
brightness_delta=32,
contrast_range=(
0.5,
1.5,
),
hue_delta=18,
saturation_range=(
0.5,
1.5,
),
type="PhotoMetricDistortion",
),
dict(type="PackDetInputs"),
]
val_cfg = dict(type="ValLoop")
val_dataloader = dict(
dataset=dict(
ann_file="/content/test.json",
data_prefix=dict(
img="/content/drive/Shareddrives/Research/Datasets/Vision/damage_detection/1.0.1/coco_data/"
),
data_root="/content/drive/Shareddrives/Research/Datasets/Vision/damage_detection/1.0.1/coco_data/images/",
metainfo=dict(
classes=(
"KD",
"BH",
"CD",
)
),
type="CocoDataset",
)
)
val_evaluator = dict(ann_file="/content/test.json", metric="bbox", type="CocoMetric")
vis_backends = [
dict(type="LocalVisBackend"),
]
visualizer = dict(
name="visualizer",
type="DetLocalVisualizer",
vis_backends=[
dict(type="LocalVisBackend"),
],
)
work_dir = "/content/drive/MyDrive/santiago/mmdet_work_dir/ssd"
- What dataset did you use?
My custom dataset
Environment
sys.platform: linux
Python: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
CUDA available: True
MUSA available: False
numpy_random_seed: 2147483648
GPU 0: NVIDIA A100-SXM4-40GB
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 12.2, V12.2.140
GCC: x86_64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
PyTorch: 2.1.2+cu121
PyTorch compiling details: PyTorch built with:
- GCC 9.3
- C++ Version: 201703
- Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220804 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v3.1.1 (Git Hash 64f6bcbcbab628e96f33a62c3e975f8535a7bde4)
- OpenMP 201511 (a.k.a. OpenMP 4.5)
- LAPACK is enabled (usually provided by MKL)
- NNPACK is enabled
- CPU capability usage: AVX512
- CUDA Runtime 12.1
- NVCC architecture flags: -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;-gencode;arch=compute_90,code=sm_90
- CuDNN 8.9.2
- Magma 2.6.1
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=12.1, CUDNN_VERSION=8.9.2, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=old-style-cast -Wno-invalid-partial-specialization -Wno-unused-private-field -Wno-aligned-allocation-unavailable -Wno-missing-braces -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_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=2.1.2, 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=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF,
TorchVision: 0.16.2+cu121
OpenCV: 4.10.0
MMEngine: 0.10.4
MMDetection: 3.3.0+02abc04
Error traceback
10/04 18:40:08 - mmengine - INFO - load model from: open-mmlab://vgg16_caffe
10/04 18:40:08 - mmengine - INFO - Loads checkpoint by openmmlab backend from path: open-mmlab://vgg16_caffe
10/04 18:40:08 - mmengine - WARNING - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io
10/04 18:40:08 - mmengine - WARNING - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future.
10/04 18:40:08 - mmengine - INFO - Checkpoints will be saved to /content/drive/MyDrive/santiago/mmdet_work_dir/ssd.
Traceback (most recent call last):
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmdetection/tools/train.py", line 121, in <module>
main()
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmdetection/tools/train.py", line 117, in main
runner.train()
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmengine/mmengine/runner/runner.py", line 1777, in train
model = self.train_loop.run() # type: ignore
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmengine/mmengine/runner/loops.py", line 96, in run
self.run_epoch()
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmengine/mmengine/runner/loops.py", line 110, in run_epoch
self.runner.call_hook('before_train_epoch')
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmengine/mmengine/runner/runner.py", line 1839, in call_hook
getattr(hook, fn_name)(self, **kwargs)
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmdetection/mmdet/engine/hooks/num_class_check_hook.py", line 59, in before_train_epoch
self._check_head(runner, 'train')
File "/content/drive/Othercomputers/Research/Vision/notebooks/pipeline/mmdetection/mmdet/engine/hooks/num_class_check_hook.py", line 44, in _check_head
assert module.num_classes == len(classes), \
AssertionError: The num_classes (3) in SSDHead of SingleStageDetector does not matches the length of classes 80) in CocoDataset