当前位置:网站首页>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]
边栏推荐
- centerX: 用中国特色社会主义的方式打开centernet
- Redis入门完整教程:复制配置
- Kubernetes源码分析(二)----资源Resource
- Leetcode 77: combination
- Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
- Kubernetes source code analysis (II) -- resource
- Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey
- Niuke programming problem -- double pointer of 101 must be brushed
- Redis Getting started tutoriel complet: positionnement et optimisation des problèmes
- What are the applications and benefits of MES management system
猜你喜欢
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
uniapp的表单验证
HAVE FUN | “飞船计划”活动最新进展
Redis入门完整教程:AOF持久化
6-6 vulnerability exploitation SSH security defense
MySQL --- 常用函数 - 字符串函数
Apifox, is your API interface document rolled up like this?
Redis getting started complete tutorial: replication topology
Redis入門完整教程:問題定比特與優化
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (time synchronization part)
随机推荐
【软件测试】最全面试问题和回答,全文背熟不拿下offer算我输
Oauth2协议中如何对accessToken进行校验
uniapp适配问题
wzoi 1~200
商城商品的知识图谱构建
Redis introduction complete tutorial: replication principle
Oracle中日期的使用方法实例
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
MySQL is an optimization artifact to improve the efficiency of massive data query
Apifox, is your API interface document rolled up like this?
Django database (SQLite) basic introductory tutorial
Electrical engineering and automation
Convert widerperson dataset to Yolo format
Examples of how to use dates in Oracle
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
Redis入门完整教程:复制拓扑
MySQL - common functions - string functions
Kubernetes source code analysis (II) -- resource
Metaforce force meta universe fossage 2.0 smart contract system development (source code deployment)