当前位置:网站首页>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]
边栏推荐
- 商城商品的知识图谱构建
- QPushButton-》函数精解
- 记一次JAP查询导致OOM的问题分析
- 代码调试core-踩内存
- 如何设计好接口测试用例?教你几个小技巧,轻松稿定
- AWS learning notes (I)
- Five reasons for clothing enterprises to deploy MES management system
- Huitong programming introductory course - 2A breakthrough
- [secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]
- 你不可不知道的Selenium 8种元素定位方法,简单且实用
猜你喜欢
MySQL is an optimization artifact to improve the efficiency of massive data query

Redis入门完整教程:问题定位与优化

换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!

基于ensp防火墙双击热备二层网络规划与设计

密码学系列之:在线证书状态协议OCSP详解

Five reasons for clothing enterprises to deploy MES management system

左程云 递归+动态规划

QT Bluetooth: qbluetooth DeviceInfo

如何分析粉丝兴趣?
MySQL提升大量数据查询效率的优化神器
随机推荐
CSDN summer camp course project analysis
惯导标定国内外研究现状小结(删减版)
NuScenes数据集关于Radar数据的统计
Safety delivery engineer
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
如何设计好接口测试用例?教你几个小技巧,轻松稿定
Andrews - multimedia programming
ERROR: Could not find a version that satisfies the requirement xxxxx (from versions: none)解决办法
知识图谱构建全流程
tensorboard的使用
Redis getting started complete tutorial: client management
QT common Concepts-1
简单冒泡排序
PSINS中19维组合导航模块sinsgps详解(滤波部分)
MySQL
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
Code line breaking problem of untiy text box
Leetcode:minimum_ depth_ of_ binary_ Tree solutions
一文读懂Faster RCNN
Redis getting started complete tutorial: common exceptions on the client