Closed camongman closed 1 year ago
I've met this error too. Here's my solution: 1.Create a new dataset class based on CocoDataset:
# Copyright (c) OpenMMLab. All rights reserved.
import copy
import os.path as osp
from typing import List, Union
from mmengine.fileio import get_local_path
from mmdet.registry import DATASETS
from .api_wrappers import COCO
from .coco import CocoDataset
@DATASETS.register_module()
class CocoNewDataset(CocoDataset):
"""Dataset for COCO."""
METAINFO = {
'classes':
('excavator',),
# palette is a list of color tuples, which is used for visualization.
'palette':
[(220, 20, 60), ]
}
COCOAPI = COCO
# ann_id is unique in coco dataset.
ANN_ID_UNIQUE = True
2.Change dataset_type in config file:
dataset_type = 'CocoNewDataset'
train_dataloader = dict(
dataset=dict(
type=dataset_type,
data_root=data_root,
metainfo=metainfo,
data_prefix=dict(img='train/'),
ann_file='train.json',
filter_cfg=dict(filter_empty_gt=True, min_size=32),
pipeline=train_pipeline,
backend_args=backend_args))
val_dataloader = dict(
dataset=dict(
type=dataset_type,
data_root=data_root,
data_prefix=dict(img='val/'),
ann_file='val.json',
test_mode=True,
pipeline=test_pipeline,
backend_args=backend_args))
test_dataloader = val_dataloader
Also, this error may occur when the category name in the json file does not match the one in metainfo, i guess.
I guess it may be because you didn't add the newly created dataset class to /mmdet/datasets/__init__.py
# Copyright (c) OpenMMLab. All rights reserved.
from .ade20k import (ADE20KInstanceDataset, ADE20KPanopticDataset,
ADE20KSegDataset)
from .base_det_dataset import BaseDetDataset
from .base_semseg_dataset import BaseSegDataset
from .base_video_dataset import BaseVideoDataset
from .cityscapes import CityscapesDataset
from .coco import CocoDataset
from .coco_caption import CocoCaptionDataset
from .coco_panoptic import CocoPanopticDataset
from .coco_semantic import CocoSegDataset
from .crowdhuman import CrowdHumanDataset
from .dataset_wrappers import MultiImageMixDataset
from .deepfashion import DeepFashionDataset
from .dsdl import DSDLDetDataset
from .isaid import iSAIDDataset
from .lvis import LVISDataset, LVISV1Dataset, LVISV05Dataset
from .mot_challenge_dataset import MOTChallengeDataset
from .objects365 import Objects365V1Dataset, Objects365V2Dataset
from .openimages import OpenImagesChallengeDataset, OpenImagesDataset
from .refcoco import RefCocoDataset
from .reid_dataset import ReIDDataset
from .samplers import (AspectRatioBatchSampler, ClassAwareSampler,
GroupMultiSourceSampler, MultiSourceSampler,
TrackAspectRatioBatchSampler, TrackImgSampler)
from .utils import get_loading_pipeline
from .voc import VOCDataset
from .wider_face import WIDERFaceDataset
from .xml_style import XMLDataset
from .youtube_vis_dataset import YouTubeVISDataset
from .excavator_dataset import ExcavatorDataset
__all__ = [
'XMLDataset', 'CocoDataset', 'DeepFashionDataset', 'VOCDataset',
'CityscapesDataset', 'LVISDataset', 'LVISV05Dataset', 'LVISV1Dataset',
'WIDERFaceDataset', 'get_loading_pipeline', 'CocoPanopticDataset',
'MultiImageMixDataset', 'OpenImagesDataset', 'OpenImagesChallengeDataset',
'AspectRatioBatchSampler', 'ClassAwareSampler', 'MultiSourceSampler',
'GroupMultiSourceSampler', 'BaseDetDataset', 'CrowdHumanDataset',
'Objects365V1Dataset', 'Objects365V2Dataset', 'DSDLDetDataset',
'BaseVideoDataset', 'MOTChallengeDataset', 'TrackImgSampler',
'ReIDDataset', 'YouTubeVISDataset', 'TrackAspectRatioBatchSampler',
'ADE20KPanopticDataset', 'CocoCaptionDataset', 'RefCocoDataset',
'BaseSegDataset', 'ADE20KSegDataset', 'CocoSegDataset',
'ADE20KInstanceDataset', 'iSAIDDataset',
'ExcavatorDataset',
]
pip install -v -e .
And as far as I can remember, it doesn't matter if metainfo
is in config file or not.
@hito2448 Thank you very much. I've double-checked it here and there and I found out that there was a typo in the label name in the json file. excavaotor -> excavator I'd appreciate you again. Have a good day!!
modify main function in tools/train.py: from mmdet.datasets.coco import CocoDataset CocoDataset.METAINFO = { 'classes': ('fire',),
'palette':
[(220, 20, 60), ]
}
I know that there was a similar issue here but it's not helpful to me. I've tested with my custom dataset and initial model is like this.
Please, help me and welcome to any comments. Thanks a lot in advance.
My environment is the docker desktop in win10 with nvidia rtx 3090 and I used the "Dockerfile" here and installed through it.
Installation info. (please, note that python and torch version below might be different because I upgraded and tested them. But i'm sure it's not related to this issue.).
config is like this below.(no big deal. I just fixed a few lines with metainfo)
Errros's here: