Problem encountered in MMDetection. KeyError: 'mask_detectionDataset is not in the dataset registry'
I tried to train my model with MMdetection, however, error like &quot;KeyError: 'mask_detectionDataset is not in the dataset registry'&quot; keep showing.
I've added my dataset to init.py in \mmdetection\mmdet\datasets. And use @DATASETS.register_module(), but problem doesn't solved.
When I try to run init.py directly in \mmdetection\mmdet\datasets, it shows attempted relative import with no known parent package,i'm wondering why.
here is my code:
# -*- coding: utf-8 -*-
&quot;&quot;&quot;
Created on Sat Nov 27 00:55:00 2021

@author: daish
&quot;&quot;&quot;
import mmcv
from mmcv import Config
from mmdet.apis import set_random_seed
import os

cfg = Config.fromfile('F:/Project/mmdetection/configs/swin/mask_rcnn_swin-t-p4-w7_fpn_1x_coco.py')
# Modify dataset type and path
cfg.dataset_type = 'mask_detectionDataset'
cfg.data_root = 'F:/Project/dataset/'

cfg.data.test.type = 'mask_detectionDataset'
cfg.data.test.data_root = 'F:/Project/dataset/'
cfg.data.test.ann_file = 'test.txt'
cfg.data.test.img_prefix = 'images'

cfg.data.train.type = 'mask_detectionDataset'
cfg.data.train.data_root = 'F:/Project/dataset/'
cfg.data.train.ann_file = 'train.txt'
cfg.data.train.img_prefix = 'images'

cfg.data.val.type = 'mask_detectionDataset'
cfg.data.val.data_root = 'F:/Project/dataset/'
cfg.data.val.ann_file = 'val.txt'
cfg.data.val.img_prefix = 'images'

# modify num classes of the model in box head
cfg.model.roi_head.bbox_head.num_classes = 3
cfg.model.roi_head.mask_head.num_classes = 3
# We can still use the pre-trained Mask RCNN model though we do not need to
# use the mask branch
cfg.load_from = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth' 

# Set up working dir to save files and logs.
cfg.work_dir = './swin/mask_rcnn_swin-t-p4-w7_fpn_1x'

# The original learning rate (LR) is set for 8-GPU training.
# We divide it by 8 since we only use one GPU.
cfg.optimizer.lr = 0.02 / 8
cfg.lr_config.warmup = None
cfg.log_config.interval = 10

# Change the evaluation metric since we use customized dataset.
cfg.evaluation.metric = 'mAP'
# We can set the evaluation interval to reduce the evaluation times
cfg.evaluation.interval = 12
# We can set the checkpoint saving interval to reduce the storage cost
cfg.checkpoint_config.interval = 12

# Set seed thus the results are more reproducible
cfg.seed = 0
set_random_seed(0, deterministic=False)
cfg.gpu_ids = range(1)


# We can initialize the logger for training and have a look
# at the final config used for training
print(f'Config:\n{cfg.pretty_text}')

from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.apis import train_detector

# Build dataset
datasets = [build_dataset(cfg.data.train)]

# Build the detector
model = build_detector(
    cfg.model, train_cfg=cfg.get('train_cfg'), test_cfg=cfg.get('test_cfg'))
# Add an attribute for visualization convenience
model.CLASSES = datasets[0].CLASSES

# Create work_dir
mmcv.mkdir_or_exist(os.path.abspath(cfg.work_dir))
train_detector(model, datasets, cfg, distributed=False, validate=True)

below is the error:
Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;D:\anaconda3\envs\openmmlab\lib\multiprocessing\spawn.py&quot;, line 105, in spawn_main
    exitcode = _main(fd)
  File &quot;D:\anaconda3\envs\openmmlab\lib\multiprocessing\spawn.py&quot;, line 114, in _main
    prepare(preparation_data)
  File &quot;D:\anaconda3\envs\openmmlab\lib\multiprocessing\spawn.py&quot;, line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File &quot;D:\anaconda3\envs\openmmlab\lib\multiprocessing\spawn.py&quot;, line 277, in _fixup_main_from_path
    run_name=&quot;__mp_main__&quot;)
  File &quot;D:\anaconda3\envs\openmmlab\lib\runpy.py&quot;, line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File &quot;D:\anaconda3\envs\openmmlab\lib\runpy.py&quot;, line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File &quot;D:\anaconda3\envs\openmmlab\lib\runpy.py&quot;, line 85, in _run_code
    exec(code, run_globals)
  File &quot;F:\Project\config.py&quot;, line 70, in &lt;module&gt;
    datasets = [build_dataset(cfg.data.train)]
  File &quot;D:\anaconda3\envs\openmmlab\lib\site-packages\mmdet\datasets\builder.py&quot;, line 80, in build_dataset
    dataset = build_from_cfg(cfg, DATASETS, default_args)
  File &quot;D:\anaconda3\envs\openmmlab\lib\site-packages\mmcv\utils\registry.py&quot;, line 44, in build_from_cfg
    f'{obj_type} is not in the {registry.name} registry')
KeyError: 'mask_detectionDataset is not in the dataset registry'


maybe add a custom_imports key in your config?
custom_imports = dict(
    imports=['mmdet.datasets.mask_detectionDataset'],
    allow_failed_imports=False)

