open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
8.3k stars 2.62k forks source link

Training error reported #3199

Open chenhuagg opened 1 year ago

chenhuagg commented 1 year ago

File "d:\mmsegmentation-main\mmseg\evaluation\metrics\iou_metric.py", line 77, in process num_classes = len(self.dataset_meta['classes']) KeyError: 'classes'

mm-assistant[bot] commented 1 year ago

We recommend using English or English & Chinese for issues so that we could have broader discussion.

chenhuagg commented 1 year ago

from mmseg.registry import DATASETS from .basesegdataset import BaseSegDataset

@DATASETS.register_module() class GIDDataset(BaseSegDataset): METAINFO = dict(

CLASSES =('built-up','farmland','forest','meadow','water'),

PALETTE = [[0, 0, 255], [0, 255, 0],[255, 255, 0],[0, 255, 255], [255, 0, 0]])

def __init__(self,
             img_suffix='.jpg',
             seg_map_suffix='.png',
             reduce_zero_label=True,
             **kwargs) -> None:
    super().__init__(
        img_suffix=img_suffix,
        seg_map_suffix=seg_map_suffix,
        reduce_zero_label=reduce_zero_label,
        **kwargs)
xiexinch commented 1 year ago

Hi @chenhuagg, might follow our document to customize your dataset. https://mmsegmentation.readthedocs.io/en/latest/advanced_guides/add_datasets.html

We have supported GID dataset at https://github.com/open-mmlab/mmsegmentation/tree/main/projects/gid_dataset/mmseg/datasets

qzw2416 commented 1 year ago

Traceback (most recent call last): File "tools/train.py", line 104, in main() File "tools/train.py", line 93, in main runner = Runner.from_cfg(cfg) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\runner\runner.py", line 443, in from_cfg runner = cls( File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\runner\runner.py", line 397, in init self.visualizer = self.build_visualizer(visualizer) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\runner\runner.py", line 784, in build_visualizer return VISUALIZERS.build(visualizer) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\registry\registry.py", line 570, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\registry\build_functions.py", line 144, in build_from_cfg raise type(e)( ValueError: class SegLocalVisualizer in mmseg/visualization/local_visualizer.py: Unrecognized dataset: cityscapes (openmmlab001) PS E:\qzw\mmsegmentation-dev-1.x> (openmmlab001) PS E:\mmsegmentation-master> python tools/train.py configs/swin/upernet_swin_tiny_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py

I wanna train my custom dataset ,i change mu code ,but i always meet this error ,i do not know why it is can you help me

qzw2416 commented 1 year ago

