基于Slicing Aided Hyper Inference (SAHI)做小目标检测

        遥感等领域数据大图像检测时,直接对大图检测会严重影响精度,而通用工具多不能友好支持大图分块检测。Slicing Aided Hyper Inference (SAHI)是一个用于辅助大图切片检测预测的包。目前可以良好的支持YOLOX、YOLOv5、MMDetection、Detection2等。代码:obss/sahi: Framework agnostic sliced/tiled inference + interactive ui + error analysis plots (github.com)

        在训练时,为了避免在模型的训练预处理管道中由于调整图像大小而丢失小对象,我们在管道的开头添加了随机裁剪。实际上,我们正在原始图像的小块上进行训练,并保留这些图像中的所有信息。例如:

train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations', with_bbox=True),
    dict(type='RandomCrop', crop_size=(height, width)),
    dict(
        type='Resize',
        img_scale=[(1333, 640), (1333, 672), (1333, 704), (1333, 736),
                   (1333, 768), (1333, 800)],
        multiscale_mode='value',
        keep_ratio=True),
    dict(type='RandomFlip', flip_ratio=0.5),
    dict(
        type='Normalize',
        mean=[103.53, 116.28, 123.675],
        std=[1.0, 1.0, 1.0],
        to_rgb=False),
    dict(type='Pad', size_divisor=32),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'])
]

        在推理时,SAHI的图像预测将输入图像分解为略微重叠的切片,对每个切片进行预测,最后合并每个切片的检测结果,恢复到原始图像上的坐标。

from sahi.model import MmdetDetectionModel
from sahi.predict import get_prediction, get_sliced_prediction, predict
from sahi.utils.cv import visualize_object_predictions


detection_model = MmdetDetectionModel(
    model_path=trained_model_path,
    config_path=config_path,
    device='cuda' # or 'cpu'
)


sliced_pred_result = get_sliced_prediction(
    test_img_path,
    detection_model, 
    slice_width=width, 
    slice_height=height
)

visualize_object_predictions(
    image=np.ascontiguousarray(sliced_pred_result.image),
    object_prediction_list=sliced_pred_result.object_prediction_list,
    rect_th=1,
    text_size=0.3,
    text_th=1,
    color=(0, 0, 0),
    output_dir=viz_path,
    file_name=test_img_name + "_sliced_pred_result",
    export_format=format,
)

         效果示例:

参考:

obss/sahi: Framework agnostic sliced/tiled inference + interactive ui + error analysis plots (github.com)

How to detect small objects in (very) large images | by Maximilian Gartz | ML6team

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值