YOLOV5之提高模型评估和测试方法(TTA、Ensemble、WBF)

news/2025/3/16 6:04:23/

一、Ensemble

本指南解释了如何在测试和推断改进的mAP和Recall过程中使用YOLOv5模型集成。2022年1月25日更新。

集成建模是一个过程,通过使用许多不同的建模算法或使用不同的训练数据集,创建多个不同的模型来预测结果。然后,集合模型将每个基本模型的预测聚合起来,并对未见数据产生一次最终预测。使用集成模型的动机是为了减少预测的泛化误差。当采用集成方法时,只要基本模型是不同的和独立的,模型的预测误差就会减小。这种方法在预测中寻求群体的智慧。尽管集成模型在模型中有多个基本模型,但它作为单个模型进行操作和执行。

1、Ensemble Test

python val.py --weights yolov5x.pt yolov5l6.pt --data coco.yaml --img 640 --half

2、Ensemble Inference

python detect.py --weights model1.pt model2.pt --augment

3、TTA和模型集成测试

集合和TTA不是相互排斥的。你可以TTA一个模型,你也可以集成一组有或没有TTA的模型:

python detect.py --weights yolov5x.pt yolov5l6.pt --img 640 --source data/images

ensembling runs multiple models, while TTA tests a single model at with different augmentations. Typically I've seen the best result when merging output grids directly, (i.e. ensembling YOLOv5l and YOLOv5x), rather than simply appending boxes from multiple models for NMS to sort out. This is not always possible however, for example Ensembling an EfficientDet model with YOLOv5x, you can not merge grids, you must use NMS or WBF (or Merge NMS) to get a final result.

二、TTA

Test with TTA

$ python val.py --weights yolov5x.pt --data coco.yaml --img 832 --augment --half

Inference with TTA

$ python detect.py --weights yolov5s.pt --img 832 --source data/images --augment

Customize

ou can customize the TTA ops applied in the YOLOv5 forward_augment() method here:

def forward_augment(self, x): img_size = x.shape[-2:]  # height, width s = [1, 0.83, 0.67]  # scales f = [None, 3, None]  # flips (2-ud, 3-lr) y = []  # outputs for si, fi in zip(s, f): xi = scale_img(x.flip(fi) if fi else x, si, gs=int(self.stride.max())) yi = self.forward_once(xi)[0]  # forward # cv2.imwrite(f'img_{si}.jpg', 255 * xi[0].cpu().numpy().transpose((1, 2, 0))[:, :, ::-1])  # save yi = self._descale_pred(yi, fi, si, img_size) y.append(yi) return torch.cat(y, 1), None  # augmented inference, train 

三、WBF

WBF:优化目标检测,融合过滤预测框

使用YoloV5高级功能提升目标检测性能

https://towardsdatascience.com/advanced-yolov5-tutorial-enhancing-yolov5-with-weighted-boxes-fusion-3bead5b71688


http://www.ppmy.cn/news/911399.html

相关文章

[论文翻译]测试时数据增强(TTA):Automatic Brain Tumor Segmentation using Convolutional Neural Networks with TTA

论文下载: 地址 Automatic Brain Tumor Segmentation using Convolutional Neural Networks with Test-Time Augmentation 使用带有TTA的卷积神经网络实现胶质瘤的自动分割 Abstract. Automatic brain tumor segmentation plays an important role for diagnosis, surgical pl…

【Kaggle比赛常用trick】K折交叉验证、TTA

一、什么是k折交叉验证? 在训练阶段,我们一般不会使用全部的数据进行训练,而是采用交叉验证的方式来训练。交叉验证(Cross Validation,CV)是机器学习模型的重要环节之一。它可以增强随机性,从有…

W-Sharing取得TTA与PaaS-TA兼容级别1双项认证

W-Sharing是一款可以实现实时共享功能的SaaS型产品。W-Sharing能够实现医患、医医线上互通,1天构建完成,次日投入使用,让好医疗近在眼前,同时也可以应用到金融、保险等多种非面对面业务服务中。 去年,对非面对面画面共…

李宏毅机器学习作业3——Image Classification,模型集成,交叉验证,TTA

目录 任务和数据集 任务 数据集 Baseline 导包 数据处理 Transforms Datasets 数据加载函数 分类模型 训练 训练函数 加载数据 训练 预测 输出 解答 数据增广 使用原代码模型 EnsembleTTA 模型集成Ensemble Test Time Augmentation EnsembleTTA Cross V…

Pytorch TTA(预测增强) 源码阅读

Pytorch TTA 源码阅读 1.ttach/wrappers.py TTA主要调用的接口 继承了pytorch的nn.Module import torch import torch.nn as nn # 做类型注解的库 # 参考 https://www.bilibili.com/read/cv3249320/ from typing import Optional, Mapping, Union, Tuple from .base import…

【目标检测-YOLO】YOLOv5 Test-Time Augmentation (TTA) 教程

📚 This guide explains how to use Test Time Augmentation (TTA) during testing and inference for improved mAP and Recall with YOLOv5 🚀. UPDATED 25 January 2022. Before You Start Clone repo and install requirements.txt in a =3.7.0">Python>=…

目标检测学习笔记——TTA

transforms.ToTensor()源码 TTA用法示例: class BaseWheatTTA:""" author: shonenkov """image_size 512def augment(self, image):raise NotImplementedErrordef batch_augment(self, images):raise NotImplementedErrordef deau…

pytorch版TTA 源码阅读2

TTA 源码阅读2 1. Transforms.py 主要是图片增强方法的文件 首先要提一下的是,它这里transform的类继承DualTransform,而这个类又是完全继承上一篇解析过的BaseTransform的 class DualTransform(BaseTransform):pass因此看到它直接当做BaseTransform…