open-mmlab / mmdetection

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

SUNRGBDDataset is not in the dataset registry #5800

Closed emirhanKural closed 3 years ago

emirhanKural commented 3 years ago

Describe the bug

I have tried to create my own dataset class by following this but I got this error : SUNRGBDDataset is not in the dataset registry. I checked out similar issues but there isn't any fixed solution there. Also I added name of the class name in __init__.py.

Second error: Moreover I can run MMDet_Tutorial.ipynb by this new class and new dataset. Because of that I couldn't train normal way, I converted MMDet_Tutorial.ipynb to a .py file to train dataset in terminal. It is working but I cannot get any log file. It only produced None.log.json. I hope it will give weights when epoch raise checkpoint_config.interval but not giving log file made me suspicious

Reproduction

  1. What command or script did you run?
python tools/train.py configs/_base_/sunrgbd.py
  1. Did you make any modifications on the code or config? Did you understand what you have modified?
    I modified load_annotation func of my customized class to convert sunrgbd format to the middle format.
    I created sunrgbd.py in mmdet/datasets/ and added class name in mmdet/datasets/__init__.py
  2. What dataset did you use? SUN RGB-D

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment information and paste it here.
    
    sys.platform: linux
    Python: 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37) [GCC 9.3.0]
    CUDA available: True
    GPU 0: Tesla K80
    CUDA_HOME:
    GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
    PyTorch: 1.4.0
    PyTorch compiling details: PyTorch built with:
    - GCC 7.3
    - Intel(R) oneAPI Math Kernel Library Version 2021.3-Product Build 20210617 for Intel(R) 64 architecture applications
    - Intel(R) MKL-DNN v0.21.1 (Git Hash 7d2fd500bc78936d1d648ca713b901012f470dbc)
    - OpenMP 201511 (a.k.a. OpenMP 4.5)
    - NNPACK is enabled
    - CUDA Runtime 10.0
    - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
    - CuDNN 7.6.3
    - Magma 2.5.1
    - Build settings: BLAS=MKL, BUILD_NAMEDTENSOR=OFF, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Wno-stringop-overflow, DISABLE_NUMA=1, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF,

TorchVision: 0.5.0 OpenCV: 4.5.3 MMCV: 1.3.9 MMCV Compiler: GCC 7.5 MMCV CUDA Compiler: 10.0 MMDetection: 2.14.0+4853ea1


**Error traceback**
If applicable, paste the error trackback here.

