【pytorch函数笔记】transforms的使用

接上篇:ToTensor()将图像转为tensor格式

用的不是很多,了解基础的就行了。

python 复制代码
transforms_train = torchvision.transforms.Compose([
    torchvision.transforms.ToPILImage(),
    # imagenet mean and std
    torchvision.transforms.RandomHorizontalFlip(p=0.5),  # 翻转概率的p=0.5
    torchvision.transforms.RandomAffine(degrees=10, shear=16),  # 对图像进行随机仿射变换,包括旋转、平移、缩放和剪切等。
    torchvision.transforms.ColorJitter(brightness=0.1, contrast=0.1, saturation=0.1, hue=0.1),
    # 对图像进行颜色抖动,包括亮度、对比度、饱和度和色调等方面的随机变化。
    # torchvision.transforms.RandomGrayscale(p=0.1),
    # not in the original paper
    torchvision.transforms.Resize((256, 256)),
    torchvision.transforms.RandomCrop((227, 227)),  # VGG16
    torchvision.transforms.ToTensor(),
    # torchvision.transforms.Normalize([0.4816, 0.4199, 0.3884], [0.2568, 0.2408, 0.2323]),
    torchvision.transforms.Normalize([0.485, 0.456, 0.406],
                                     [0.229, 0.224, 0.225])
    # :对张量进行标准化处理,其中 mean 和 std 是预先计算好的均值和标准差(此处使用的是 ImageNet 数据集的均值和标准差)
])
相关推荐
302wanger6 小时前
【阅读笔记】当AI拿走一切之后
笔记
疯狂打码的少年8 小时前
【数据结构】串(字符串):基本概念与存储
数据结构·笔记
天疆说9 小时前
Ubuntu 26.04 下 Intel Meteor Lake 核显 + NPU 驱动配置与 PyTorch NPU 推理实测
linux·pytorch·ubuntu
Hotchip_MEMS10 小时前
TWS耳机微米级较量:超薄LGA封装如何助力MEMS麦克风小型化?
人工智能·笔记·物联网·电脑
Ztt66666666610 小时前
金泉方壶四面端正,月白釉却把棱角放柔了
经验分享·笔记·其他·百度·微信公众平台
学习和思考10 小时前
非自动化专业如何自学PLC?我的6个月学习路线图
笔记·学习·自动化·学习方法
疯狂打码的少年12 小时前
【数据结构】栈的应用:表达式求值(后缀表达式)
java·数据结构·笔记·算法
東隅已逝,桑榆非晚13 小时前
类和对象(中)
c++·笔记
野生yumeko13 小时前
QtScrcpy电脑无线控制手机屏幕
经验分享·笔记·智能手机
xian_wwq14 小时前
【学习笔记】Loop Engineering,从手动提示到目标驱动自动化-13/16
笔记·学习·自动化