open-mmlab / mmsegmentation

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

AttributeError: 'SegDataSample' object has no attribute 'gt_edge_map' #3350

Open HePengguang opened 1 year ago

HePengguang commented 1 year ago

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. The bug has not been fixed in the latest version.

Describe the bug When I ran the pidnet_s on my own seg dataset, I got this error: "AttributeError: 'SegDataSample' object has no attribute 'gt_edge_map'".

Reproduction

  1. What command or script did you run? python .\tools\train.py .\configs\pidnet\pidnet-s_2xb6-6k_224x224-feces.py. "feces" is the name of my dataset.

  2. Did you make any modifications on the code or config? Did you understand what you have modified? Yes, I know the meaning of config file, and I just modified the crop_size.

Environment sys.platform: win32 Python: 3.8.17 (default, Jul 5 2023, 20:44:21) [MSC v.1916 64 bit (AMD64)] CUDA available: True
numpy_random_seed: 2147483648
GPU 0: NVIDIA GeForce RTX 3080
CUDA_HOME: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7
NVCC: Cuda compilation tools, release 11.7, V11.7.64
MSVC: 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.28.29334 版
GCC: n/a PyTorch: 1.13.1+cu117 PyTorch compiling details: PyTorch built with:

TorchVision: 0.14.1+cu117 OpenCV: 4.8.0 MMEngine: 0.8.4 MMSegmentation: 1.1.0

Error traceback