```none
..................................
..................................
..................................
runner = dict(type='EpochBasedRunner', max_epochs=96)
checkpoint_config = dict(interval=12)
log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')])
custom_hooks = [dict(type='NumClassCheckHook')]
dist_params = dict(backend='nccl')
log_level = 'INFO'
resume_from = None
workflow = [('train', 1)]
work_dir = './work_dirs/sunrgbd'
gpu_ids = range(0, 1)

/home/ubuntu/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/core/anchor/builder.py:16: UserWarning: ``build_anchor_generator`` would be deprecated soon, please use ``build_prior_generator``
  '``build_anchor_generator`` would be deprecated soon, please use '
Traceback (most recent call last):
  File "tools/train.py", line 188, in <module>
    main()
  File "tools/train.py", line 164, in main
    datasets = [build_dataset(cfg.data.train)]
  File "/home/ubuntu/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/datasets/builder.py", line 71, in build_dataset
    dataset = build_from_cfg(cfg, DATASETS, default_args)
  File "/home/ubuntu/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/utils/registry.py", line 44, in build_from_cfg
    f'{obj_type} is not in the {registry.name} registry')
KeyError: 'SunrgbdDataset is not in the dataset registry'

My Customized CLass: mmdet/datasets/sunrgbd.py

import copy
import os.path as osp

import mmcv
import numpy as np

from .builder import DATASETS
from .custom import CustomDataset

@DATASETS.register_module()
class SunrgbdDataset(CustomDataset):

    CLASSES = ('void',
                'wall', 'floor', 'cabinet', 'bed', 'chair',
                'sofa', 'table', 'door', 'window', 'bookshelf',
                'picture', 'counter', 'blinds', 'desk', 'shelves',
                'curtain', 'dresser', 'pillow', 'mirror', 'floor_mat',
                'clothes', 'ceiling', 'books', 'refridgerator', 'television',
                'paper', 'towel', 'shower_curtain', 'box', 'whiteboard',
                'person', 'night_stand', 'toilet', 'sink', 'lamp',
                'bathtub', 'bag', 'otherstructure', 'otherfurniture', 'otherprop')

    def load_annotations(self, ann_file):
        cat2label = {k: i for i, k in enumerate(self.CLASSES)}
        # load image list from file
        image_list = mmcv.load(ann_file)

        data_infos = []
        # convert annotations to middle format
        for image_id in image_list.keys():

            filename = f'{self.img_prefix}/{image_id}.jpeg'
            height, width = image_list[image_id]["height"], image_list[image_id]["width"]

            data_info = dict(filename=f'{image_id}.jpeg', width=width, height=height)

            # load annotations

            bbox_names = image_list[image_id]["cls_names"]
            bboxes = image_list[image_id]["bboxes"]

            gt_bboxes = []
            gt_labels = []
            gt_bboxes_ignore = []
            gt_labels_ignore = []

            # filter 'DontCare'
            for bbox_name, bbox in zip(bbox_names, bboxes):
                if bbox_name in cat2label:
                    gt_labels.append(cat2label[bbox_name])
                    gt_bboxes.append(bbox)
                else:
                    gt_labels_ignore.append(-1)
                    gt_bboxes_ignore.append(bbox)

            data_anno = dict(
                bboxes=np.array(gt_bboxes, dtype=np.float32).reshape(-1, 4),
                labels=np.array(gt_labels, dtype=np.int64),
                bboxes_ignore=np.array(gt_bboxes_ignore,
                                       dtype=np.float32).reshape(-1, 4),
                labels_ignore=np.array(gt_labels_ignore, dtype=np.int64))

            data_info.update(ann=data_anno)
            data_infos.append(data_info)

        return data_infos

My Customized CLass: mmdet/datasets/__init__.py

from .builder import DATASETS, PIPELINES, build_dataloader, build_dataset
from .cityscapes import CityscapesDataset
from .coco import CocoDataset
from .coco_panoptic import CocoPanopticDataset
from .custom import CustomDataset
from .sunrgbd import SunrgbdDataset
from .dataset_wrappers import (ClassBalancedDataset, ConcatDataset,
                               RepeatDataset)
from .deepfashion import DeepFashionDataset
from .lvis import LVISDataset, LVISV1Dataset, LVISV05Dataset
from .samplers import DistributedGroupSampler, DistributedSampler, GroupSampler
from .utils import (NumClassCheckHook, get_loading_pipeline,
                    replace_ImageToTensor)
from .voc import VOCDataset
from .wider_face import WIDERFaceDataset
from .xml_style import XMLDataset

__all__ = [
    'SunrgbdDataset','CustomDataset', 'XMLDataset', 'CocoDataset', 'DeepFashionDataset',
    'VOCDataset', 'CityscapesDataset', 'LVISDataset', 'LVISV05Dataset',
    'LVISV1Dataset', 'GroupSampler', 'DistributedGroupSampler',
    'DistributedSampler', 'build_dataloader', 'ConcatDataset', 'RepeatDataset',
    'ClassBalancedDataset', 'WIDERFaceDataset', 'DATASETS', 'PIPELINES',
    'build_dataset', 'replace_ImageToTensor', 'get_loading_pipeline',
    'NumClassCheckHook', 'CocoPanopticDataset'
]
jshilong commented 3 years ago

Please make sure that the mmdet you use is modified which adding the SunrgbdDataset,I am afraid you are using the version installed in the environment before

jshilong commented 3 years ago

You can check it very easily by

import copy
import os.path as osp

import mmcv
import numpy as np

from .builder import DATASETS
from .custom import CustomDataset

import pdb;pdb.set_trace()

@DATASETS.register_module()
class SunrgbdDataset(CustomDataset):

    CLASSES = ('void',
                'wall', 'floor', 'cabinet', 'bed', 'chair',
                'sofa', 'table', 'door', 'window', 'bookshelf',
                'picture', 'counter', 'blinds', 'desk', 'shelves',
                'curtain', 'dresser', 'pillow', 'mirror', 'floor_mat',
                'clothes', 'ceiling', 'books', 'refridgerator', 'television',
                'paper', 'towel', 'shower_curtain', 'box', 'whiteboard',
                'person', 'night_stand', 'toilet', 'sink', 'lamp',
                'bathtub', 'bag', 'otherstructure', 'otherfurniture', 'otherprop')

    def load_annotations(self, ann_file):
        cat2label = {k: i for i, k in enumerate(self.CLASSES)}
        # load image list from file
        image_list = mmcv.load(ann_file)

        data_infos = []
        # convert annotations to middle format
        for image_id in image_list.keys():

            filename = f'{self.img_prefix}/{image_id}.jpeg'
            height, width = image_list[image_id]["height"], image_list[image_id]["width"]

            data_info = dict(filename=f'{image_id}.jpeg', width=width, height=height)

            # load annotations

            bbox_names = image_list[image_id]["cls_names"]
            bboxes = image_list[image_id]["bboxes"]

            gt_bboxes = []
            gt_labels = []
            gt_bboxes_ignore = []
            gt_labels_ignore = []

            # filter 'DontCare'
            for bbox_name, bbox in zip(bbox_names, bboxes):
                if bbox_name in cat2label:
                    gt_labels.append(cat2label[bbox_name])
                    gt_bboxes.append(bbox)
                else:
                    gt_labels_ignore.append(-1)
                    gt_bboxes_ignore.append(bbox)

            data_anno = dict(
                bboxes=np.array(gt_bboxes, dtype=np.float32).reshape(-1, 4),
                labels=np.array(gt_labels, dtype=np.int64),
                bboxes_ignore=np.array(gt_bboxes_ignore,
                                       dtype=np.float32).reshape(-1, 4),
                labels_ignore=np.array(gt_labels_ignore, dtype=np.int64))

            data_info.update(ann=data_anno)
            data_infos.append(data_info)

        return data_infos

then launch the training, if it can not stop at pdb.set_trace(), we can know you do not launch the modified version

emirhanKural commented 3 years ago

Hi @jshilong ! Thank you for your response ^^

I added pdb.set_trace() and still got the same error. It seems you are right about using env mmdet. So what should I do to use modified version? Should I remove mmdet from env ?

emirhanKural commented 3 years ago

OK I got it ^^ hah.. It worked when I moved train.py file from tools to mmdetection folder...

Thank you for your response again !!!

jshilong commented 3 years ago

Feel free to reopen the issue if there is any question