当前位置:网站首页>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]
边栏推荐
- 从控制理论的角度谈数据分析
- How to find file accessed / created just feed minutes ago
- 实施MES管理系统时,哪些管理点是需要注意的
- Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (filtering part)
- Form validation of uniapp
- Redis入门完整教程:复制原理
- 左程云 递归+动态规划
- Redis getting started complete tutorial: common exceptions on the client
- Use of promise in ES6
- Safety delivery engineer
猜你喜欢

Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!

Planning and design of double click hot standby layer 2 network based on ENSP firewall

wireshark安装

知识图谱构建全流程

Redis入门完整教程:复制原理

Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey

Redis入门完整教程:复制配置

实施MES管理系统时,哪些管理点是需要注意的

从零安装Redis

NuScenes数据集关于Radar数据的统计
随机推荐
一文读懂Faster RCNN
从控制理论的角度谈数据分析
What are the characteristics of the operation and maintenance management system
Dotconnect for DB2 Data Provider
Summary of research status of inertial navigation calibration at home and abroad (abridged version)
Safety delivery engineer
Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
Code debugging core step memory
fasterxml ToStringSerializerBase报错
uniapp的表单验证
Examples of how to use dates in Oracle
Wireshark installation
centerX: 用中国特色社会主义的方式打开centernet
Oauth2协议中如何对accessToken进行校验
实施MES管理系统时,哪些管理点是需要注意的
Redis入门完整教程:复制原理
2022 spring recruitment begins, and a collection of 10000 word interview questions will help you
【2022国赛模拟】多边形——计算几何、二分答案、倍增
Code line breaking problem of untiy text box
How-PIL-to-Tensor