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

关于mmsegmentation的SAM推理器部署训练 #3611

Open xiaowuwqg opened 8 months ago

xiaowuwqg commented 8 months ago

一、看了mmsegmentation上面写的支持SAM推理器,自己部署运行了,模型可以跑起来,但是不知道为什么每次到模型评估保存点就会断开。 二、链接如下: https://github.com/open-mmlab/mmsegmentation/pull/2897/commits/5a8d9e1ff97e2c22086ff6638e08db5d0567bcc9 三、版本如下: 拉取的mmsegmentation-dev_1.x(具体安装为1.2.2),pytorch-2.0.0,mmengine-0.10.3,mmcv-2.0.0 四、错误如下: Traceback (the recent call last): File “E:\ShenDuXueXi\mmsegmentation-1.1.2\tools\train.py”, line 104, in main() File “E:\ShenDuXueXi\mmsegmentation-1.1.2\tools\train.py”, line 100, in main runner.train() File “E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\runner.py”, line 1777, in train model = self.train_loop.run() # type: ignore File “E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\loops.py”, line 292, in run self.runner.val_loop.run() File “E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\loops.py”, line 371, in run self.run_iter(idx, data_batch) 文件“E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\torch\utils_contextlib.py”,第 115 行,在decorate_context 返回 func(args, kwargs) 文件“E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\loops.py”,第 391 行,在 run_iter 输出 = self.runner.model.val_step(data_batch) 文件“E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\model\base_model\base_model.py“,第 133 行,在 val_step 中返回 self._run_forward(data, mode='predict') # type: ignore File ”E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\model\base_model\base_model.py“,第 361 行,在 _run_forward results = self(data, mode=mode) 文件”E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\torch\nn\modules\module.py“,第 1501 行,在 _call_impl return forward_call(args, **kwargs) 文件“E:\ShenDuXueXi\mmsegmentation-1.1.2\mmseg\models\segmentors\base.py”,第 96 行,正向 返回 self.predict(inputs, data_samples) 文件“E:\ShenDuXueXi\mmsegmentation-1.1.2\mmseg\models\segmentors\encoder_decoder.py”,第 220 行,在 predict seg_logits = self.inference(inputs, batch_img_metas) 文件“E:\ShenDuXueXi\mmsegmentation-1.1.2\mmseg\models\segmentors\encoder_decoder.py”,第 331 行,在inference assert self.test_cfg.get('mode', 'whole') in ['slide', 'whole'], AttributeError: 'NoneType' object has no attribute 'get'

五、配置文件如下: checkpoint_path = 'https://download.openmmlab.com/mmclassification/v1/vit_sam/vit-base-p16_sam-pre_3rdparty_sa1b-1024px_20230411-2320f9cc.pth' crop_size = ( 512, 512, ) data_preprocessor = dict( bgr_to_rgb=True, mean=[ 123.675, 116.28, 103.53, ], pad_val=0, seg_pad_val=255, size=( 512, 512, ), std=[ 58.395, 57.12, 57.375, ], test_cfg=dict(size=( 512, 512, )), type='SegDataPreProcessor') data_root = 'E:\ShenDuXueXi\mmsegmentation-dev-1.x\data' dataset_type = 'ZihaoDataset' default_hooks = dict( checkpoint=dict(by_epoch=False, interval=100, type='CheckpointHook'), logger=dict(interval=50, 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, ] launcher = '无' load_from = 无 log_level = '信息' log_processor = dict(by_epoch=False) 模型 = dict( backbone=dict( arch='base', img_size=512, init_cfg=dict( checkpoint= 'https://download.openmmlab.com/mmclassification/v1/vit_sam/vit-base-p16_sam-pre_3rdparty_sa1b-1024px_20230411-2320f9cc.pth', prefix='backbone', type='预训练'), out_channels=256, patch_size=16, type='ViTSAM', use_abs_pos=True, use_rel_pos=True, window_size=14), decode_head=dict( align_corners=False, channels=128, concat_input=True, dropout_ratio=0.1, in_channels=256, in_index=0, loss_decode=dict( loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=False), norm_cfg=dict(requires_grad=True, type='BN'), num_classes=2, num_convs=2, type='FCNHead'), type='EncoderDecoder') norm_cfg = dict(requires_grad=True, type='BN') 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=20000, eta_min=0.0001, power=0.9, type='PolyLR'), ] resume = False test_cfg = dict(type='TestLoop') test_dataloader = dict( batch_size=1, dataset=dict( data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'), data_root='E:\ShenDuXueXi\mmsegmentation-dev-1.x\data', pipeline=[ dict(type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 2048, 1024, ), type='Resize'), dict(type='LoadAnnotations'), dict(type='PackSegInputs'), ], type='ZihaoDataset'), num_workers=4, persistent_workers=True, sampler=dict(shuffle=False, type='DefaultSampler')) test_evaluator = dict( iou_metrics=[ 'mIoU', 'mDice', 'mFscore', ], ], type='IoUMetric') test_pipeline = [ dict(type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 2048, 1024, ), type='Resize'), dict(type='LoadAnnotations'), dict(type='PackSegInputs'), ] train_cfg = dict(max_iters=20000, type='IterBasedTrainLoop', val_interval=100) train_dataloader = dict( batch_size=2, dataset=dict( data_prefix=dict( img_path='img_dir/train', seg_map_path='ann_dir/train'), data_root='E:\ShenDuXueXi\mmsegmentation-dev-1.x\data', pipeline=[ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( keep_ratio=True, ratio_range=( 0.5, 2.0, ), scale=( 2048, 1024, ), type='RandomResize'), dict( cat_max_ratio=0.75, crop_size=( 512, 512, ), type='RandomCrop'), dict(prob=0.5, type='RandomFlip'), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs'), ], type='ZihaoDataset'), num_workers=2, 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=( 2048, 1024, ), type='RandomResize'), dict(cat_max_ratio=0.75, crop_size=( 512, 512, ), type='RandomCrop'), dict(prob=0.5, type='RandomFlip'), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs'), ] tta_model = dict(type='SegTTAModel') tta_pipeline = [ dict(file_client_args=dict(backend='disk'), 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='img_dir/val', seg_map_path='ann_dir/val'), data_root='E:\ShenDuXueXi\mmsegmentation-dev-1.x\data', pipeline=[ dict(type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 2048, 1024, ), type='Resize'), dict(type='LoadAnnotations'), dict(type='PackSegInputs'), ], type='ZihaoDataset'), num_workers=4, persistent_workers=True, sampler=dict(shuffle=False, type='DefaultSampler')) val_evaluator = dict( iou_metrics=[ 'mIoU', 'mDice', 'mFscore', ], type='IoUMetric') vis_backends = [ dict(type='LocalVisBackend'), ] visualizer = dict( name='visualizer', type='SegLocalVisualizer', vis_backends=[ dict(type='LocalVisBackend'), ]) work_dir = './work_dirs\sam_vit-b_fcn_8xb2-40k_cityscapes-512x1024'

xiaowuwqg commented 8 months ago

@xiexinch 大佬,能否帮忙看下?跪谢