当前位置:网站首页>torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
2022-07-07 19:57:00 【ODIMAYA】
torch.nn.functional.pad This function is used to fill tensor
The parameter pad Four parameters are defined , Represents the last two dimensions of the input matrix (w,h– And normal h,w contrary ) To expand :
( Left padding number , Number of padding on the right , Number of top fills , The number of bottom fills )
If you only write two parameters , Then fill in w:
( Left padding number , Number of padding on the right )
If you write six parameters , Then fill in (w,h,c) Three dimensions :
( Left padding number , Number of padding on the right , Number of top fills , The number of bottom fills , Number of channel fills 1, Number of channel fills 2)
t4d = torch.empty(3, 3, 4, 2)
p1d = (1, 1) # pad last dim by 1 on each side
out = F.pad(t4d, p1d, "constant", 0) # effectively zero padding
print(out.size())
p2d = (1, 1, 2, 2) # pad last dim by (1, 1) and 2nd to last by (2, 2)
out = F.pad(t4d, p2d, "constant", 0)
print(out.size())
t4d = torch.empty(3, 3, 4, 2)
p3d = (0, 1, 2, 1, 3, 3) # pad by (0, 1), (2, 1), and (3, 3)
out = F.pad(t4d, p3d, "constant", 0)
print(out.size())
Be careful :
The above often used padding number is a positive number , However, negative numbers can also be used in practical applications , To shrink tensor Of size, such as :
x = torch.rand((8,3,57,57))
up = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)
xx = up(x)
xx.shape
Out[8]: torch.Size([8, 3, 114, 114])
import torch.nn.functional as F
xxx = F.pad(xx, [0, -1, 0, -1])
xxx.shape
Out[18]: torch.Size([8, 3, 113, 113])
xxxx = F.pad(xxx,[-2,-2,-3,-3,-1,-1])
xxxx.shape
Out[20]: torch.Size([8, 1, 107, 109])
边栏推荐
- 位运算介绍
- Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
- 关于自身的一些安排
- J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
- 超分辨率技术在实时音视频领域的研究与实践
- LeetCode 515(C#)
- CMD command enters MySQL times service name or command error (fool teaching)
- R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
- LeetCode 648(C#)
- L1-028 judging prime number (Lua)
猜你喜欢
杰理之测试盒配置声道【篇】
Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
LeetCode_7_5
Welcome to the markdown editor
Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry
J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
Make insurance more "safe"! Kirin Xin'an one cloud multi-core cloud desktop won the bid of China Life Insurance, helping the innovation and development of financial and insurance information technolog
Flink并行度和Slot详解
Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
随机推荐
8 CAS
tp6 实现佣金排行榜
R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
My creation anniversary
开源OA开发平台:合同管理使用手册
648. 单词替换
Specify the version of OpenCV non-standard installation
9 原子操作类之18罗汉增强
杰理之手动配对方式【篇】
杰理之按键发起配对【篇】
歌单11111
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
IP 工具类
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
What does "true" mean
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
项目经理『面试八问』,看了等于会了
一锅乱炖,npm、yarn cnpm常用命令合集
Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse
A pot of stew, a collection of common commands of NPM and yarn cnpm