Kaggle提示:TTA(测试时间增加),小,技巧,TTAtesttimeaugmentation,增强

news/2025/3/16 1:16:16/

文章目录
1.原理简述
2.代码实现
1.原理简述
TTA:test time augmentation
顾名思义是测试时增强的意思,可将准确率提高若干个百分点,它就是测试时增强(test time augmentation, TTA)。这里会为原始图像造出多个不同版本,包括不同区域裁剪和更改缩放程度等,并将它们输入到模型中;然后对多个版本进行计算得到平均输出,作为图像的最终输出分数。
尽管有作弊的嫌疑。
但这种技术很有效,因为原始图像显示的区域可能会缺少一些重要特征,在模型中输入图像的多个版本并取平均值,能解决上述问题。

2.代码实现
这次打kaggle比赛时,是图像目标检测类的,用到了TTA,提高了LB,实现的主要API类如下:


类中函数说明:
augment:为一张图片制作TTA
batch_augment:为多张图片批量制作TTA
deaugment_boxes:将TTA预测框返回到图像的原始状态中


class BaseTTA:
image_size = 512

def augment(self, image):raise NotImplementedErrordef batch_augment(self, images):raise NotImplementedErrordef deaugment_boxes(self, boxes):raise NotImplementedError

水平翻转

class TTAHorizontalFlip(BaseTTA):
def augment(self, image):
return image.flip(1)

def batch_augment(self, images):return images.flip(2)def deaugment_boxes(self, boxes):boxes[:, [1,3]] = self.image_size - boxes[:, [3,1]]return boxes

垂直翻转

class TTAVerticalFlip(BaseTTA):

def augment(self, image):return image.flip(2)def batch_augment(self, images):return images.flip(3)def deaugment_boxes(self, boxes):boxes[:, [0,2]] = self.image_size - boxes[:, [2,0]]return boxes

旋转90°

class TTARotate90(BaseTTA):
def augment(self, image):
return torch.rot90(image, 1, (1, 2))

def batch_augment(self, images):return torch.rot90(images, 1, (2, 3))def deaugment_boxes(self, boxes):res_boxes = boxes.copy()res_boxes[:, [0,2]] = self.image_size - boxes[:, [1,3]]res_boxes[:, [1,3]] = boxes[:, [2,0]]return res_boxes

组合使用

class TTACompose(BaseTTA):
def init(self, transforms):
self.transforms = transforms

def augment(self, image):for transform in self.transforms:image = transform.augment(image)return imagedef batch_augment(self, images):for transform in self.transforms:images = transform.batch_augment(images)return imagesdef prepare_boxes(self, boxes):result_boxes = boxes.copy()result_boxes[:,0] = np.min(boxes[:, [0,2]], axis=1)result_boxes[:,2] = np.max(boxes[:, [0,2]], axis=1)result_boxes[:,1] = np.min(boxes[:, [1,3]], axis=1)result_boxes[:,3] = np.max(boxes[:, [1,3]], axis=1)return result_boxesdef deaugment_boxes(self, boxes):for transform in self.transforms[::-1]:boxes = transform.deaugment_boxes(boxes)return self.prepare_boxes(boxes)

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

相关文章

关于FT和TTa引脚作为数据IO时配置问题

虽然STM32F4内部带了RTC,但公司最近项目还是使用了外部时钟DS1302。以前只在51上用过,本以为在F4上移植只是简单更改一下,没想到却发现了一点问题。 硬件使用的电路和下图类似: 只不过三个IO上拉都使用了10K电阻,上拉…

Test time augmentation(TTA)

Test time augmentation 数据扩充是模型训练期间通常使用的一种方法,它使用来自训练数据集的样本的修改副本来扩充训练集。 数据增强通常使用图像数据执行,其中使用一些执行的图像处理技术(如缩放、翻转、移位等)创建训练数据集中的图像副本。 人工扩展…

TTA 测试时数据增强(multi-scale testing)(TEST.AUG)

TTA, Test-Time Augmentation,测试时数据增强 测试时将原始数据做不同形式的增强,然后取结果的平均值作为最终结果。可以进一步提升最终结果的精度 The input size significantly influences detection accuracy, since high resolution inputs make the detectors …

ISTQB- TTA大纲

1.基于风险的测试中技术测试分析师的任务 1.1 简介 基于风险的测试策略的建立和管理由测试经理全面负责,但测试经理通常会要求技术测试分析师的参与以确保正确实施基于风险的方法。 技术测试分析师在由测试经理为项目而制定的基于风险的测试框架内工作&#xff0…

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

一、Ensemble 本指南解释了如何在测试和推断改进的mAP和Recall过程中使用YOLOv5模型集成。2022年1月25日更新。 集成建模是一个过程,通过使用许多不同的建模算法或使用不同的训练数据集,创建多个不同的模型来预测结果。然后,集合模型将每个…

[论文翻译]测试时数据增强(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天构建完成,次日投入使用,让好医疗近在眼前,同时也可以应用到金融、保险等多种非面对面业务服务中。 去年,对非面对面画面共…