PointTransformer数据增强模块怎么写

本文介绍了如何使用Python编写一个Compose函数进行图像数据增强,包括RandomScale类实现的随机尺寸缩放,以及Chromatic系列类如AutoContrast、Translation和Jitter等用于调整色彩。
摘要由CSDN通过智能技术生成

代码地址:https://github.com/POSTECH-CVLab/point-transformer/blob/10d43ab5210fc93ffa15886f2a4c6460cc308780/tool/train.py#L165

from util import transform as t

train_transform = t.Compose([ t.RandomScale([0.9, 1.1]), 
t.ChromaticAutoContrast(), 
t.ChromaticTranslation(), 
t.ChromaticJitter(), 
t.HueSaturationTranslation()
])

数据增强的方式是随机尺寸放缩、自动对比度、色彩平移、调节对比度饱和度和随机噪声。

写一个Compose函数来进行数据增强,transform是一个list,每个里面都是一个类的instance。

class Compose(object):
    def __init__(self, transforms):
        self.transforms = transforms

    def __call__(self, coord, feat, label):
        for t in self.transforms:
            coord, feat, label = t(coord, feat, label)
        return coord, feat, label

依次定义不同的数据增强方式

class RandomScale(object):
    def __init__(self, scale=[0.9, 1.1], anisotropic=False):
        self.scale = scale
        self.anisotropic = anisotropic

    def __call__(self, coord, feat, label):
        scale = np.random.uniform(self.scale[0], self.scale[1], 3 if self.anisotropic else 1)
        coord *= scale
        return coord, feat, label

调用:

if transform:
        coord, feat, label = transform(coord, feat, label)
  • 12
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值