09/26 17:01:39 - mmengine - INFO - Config: checkpoint_file = 'https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/pidnet/pidnet-s_imagenet1k_20230306-715e6273.pth' class_weight = [ 0.8, 0.9, 1.1, 1.1, ] crop_size = ( 224, 224, ) data_preprocessor = dict( bgr_to_rgb=True, mean=[ 123.675, 116.28, 103.53, ], pad_val=0, seg_pad_val=255, size=( 224, 224, ), std=[ 58.395, 57.12, 57.375, ], type='SegDataPreProcessor') data_root = 'D:\Allcode\mmlab\mmsegmentation-dev-1.x\data\data' dataset_type = 'Feces' default_hooks = dict( checkpoint=dict(by_epoch=False, interval=200, type='CheckpointHook'), logger=dict(interval=5, log_metric_by_epoch=False, type='LoggerHook'), param_scheduler=dict(type='ParamSchedulerHook'), sampler_seed=dict(type='DistSamplerSeedHook'), timer=dict(type='IterTimerHook'), visualization=dict(type='SegVisualizationHook')) default_scope = 'mmseg' env_cfg = dict( cudnn_benchmark=True, dist_cfg=dict(backend='nccl'), mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0)) img_ratios = [ 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, ] img_scale = ( 448, 448, ) iters = 6000 launcher = 'none' load_from = None log_level = 'INFO' log_processor = dict(by_epoch=False) model = dict( backbone=dict( act_cfg=dict(inplace=True, type='ReLU'), align_corners=False, channels=32, in_channels=3, init_cfg=dict( checkpoint= 'https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/pidnet/pidnet-s_imagenet1k_20230306-715e6273.pth', type='Pretrained'), norm_cfg=dict(requires_grad=True, type='SyncBN'), num_branch_blocks=3, num_stem_blocks=2, ppm_channels=96, type='PIDNet'), data_preprocessor=dict( bgr_to_rgb=True, mean=[ 123.675, 116.28, 103.53, ], pad_val=0, seg_pad_val=255, size=( 224, 224, ), std=[ 58.395, 57.12, 57.375, ], type='SegDataPreProcessor'), decode_head=dict( act_cfg=dict(inplace=True, type='ReLU'), align_corners=True, channels=128, in_channels=128, loss_decode=[ dict( class_weight=[ 0.8, 0.9, 1.1, 1.1, ], loss_weight=0.4, type='CrossEntropyLoss', use_sigmoid=False), dict( class_weight=[ 0.8, 0.9, 1.1, 1.1, ], loss_weight=1.0, min_kept=131072, thres=0.9, type='OhemCrossEntropy'), dict(loss_weight=20.0, type='BoundaryLoss'), dict( class_weight=[ 0.8, 0.9, 1.1, 1.1, ], loss_weight=1.0, min_kept=131072, thres=0.9, type='OhemCrossEntropy'), ], norm_cfg=dict(requires_grad=True, type='SyncBN'), num_classes=4, type='PIDHead'), test_cfg=dict(mode='whole'), train_cfg=dict(), type='EncoderDecoder') norm_cfg = dict(requires_grad=True, type='SyncBN') optim_wrapper = dict( clip_grad=None, optimizer=dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0005), type='OptimWrapper') optimizer = dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0005) param_scheduler = [ dict( begin=0, by_epoch=False, end=6000, eta_min=0, power=0.9, type='PolyLR'), ] randomness = dict(seed=304) resume = False test_cfg = dict(type='TestLoop') test_dataloader = dict( batch_size=1, dataset=dict( data_prefix=dict( img_path='images/validation', seg_map_path='annotations/validation'), data_root='D:\Allcode\mmlab\mmsegmentation-dev-1.x\data\data', pipeline=[ dict(type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 448, 448, ), type='Resize'), dict(type='LoadAnnotations'), dict(type='PackSegInputs'), ], type='Feces'), num_workers=2, persistent_workers=True, sampler=dict(shuffle=False, type='DefaultSampler')) test_evaluator = dict( iou_metrics=[ 'mDice', 'mIoU', 'mFscore', ], type='IoUMetric') test_pipeline = [ dict(type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 448, 448, ), type='Resize'), dict(type='LoadAnnotations'), dict(type='PackSegInputs'), ] train_cfg = dict(max_iters=6000, type='IterBasedTrainLoop', val_interval=200) train_dataloader = dict( batch_size=64, dataset=dict( dataset=dict( data_prefix=dict( img_path='images/training', seg_map_path='annotations/training'), data_root='D:\Allcode\mmlab\mmsegmentation-dev-1.x\data\data', pipeline=[ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( keep_ratio=True, ratio_range=( 0.5, 2.0, ), scale=( 448, 448, ), type='RandomResize'), dict(prob=0.5, type='RandomFlip'), dict(type='PhotoMetricDistortion'), dict( cat_max_ratio=0.75, crop_size=( 224, 224, ), type='RandomCrop'), dict(type='PackSegInputs'), ], type='Feces'), times=40000, type='RepeatDataset'), num_workers=4, persistent_workers=True, sampler=dict(shuffle=True, type='InfiniteSampler')) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( keep_ratio=True, ratio_range=( 0.5, 2.0, ), scale=( 448, 448, ), type='RandomResize'), dict(cat_max_ratio=0.75, crop_size=( 224, 224, ), type='RandomCrop'), dict(prob=0.5, type='RandomFlip'), dict(type='PhotoMetricDistortion'), dict(edge_width=4, type='GenerateEdge'), dict(type='PackSegInputs'), ] tta_model = dict(type='SegTTAModel') tta_pipeline = [ dict(backend_args=None, type='LoadImageFromFile'), dict( transforms=[ [ dict(keep_ratio=True, scale_factor=0.5, type='Resize'), dict(keep_ratio=True, scale_factor=0.75, type='Resize'), dict(keep_ratio=True, scale_factor=1.0, type='Resize'), dict(keep_ratio=True, scale_factor=1.25, type='Resize'), dict(keep_ratio=True, scale_factor=1.5, type='Resize'), dict(keep_ratio=True, scale_factor=1.75, type='Resize'), ], [ dict(direction='horizontal', prob=0.0, type='RandomFlip'), dict(direction='horizontal', prob=1.0, type='RandomFlip'), ], [ dict(type='LoadAnnotations'), ], [ dict(type='PackSegInputs'), ], ], type='TestTimeAug'), ] val_cfg = dict(type='ValLoop') val_dataloader = dict( batch_size=1, dataset=dict( data_prefix=dict( img_path='images/validation', seg_map_path='annotations/validation'), data_root='D:\Allcode\mmlab\mmsegmentation-dev-1.x\data\data', pipeline=[ dict(type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 448, 448, ), type='Resize'), dict(type='LoadAnnotations'), dict(type='PackSegInputs'), ], type='Feces'), num_workers=2, persistent_workers=True, sampler=dict(shuffle=False, type='DefaultSampler')) val_evaluator = dict( iou_metrics=[ 'mDice', 'mIoU', 'mFscore', ], type='IoUMetric') vis_backends = [ dict(type='LocalVisBackend'), dict(type='TensorboardVisBackend'), ] visualizer = dict( name='visualizer', type='SegLocalVisualizer', vis_backends=[ dict(type='LocalVisBackend'), dict(type='TensorboardVisBackend'), ]) work_dir = './work_dirs\pidnet-s_2xb6-6k_224x224-feces'

