当前位置:网站首页>How-PIL-to-Tensor
How-PIL-to-Tensor
2022-07-07 03:04:00 【Braised code】
How is the picture from N u m P y NumPy NumPy Form orientation T e n s o r Tensor Tensor What about form conversion ?
from PIL import Image
import numpy as np
from torchvision.transforms import ToTensor
img=Image.open('./sword.png')
img_arr=np.array(img)
img_tensor=ToTensor().__call__(img)
N u m P y NumPy NumPy Picture format for H , W , C H,W,C H,W,C, namely h e i g h t , w i d t h , c h a n n e l s height,width,channels height,width,channels( high 、 wide 、 The channel number )
img_arr.shape
(73, 183, 4)
T e n s o r Tensor Tensor The format of the picture is C , H , W C,H,W C,H,W, namely c h a n n e l s , h e i g h t , w i d t h channels,height,width channels,height,width( The channel number 、 high 、 wide )
img_tensor.shape
torch.Size([4, 73, 183])
Actually N u m P y NumPy NumPy Divide the corresponding pixel value at each position of the array by 255 255 255 You get the corresponding T e n s o r Tensor Tensor data type
# Take out the first point in the upper left corner of the image RGBA value
print(img_arr[0, 0, :])
print(img_tensor[:, 0, 0])
[ 35 33 47 255]
tensor([0.1373, 0.1294, 0.1843, 1.0000])
# verification , Absolutely right
print(255*img_tensor[:, 0, 0])
print(img_arr[0, 0, :])
tensor([ 35., 33., 47., 255.])
[ 35 33 47 255]
边栏推荐
- Examples of how to use dates in Oracle
- MySQL --- 常用函数 - 字符串函数
- Analysis of USB network card sending and receiving data
- 哈希表及完整注释
- Unity custom webgl packaging template
- The 8 element positioning methods of selenium that you have to know are simple and practical
- Qt蓝牙:QBluetoothDeviceInfo
- How to design interface test cases? Teach you a few tips to draft easily
- Redis入门完整教程:复制配置
- Derivative, partial derivative, directional derivative
猜你喜欢
Oauth2协议中如何对accessToken进行校验
知识图谱构建全流程
Analysis of USB network card sending and receiving data
商城商品的知识图谱构建
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺
运维管理系统有哪些特色
How-PIL-to-Tensor
Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey
实施MES管理系统时,哪些管理点是需要注意的
随机推荐
Redis Getting started tutoriel complet: positionnement et optimisation des problèmes
用全连接+softmax对图片的feature进行分类
Common fitting models and application methods of PCL
PSINS中19维组合导航模块sinsgps详解(时间同步部分)
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
Redis入门完整教程:复制拓扑
QT常见概念-1
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
惯导标定国内外研究现状小结(删减版)
Code line breaking problem of untiy text box
uniapp适配问题
ERROR: Could not find a version that satisfies the requirement xxxxx (from versions: none)解决办法
Niuke programming problem -- double pointer of 101 must be brushed
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (initial assignment part)
wzoi 1~200
Django database (SQLite) basic introductory tutorial
S120驱动器基本调试步骤总结
Have fun | latest progress of "spacecraft program" activities
Kubernetes源码分析(二)----资源Resource
centerX: 用中国特色社会主义的方式打开centernet