torchvision 笔记:transforms.Compose()
生活随笔
收集整理的這篇文章主要介紹了
torchvision 笔记:transforms.Compose()
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
torchvision.transforms.Compose()類的主要作用是串聯(lián)多個transforms列表里面的transform操作
比如,在torchvision 筆記:transforms.Normalize()_UQI-LIUWJ的博客-CSDN博客?中的代碼,可以用Compose來代替
不變的部分
from PIL import Image from torchvision import transforms, utils a=Image.open(b+'img/00000.jpg') a?Compose的部分
t=transforms.Compose([transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ]) a=t(a) a ''' tensor([[[1.9235, 1.9235, 1.9235, ..., 1.8893, 1.8893, 1.8893],[1.9235, 1.9235, 1.9235, ..., 1.8893, 1.8893, 1.8893],[1.9235, 1.9235, 1.9235, ..., 1.8893, 1.8893, 1.8893],...,[1.3242, 1.3242, 1.3242, ..., 1.3413, 1.3413, 1.3413],[1.3242, 1.3242, 1.3242, ..., 1.3413, 1.3413, 1.3413],[1.3242, 1.3242, 1.3242, ..., 1.3413, 1.3413, 1.3413]],[[2.0959, 2.0959, 2.0959, ..., 2.0784, 2.0784, 2.0784],[2.0959, 2.0959, 2.0959, ..., 2.0784, 2.0784, 2.0784],[2.0959, 2.0959, 2.0959, ..., 2.0784, 2.0784, 2.0784],...,[1.5182, 1.5182, 1.5182, ..., 1.5007, 1.5007, 1.5007],[1.5182, 1.5182, 1.5182, ..., 1.5007, 1.5007, 1.5007],[1.5182, 1.5182, 1.5182, ..., 1.5007, 1.5007, 1.5007]],[[2.3088, 2.3088, 2.3088, ..., 2.3263, 2.3263, 2.3263],[2.3088, 2.3088, 2.3088, ..., 2.3263, 2.3263, 2.3263],[2.3088, 2.3088, 2.3088, ..., 2.3263, 2.3263, 2.3263],...,[1.7163, 1.7163, 1.7163, ..., 1.7511, 1.7511, 1.7511],[1.7163, 1.7163, 1.7163, ..., 1.7511, 1.7511, 1.7511],[1.7163, 1.7163, 1.7163, ..., 1.7511, 1.7511, 1.7511]]]) '''?
一樣的效果
?
總結
以上是生活随笔為你收集整理的torchvision 笔记:transforms.Compose()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将tensor张量转换成图片格式并保存
- 下一篇: pytorch 笔记:DataLoade