from sahi import AutoDetectionModel
from sahi.predict import get_prediction, get_sliced_prediction, predict
yolov8_model_path = r'yolov8n.pt'
imfile = r'small-vehicles1.jpeg'
export_dir = r'ashi-res'
detection_model = AutoDetectionModel.from_pretrained(
model_type='yolov8',
model_path=yolov8_model_path,
confidence_threshold=0.3,
device="cpu", # or 'cuda:0'
)
def set_cfg_predict():
slice_height = 320
slice_width = 320
result = get_sliced_prediction(
imfile,
detection_model,
slice_height=slice_height,
slice_width=slice_width,
overlap_height_ratio=0.2,
overlap_width_ratio=0.2
)
result.export_visuals(export_dir=export_dir, hide_labels=True)
# std_predict()
# auto_cfg_predict()
set_cfg_predict()
上面以yolov8n对工程中示例图为例进行了简单测试。
原图
1、标准推理
def std_predict():
result = get_prediction(
imfile,
detection_model)
result.export_visuals(export_dir=export_dir, hide_labels=True)
大量漏检
2、自动分割
def auto_cfg_predict():
result = get_sliced_prediction(
imfile,
detection_model
)
result.export_visuals(export_dir=export_dir, hide_labels=True)
有少量漏检
3、设置h-w=512
有错误检测
4、设置h-w=416
综合最好
5、设置h-w=320
有错误检测