【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 数据集的均值和标准差)
])
相关推荐
Andy杨37 分钟前
20250718-5-Kubernetes 调度-Pod对象:重启策略+健康检查_笔记
笔记·容器·kubernetes
石迹耿千秋5 小时前
迁移学习--基于torchvision中VGG16模型的实战
人工智能·pytorch·机器学习·迁移学习
杭州杭州杭州6 小时前
Python笔记
开发语言·笔记·python
谢白羽10 小时前
jenkins搭建笔记
运维·笔记·jenkins
xiaoli232710 小时前
课题学习笔记1——文本问答与信息抽取关键技术研究论文阅读(用于无结构化文本问答的文本生成技术)
笔记·学习
吃西瓜不吐籽_11 小时前
Mac 安装及使用sdkman指南
java·笔记
LGGGGGQ11 小时前
嵌入式学习-PyTorch(7)-day23
人工智能·pytorch·学习
甄卷11 小时前
李沐动手学深度学习Pytorch-v2笔记【08线性回归+基础优化算法】2
pytorch·深度学习·算法
PyAIExplorer11 小时前
PyTorch 损失函数详解:从理论到实践
人工智能·pytorch·python