mmdetection第二代中SegRescale如何使用
时间: 2024-05-14 13:18:51 浏览: 194
在 mmdetection 第二代中,SegRescale 是一种用于多尺度训练的数据增强方式。具体使用方法如下:
1.在配置文件中设置 `img_scale` 参数为多个尺度,例如:
```python
img_scale=[(1333, 800), (1333, 640)]
```
2.在数据集中定义 `seg_prefix` 参数,例如:
```python
data = dict(
train=dict(
type='CocoDataset',
ann_file='data/coco/annotations/instances_train2017.json',
img_prefix='data/coco/train2017/',
seg_prefix='data/coco/train2017/',
pipeline=train_pipeline),
val=dict(
type='CocoDataset',
ann_file='data/coco/annotations/instances_val2017.json',
img_prefix='data/coco/val2017/',
seg_prefix='data/coco/val2017/',
pipeline=test_pipeline),
test=dict(
type='CocoDataset',
ann_file='data/coco/annotations/instances_val2017.json',
img_prefix='data/coco/val2017/',
seg_prefix='data/coco/val2017/',
pipeline=test_pipeline))
```
3.在训练配置中添加 `seg_rescaler` 参数,例如:
```python
train_cfg = dict(
seg_rescaler=dict(
type='RelativeSegRescaler',
scale_factor=[0.5, 1.5],
policy='random',
power=0.1),
# ...
)
```
其中,`scale_factor` 参数表示相对于 `img_scale` 中的尺度进行缩放的尺度因子范围,`policy` 参数表示缩放方式,可以为 'random' 或 'range',`power` 参数表示缩放因子的幂次。
4.在模型配置中添加 `seg_resampling` 参数,例如:
```python
model = dict(
type='MaskRCNN',
# ...
roi_head=dict(
type='StandardRoIHead',
# ...
mask_roi_extractor=dict(
type='SingleRoIExtractor',
roi_layer=dict(type='RoIAlign', out_size=14, sample_num=2),
out_channels=256,
featmap_strides=[4, 8, 16, 32]),
mask_head=dict(
type='FCNMaskHead',
num_convs=4,
in_channels=256,
conv_out_channels=256,
num_classes=80,
loss_mask=dict(
type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)),
seg_resampling=True, # 添加该参数
),
# ...
)
```
其中,`seg_resampling` 参数表示是否使用 SegRescale 进行多尺度训练。
通过以上步骤,即可在 mmdetection 第二代中使用 SegRescale 进行多尺度训练。
阅读全文
相关推荐

