07/29 17:52:26 - mmengine - INFO - Config: norm_cfg = dict(type='BN', requires_grad=True) backbone_norm_cfg = dict(type='LN', requires_grad=True) data_preprocessor = dict( type='SegDataPreProcessor', mean=[ 123.675, 116.28, 103.53, ], std=[ 58.395, 57.12, 57.375, ], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=( 512, 512, )) model = dict( type='EncoderDecoder', data_preprocessor=dict( type='SegDataPreProcessor', mean=[ 123.675, 116.28, 103.53, ], std=[ 58.395, 57.12, 57.375, ], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=( 512, 512, )), pretrained=None, backbone=dict( type='SwinTransformer', pretrain_img_size=224, embed_dims=96, patch_size=4, window_size=7, mlp_ratio=4, depths=[ 2, 2, 6, 2, ], num_heads=[ 3, 6, 12, 24, ], strides=( 4, 2, 2, 2, ), out_indices=( 0, 1, 2, 3, ), qkv_bias=True, qk_scale=None, patch_norm=True, drop_rate=0.0, attn_drop_rate=0.0, drop_path_rate=0.3, use_abs_pos_embed=False, act_cfg=dict(type='GELU'), norm_cfg=dict(type='LN', requires_grad=True), init_cfg=dict( type='Pretrained', checkpoint= 'https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/swin/swin_tiny_patch4_window7_224_20220317-1cdeb081.pth' )), decode_head=dict( type='UPerHead', in_channels=[ 96, 192, 384, 768, ], in_index=[ 0, 1, 2, 3, ], pool_scales=( 1, 2, 3, 6, ), channels=512, dropout_ratio=0.1, num_classes=150, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), auxiliary_head=dict( type='FCNHead', in_channels=384, in_index=2, channels=256, num_convs=1, concat_input=False, dropout_ratio=0.1, num_classes=150, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), train_cfg=dict(), test_cfg=dict(mode='whole')) dataset_type = 'HuoDataset' data_root = 'E:/2021/test-on/pretrain' split_dir = 'INFO/' img_path = 'train' seg_map_path = 'label' img_scale = ( 512, 512, ) crop_size = ( 512, 512, ) batch_size = 4 train_tif_pipeline = [ dict(type='LoadTIFImageFromFile'), dict(type='LoadTIFAnnotations2C', reduce_zero_label=False), dict(type='Resize', scale=( 512, 512, ), keep_ratio=True), dict(type='RandomCrop', crop_size=( 512, 512, ), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs'), dict(type='Collect', keys=[ 'img', 'gt_semantic_seg', ]), ] val_tif_pipeline = [ dict(type='LoadTIFImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=( 512, 512, ), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='LoadTIFAnnotations2C', reduce_zero_label=False), dict(type='PackSegInputs'), dict(type='Collect', keys=[ 'img', 'gt_semantic_seg', ]), ]), ] train_dataloader = dict( batch_size=2, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), dataset=dict( type='HuoDataset', data_root='E:/2021/test-on/pretrain', data_prefix=dict(img_path='train', seg_map_path='label'), pipeline=[ dict(type='LoadTIFImageFromFile'), dict(type='LoadTIFAnnotations2C', reduce_zero_label=False), dict(type='Resize', scale=( 512, 512, ), keep_ratio=True), dict( type='RandomCrop', crop_size=( 512, 512, ), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs'), dict(type='Collect', keys=[ 'img', 'gt_semantic_seg', ]), ])) val_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='HuoDataset', data_root='E:/2021/test-on/pretrain', data_prefix=dict(img_path='train', seg_map_path='label'), pipeline=[ dict(type='LoadTIFImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=( 512, 512, ), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='LoadTIFAnnotations2C', reduce_zero_label=False), dict(type='PackSegInputs'), dict(type='Collect', keys=[ 'img', 'gt_semantic_seg', ]), ]), ])) test_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='HuoDataset', data_root='E:/2021/test-on/pretrain', data_prefix=dict(img_path='train', seg_map_path='label'), pipeline=[ dict(type='LoadTIFImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=( 512, 512, ), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='LoadTIFAnnotations2C', reduce_zero_label=False), dict(type='PackSegInputs'), dict(type='Collect', keys=[ 'img', 'gt_semantic_seg', ]), ]), ])) val_cfg = dict(interval=1) val_evaluator = dict( type='IoUMetric', num_classes=2, ignore_index=255, metric_options=dict(mIoU=dict(report_binary=False))) test_evaluator = dict( type='IoUMetric', num_classes=2, ignore_index=255, metric_options=dict(mIoU=dict(report_binary=False))) default_scope = 'mmseg' env_cfg = dict( cudnn_benchmark=True, mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), dist_cfg=dict(backend='nccl')) vis_backends = [ dict(type='LocalVisBackend'), ] visualizer = dict( type='SegLocalVisualizer', vis_backends=[ dict(type='LocalVisBackend'), ], name='visualizer') log_processor = dict(by_epoch=False) log_level = 'INFO' load_from = None resume = False tta_model = dict(type='SegTTAModel') checkpoint_file = 'https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/swin/swin_tiny_patch4_window7_224_20220317-1cdeb081.pth' optim_wrapper = dict( delete=True, type='OptimWrapper', optimizer=dict( type='AdamW', lr=6e-05, betas=( 0.9, 0.999, ), weight_decay=0.01), paramwise_cfg=dict( custom_keys=dict( absolute_pos_embed=dict(decay_mult=0.0), relative_position_bias_table=dict(decay_mult=0.0), norm=dict(decay_mult=0.0)))) param_scheduler = [ dict( type='LinearLR', start_factor=1e-06, by_epoch=False, begin=0, end=1500), dict( type='PolyLR', eta_min=0.0, power=1.0, begin=1500, end=160000, by_epoch=False), ] train_cfg = dict(loss_weight=[ 0.4, 0.6, ]) test_cfg = dict(mode='whole') launcher = 'none' work_dir = './work_dirs\swin-tiny-patch4-window7-in1k-pre_upernet_8xb2-160k_ade20k-512x512'

Traceback (most recent call last): File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\registry\build_functions.py", line 120, in build_from_cfg obj = obj_cls.get_instance(args) # type: ignore File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\visualization\visualizer.py", line 1181, in get_instance instance = super().get_instance(name, kwargs) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\utils\manager.py", line 110, in get_instance instance = cls(name=name, **kwargs) # type: ignore File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmsegmentation-1.1.1-py3.8.egg\mmseg\visualization\local_visualizer.py", line 77, in init self.set_dataset_meta(palette, classes, dataset_name) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmsegmentation-1.1.1-py3.8.egg\mmseg\visualization\local_visualizer.py", line 146, in set_dataset_meta classes = classes if classes else get_classes(dataset_name) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmsegmentation-1.1.1-py3.8.egg\mmseg\utils\class_names.py", line 474, in get_classes raise ValueError(f'Unrecognized dataset: {dataset}') ValueError: Unrecognized dataset: cityscapes

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "tools/train.py", line 104, in main() File "tools/train.py", line 93, in main runner = Runner.from_cfg(cfg) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\runner\runner.py", line 443, in from_cfg runner = cls( File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\runner\runner.py", line 397, in init self.visualizer = self.build_visualizer(visualizer) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\runner\runner.py", line 784, in build_visualizer return VISUALIZERS.build(visualizer) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\registry\registry.py", line 570, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "C:\Users\WB2\miniconda3\envs\openmmlab001\lib\site-packages\mmengine\registry\build_functions.py", line 144, in build_from_cfg raise type(e)( ValueError: class SegLocalVisualizer in mmseg/visualization/local_visualizer.py: Unrecognized dataset: cityscapes (openmmlab001) PS E:\qzw\mmsegmentation-dev-1.x> this is a part of my code