当前位置:网站首页>Readimg: read picture to variable variable variable
Readimg: read picture to variable variable variable
2022-06-23 16:15:00 【Growth of code Xiaobai】
from PIL import Image
from torch.autograd import Variable
from torchvision import transforms
transform = transforms.Compose(
[
# Function acceptance PIL Image or numpy.ndarray, Put it first by HWC Transpose to CHW Format , And then to float Then divide each pixel by 255
transforms.ToTensor(),
# Standardize data by channel to [-1,1], If the data is distributed in (0,1) Between , Network last bias It may be relatively large , When the model is initialized b=0 Of , This will lead to slow network convergence , after Normalize after , It can speed up the convergence of the model
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
# transforms.Normalize((0.5), (0.5))])
def readImg(opt,imgPath):
img = Image.open(imgPath) # RGB, h*w*c
# img = img.convert('L') # L = R * 0.299 + G * 0.587+ B * 0.114
# img.show()
# resize/crop
height = width = opt.input_size
img = img.resize((height, width), Image.BILINEAR)
# from PIL turn Tensor type
t_img = transform(img)
# tensor It's not back propagation ,variable It can be propagated back .Varibale There are three properties {data:tensor, grad: preservation data Gradient of , grad_fn: Point to Function object , For gradient calculation of back propagation }
img = Variable(img)
return img
After the above conversion tensor turn PIL The process is as follows :
image = im_tensor.cpu().clone()
image = image.squeeze(0) # Compress one dimension
image = transforms.ToPILImage(image) # Automatic conversion to 0-255
边栏推荐
- MySQL中json_extract函数说明
- 15 differences between MES in process and discrete manufacturing enterprises (Part I)
- ADB 按鍵名、按鍵代碼數字、按鍵說明對照錶
- [tcapulusdb knowledge base] Introduction to tmonitor background one click installation (II)
- Analysis of TCP three-time handshake and four-time handshake
- NLP 论文领读|改善意图识别的语义表示:有监督预训练中的各向同性正则化方法
- 企业想上MES系统?还得满足这些条件
- 医学影像分割的网站
- 线程池
- Spin lock using CAS
猜你喜欢

Advanced development - generic entry basic class test

PageHelper在面对复杂service数据处理下的分页问题

Ten thousand words introduction, detailed explanation of the core technical points of Tencent interview (t1-t9), and arrangement of interview questions

A tour of grpc:01 - Basic Theory
![[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction

Block, non block, multiplexing, synchronous, asynchronous, bio, NiO, AIO

机器人方向与高考选专业的一些误区

英特尔Arc A380显卡消息汇总:跑分亮眼驱动拉胯 入门性价产品亟待优化

stylegan2:analyzing and improving the image quality of stylegan

PageHelper faces the paging problem of complex service data processing
随机推荐
Golang对JSON文件的读写操作
golang写文件代码示例
生成二叉搜索平衡树[利用树递归特性]
golang数据类型图
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
R语言使用colorblinr包模拟色盲视觉、将已有的ggplot2可视化结果图像使用edit_colors函数编辑转化为色盲视觉友好的可视化结果、并自定设置色盲形式、色盲严重级别
Tableau comparatif du nom de la clé ADB, du numéro du Code de la clé et de la description de la clé
阻塞、非阻塞、多路复用、同步、异步、BIO、NIO、AIO 一文搞定
将vscode打造无敌的IDE(14) tasks.json和launch.json配置详解,随心所欲添加自动化任务
npm install 问题解决(nvm安装与使用)
window远程桌面连接互传文件加速小技巧
Detailed explanation of MQ message oriented middleware theory
Asynclistener interface of servlet 3.0
Object
Advanced development stage - the thickening of potential suspension wire begins A small step now, a big step next year
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)
How can I get the discount for opening a securities account? Is online account opening safe?
【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
英特尔Arc A380显卡消息汇总:跑分亮眼驱动拉胯 入门性价产品亟待优化
R语言plotly可视化:plotly可视化在对比条形图中添加误差条(Bar Chart with Error Bars with plotly in R)