open-mmlab / mmdetection

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

unable to register customdataset #7352

Open tusharsvaidya opened 2 years ago

tusharsvaidya commented 2 years ago

hi, I get the following error even after I have updated my __init__.py file and provided my customdataset.py file. Here is the error.

Traceback (most recent call last):
  File "tools/train-det.py", line 196, in <module>
    main()
  File "tools/train-det.py", line 173, in main
    datasets = [build_dataset(cfg.data.train)]
  File "/home/tushar/anaconda3/envs/perception/lib/python3.7/site-packages/mmdet/datasets/builder.py", line 81, in build_dataset
    dataset = build_from_cfg(cfg, DATASETS, default_args)
  File "/home/tushar/anaconda3/envs/perception/lib/python3.7/site-packages/mmcv/utils/registry.py", line 45, in build_from_cfg
    f'{obj_type} is not in the {registry.name} registry')
KeyError: 'IRAVENType is not in the dataset registry'

My current versions of all the packages are

(perception) tushar@tushar-XPS-8940:~/Storage/local_data/perceptionRPM$ pip list | grep "mmcv\|mmdet\|^torch"
mmcv-full                     1.4.6
mmdet                         2.22.0
torch                         1.7.0
torchvision                   0.8.1
jbwang1997 commented 2 years ago

This error indicates your custom dataset hasn't been registered. Please refer to https://github.com/open-mmlab/mmdetection/blob/master/docs/en/tutorials/customize_dataset.md.

ZwwWayne commented 2 years ago

A customized module is not in the registry has the following reasons:

  1. The module is not imported, e.g., not imported through the init.py in packages or not imported through custom_import as introduced in the documentation
  2. The module is imported through init.py, but the mmdet package in the current directory is not used. This happens when you install mmdet through pip install mmdet but modify and want to use the code of mmdet in your working directory. Please make sure the mmdet in your working directory is used.
jpmazellier commented 2 years ago

Dear @ZwwWayne , i'm facing the same issue as described by @tusharsvaidya.

I saw different issues about the problem "MY_DATASET is not in the dataset registry" (eg #5800 or #6149) with different answers but i was not able to make it work for me. As current issue is the most recent on this topic, I'm very interested in your potential help.

My first question is how can we figure out if we are in case 1 (module not imported through init.py) or 2 (module imported through init.py) ? My second question is about case 2 : how can we "make sure the mmdet in your working directory is used" ?

In my case, I created following files/folder : ~/mmdetection/mmdet/datasets/my_dataset.py (following https://github.com/open-mmlab/mmdetection/blob/master/docs/en/tutorials/customize_dataset.md.), with implementation of class 'my_dataset' inheriting from 'CustomDataset' ~/mmdetection/data/my_dataset (with images and annotation file) ~/mmdetection/configs/base/datasets/my_dataset.py (with command "dataset_type = 'my_dataset' and rest of config) ~/mmdetection/configs/my_config/my_config.py (with base pointing to base/models/faster-rcnn and base/datasets/my_dataset.py)

and I also modified ~/mmdetection/mmdet/datasets/init.py to include 'MY_DATASET' in all list

then i launch "python ~mmdetection/tools/train.py ~/mmdetection/configs/my_config/my_config.py

but i'm stuck with "MY_DATASET is not in the dataset registry"

Note : as mentionned in issue #5800, i tried inserting "import pdb; pdb.set_trace()" in ~/mmdetection/mmdet/datasets/my_dataset.py before section "@DATASETS.register_module()" and with ~/mmdetection/tools/train.py configs/my_config/my_config.py the training did not stopped and it blocked at "MY_DATASET is not in the dataset registry". Note : if i make my dataset compliant with CocoDataset format, i can run training and testing fine but i need a customized dataset for my project

Thanks for your valuable help !

Xuebei12 commented 2 years ago

Dear @jpmazellier, I got the same issue after updating the latest mmdet version through pip install --upgrade mmdet. However at the very beginning, I installed mmdetection through git clone, that's mean in my environment two mmdet packages existed, and all scripts in mmdetection used the relative imports so that the custom dataset cannot identify where is the mmdet directory. That's why my custom dataset cannot registry in the dataset.

Solution: find the mmdet packages in python site-packages and then uninstall them, reserve the git clone mmdet package

niqbal996 commented 6 months ago

Hi all,

I followed the suggestion of @Xuebei12 and indeed solved the problem. If you install via pip install "mmsegmentation>=1.0.0" and then modify your source, it will not be found by your python environment even though you have followed the documentation. You need to use the Case a: If you develop and run mmseg directly, install it from source: since you are using your own source code and do:

git clone -b main https://github.com/open-mmlab/mmsegmentation.git
cd mmsegmentation
pip install -v -e .

I also had to set export PYTHONPATH=$PYTHONPATH:/your/mmsegmentation/directory/where/you/built/it to make sure it finds my compiled from source version of mmseg.

Cheers.