在上一篇我们已经成功配置好了自己的数据集
但小伙伴们肯定会有疑问
搞了半天跑的是mmsegmentation里面的其他网络
我们需要跑的是SegNeXt网络呀!图文不符,退货,差评
好了好了
大家冷静
这一篇就是告诉大家我们上一篇配置好的数据集怎么拿到SegNeXt网络上来跑
首先大家先明确我们的SegNeXt网络跟我们的其他网络不在一起,其他网络都在configs/文件夹下
我们的SegNeXt在local_configs/文件夹下
里面的各个文件是啥意思 这里我就不赘述了
不清楚的小伙伴去看看我的系列教程(四)跟着去修改相关的文件
这里需要重点提一下
在里面的内容 为:
_base_ = [
'../../_base_/models/danet_r50-d8.py', '../../_base_/datasets/mydata_repeat.py',
'../../_base_/default_runtime.py', '../../_base_/schedules/schedule_80k.py'
]
model = dict(
decode_head=dict(num_classes=2), auxiliary_head=dict(num_classes=2))
checkpoint_config = dict(by_epoch=False, interval=5000)
evaluation = dict(interval=10000, metric='mIoU')
如果只是修改里面的部分内容,将路径放到我们数据集所在的位置
如下:
# dataset settings
dataset_type = 'MyRoadData'
#data_root = '/root/ADEChallengeData2016'
data_root = 'data/MyRoadData'
img_norm_cfg = dict(
mean=[0.5947, 0.5815, 0.5625], std=[0.1173, 0.1169, 0.1157], to_rgb=True)
crop_size = (512, 512)
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations', reduce_zero_label=True),
dict(type='Resize', img_scale=(512,512), ratio_range=(0.5, 2.0)),
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
dict(type='RandomFlip', prob=0.5),
dict(type='PhotoMetricDistortion'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255),
dict(type='DefaultFormatBundle'),
dict(type='Collect', keys=['img', 'gt_semantic_seg']),
]
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(
type='MultiScaleFlipAug',
img_scale=(512, 512),
# img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75],
flip=False,
transforms=[
dict(type='Resize', keep_ratio=True),
dict(type='ResizeToMultiple', size_divisor=32),
dict(type='RandomFlip'),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img']),
])
]
data = dict(
samples_per_gpu=1,
workers_per_gpu=2,
train=dict(
type='RepeatDataset',
times=50,
dataset=dict(
type=dataset_type,
data_root=data_root,
img_dir='images/training',
ann_dir='annotations/training',
pipeline=train_pipeline)),
val=dict(
type=dataset_type,
data_root=data_root,
img_dir='images/validation',
ann_dir='annotations/validation',
pipeline=test_pipeline),
test=dict(
type=dataset_type,
data_root=data_root,
img_dir='images/validation',
ann_dir='annotations/validation',
pipeline=test_pipeline))
跑出来道路IOU结果是0!!!
经过尝试正确的做法是
把我们在(四)里写的mydata.py文件里的内容复制过来
就可以正常运行啦
代码如下:
# dataset settings
dataset_type = 'MyRoadData'
data_root = 'data/MyRoadData'
img_norm_cfg = dict(
mean=[0.5947, 0.5815, 0.5625], std=[0.1173, 0.1169, 0.1157], to_rgb=True)
img_scale = (512, 512)
crop_size = (256, 256)
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations'),
dict(type='Resize', img_scale=img_scale, ratio_range=(0.5, 2.0)),
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
dict(type='RandomFlip', prob=0.5),
dict(type='PhotoMetricDistortion'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255),
dict(type='DefaultFormatBundle'),
dict(type='Collect', keys=['img', 'gt_semantic_seg'])
]
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(
type='MultiScaleFlipAug',
img_scale=img_scale,
# img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0],
flip=False,
transforms=[
dict(type='Resize', keep_ratio=True),
dict(type='RandomFlip'),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img'])
])
]
data = dict(
samples_per_gpu=8,
workers_per_gpu=16,
train=dict(
type='RepeatDataset',
times=40000,
dataset=dict(
type=dataset_type,
data_root=data_root,
img_dir='images/training',
ann_dir='annotations/training',
pipeline=train_pipeline)),
val=dict(
type=dataset_type,
data_root=data_root,
img_dir='images/validation',
ann_dir='annotations/validation',
pipeline=test_pipeline),
test=dict(
type=dataset_type,
data_root=data_root,
img_dir='images/validation',
ann_dir='annotations/validation',
pipeline=test_pipeline))
下面贴一些我的运行结果
跑了一下
iou算的是训练iou
10000次:72.62
2023-11-07 19:22:36,886 - mmseg - INFO -
+------------+-------+-------+
| Class | IoU | Acc |
+------------+-------+-------+
| background | 94.34 | 97.58 |
| road | 72.62 | 81.91 |
+------------+-------+-------+
2023-11-07 19:22:36,886 - mmseg - INFO - Summary:
2023-11-07 19:22:36,886 - mmseg - INFO -
+-------+-------+-------+
| aAcc | mIoU | mAcc |
+-------+-------+-------+
| 95.08 | 83.48 | 89.74 |
+-------+-------+-------+
70000:75.21
+------------+-------+-------+
| Class | IoU | Acc |
+------------+-------+-------+
| background | 94.68 | 96.99 |
| road | 75.21 | 87.17 |
+------------+-------+-------+
2023-11-08 02:45:12,389 - mmseg - INFO - Summary:
2023-11-08 02:45:12,389 - mmseg - INFO -
+-------+-------+-------+
| aAcc | mIoU | mAcc |
+-------+-------+-------+
| 95.42 | 84.95 | 92.08 |
+-------+-------+-------+
260000: 80.81
2023-11-09 02:07:34,806 - mmseg - INFO -
+------------+-------+-------+
| Class | IoU | Acc |
+------------+-------+-------+
| background | 96.09 | 98.16 |
| road | 80.81 | 88.66 |
+------------+-------+-------+
2023-11-09 02:07:34,806 - mmseg - INFO - Summary:
2023-11-09 02:07:34,806 - mmseg - INFO -
+-------+-------+-------+
| aAcc | mIoU | mAcc |
+-------+-------+-------+
| 96.64 | 88.45 | 93.41 |
+-------+-------+-------+
320000:82.37
2023-11-09 09:25:21,676 - mmseg - INFO -
+------------+-------+-------+
| Class | IoU | Acc |
+------------+-------+-------+
| background | 96.52 | 98.75 |
| road | 82.37 | 87.81 |
+------------+-------+-------+
2023-11-09 09:25:21,676 - mmseg - INFO - Summary:
2023-11-09 09:25:21,677 - mmseg - INFO -
+------+-------+-------+
| aAcc | mIoU | mAcc |
+------+-------+-------+
| 97.0 | 89.44 | 93.28 |
+------+-------+-------+
20000次:
road | 74.51
120000次:
road | 81.83
240000次:
road | 85.5
400000次:
road | 88.08