2023-09-26 17:01:40.657974: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found 2023-09-26 17:01:40.658149: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\builder.py:36: UserWarning: build_loss would be deprecated soon, please use mmseg.registry.MODELS.build() warnings.warn('build_loss would be deprecated soon, please use ' d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\losses\cross_entropy_loss.py:235: UserWarning: Default avg_non_ignore is False, if you would like to ignore the certain label and average loss over non-ignore labels, which is the same with PyTorch officia l cross_entropy, set avg_non_ignore=True. warnings.warn( 09/26 17:01:41 - mmengine - INFO - Distributed training is not used, all SyncBatchNorm (SyncBN) layers in the model will be automatically reverted to BatchNormXd layers if they are used. d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\engine\hooks\visualization_hook.py:61: UserWarning: The draw is False, it means that the hook for visualization will not take effect. The results will NOT be visualized or stored. warnings.warn('The draw is False, it means that the ' 09/26 17:01:41 - mmengine - INFO - Hooks will be executed in the following order: before_run: (VERY_HIGH ) RuntimeInfoHook (BELOW_NORMAL) LoggerHook

before_train: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (VERY_LOW ) CheckpointHook

before_train_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (NORMAL ) DistSamplerSeedHook

before_train_iter: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook

after_train_iter: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook

after_train_epoch: (NORMAL ) IterTimerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook

before_val: (VERY_HIGH ) RuntimeInfoHook

before_val_epoch: (NORMAL ) IterTimerHook

before_val_iter: (NORMAL ) IterTimerHook

after_val_iter: (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook

after_val_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (BELOW_NORMAL) LoggerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook

after_val: (VERY_HIGH ) RuntimeInfoHook

after_train: (VERY_HIGH ) RuntimeInfoHook (VERY_LOW ) CheckpointHook

before_test: (VERY_HIGH ) RuntimeInfoHook

before_test_epoch: (NORMAL ) IterTimerHook

before_test_iter: (NORMAL ) IterTimerHook

after_test_iter: (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook

(VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (BELOW_NORMAL) LoggerHook

after_test: (VERY_HIGH ) RuntimeInfoHook

after_run: (BELOW_NORMAL) LoggerHook

09/26 17:02:04 - mmengine - WARNING - The prefix is not set in metric class IoUMetric. 09/26 17:02:09 - mmengine - INFO - Loads checkpoint by http backend from path: https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/pidnet/pidnet-s_imagenet1k_20230306-715e6273.pth 09/26 17:02:10 - mmengine - WARNING - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io 09/26 17:02:10 - mmengine - WARNING - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future. 09/26 17:02:10 - mmengine - INFO - Checkpoints will be saved to D:\Allcode\mmlab\mmsegmentation-dev-1.x\work_dirs\pidnet-s_2xb6-6k_224x224-feces. Traceback (most recent call last): File ".\tools\train.py", line 104, in main() File ".\tools\train.py", line 100, in main runner.train() File "G:\softwares\path\Anaconda3\envs\mmseg\lib\site-packages\mmengine\runner\runner.py", line 1745, in train model = self.train_loop.run() # type: ignore File "G:\softwares\path\Anaconda3\envs\mmseg\lib\site-packages\mmengine\runner\loops.py", line 278, in run self.run_iter(data_batch) File "G:\softwares\path\Anaconda3\envs\mmseg\lib\site-packages\mmengine\runner\loops.py", line 301, in run_iter outputs = self.runner.model.train_step( File "G:\softwares\path\Anaconda3\envs\mmseg\lib\site-packages\mmengine\model\base_model\base_model.py", line 114, in train_step losses = self._run_forward(data, mode='loss') # type: ignore File "G:\softwares\path\Anaconda3\envs\mmseg\lib\site-packages\mmengine\model\base_model\base_model.py", line 340, in _run_forward results = self(*data, mode=mode) File "G:\softwares\path\Anaconda3\envs\mmseg\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl return forward_call(input, **kwargs) return self.loss(inputs, data_samples) File "d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\segmentors\encoder_decoder.py", line 181, in loss loss_decode = self._decode_head_forward_train(x, data_samples) File "d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\segmentors\encoder_decoder.py", line 142, in _decode_head_forward_train loss_decode = self.decode_head.loss(inputs, data_samples, File "d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\decode_heads\decode_head.py", line 262, in loss losses = self.loss_by_feat(seg_logits, batch_data_samples) File "d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\decode_heads\pid_head.py", line 155, in loss_by_feat sem_label, bd_label = self._stack_batch_gt(batch_data_samples) File "d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\decode_heads\pid_head.py", line 144, in _stack_batch_gt gt_edge_segs = [ File "d:\allcode\mmlab\mmsegmentation-dev-1.x\mmseg\models\decode_heads\pid_head.py", line 145, in data_sample.gt_edge_map.data for data_sample in batch_data_samples AttributeError: 'SegDataSample' object has no attribute 'gt_edge_map'

Chenhongchang commented 6 months ago

how can you fix this problem?

iamweishao commented 4 months ago

Is there any answer, I also have this problem