当前位置:网站首页>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])
边栏推荐
- 编译器优化那些事儿(4):归纳变量
- how to prove compiler‘s correctness
- R language ggplot2 visualization: use the ggdensity function of ggpubr package to visualize the packet density graph, and use stat_ overlay_ normal_ The density function superimposes the positive dist
- Experiment 1 of Compilation Principle: automatic implementation of lexical analyzer (Lex lexical analysis)
- ASP.NET体育馆综合会员管理系统源码,免费分享
- Solve the problem of remote rviz error reporting
- AD域组策略管理
- LeetCode 535(C#)
- Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
- 干货分享|DevExpress v22.1原版帮助文档下载集合
猜你喜欢
Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
模拟实现string类
Matplotlib drawing 3D graphics
ASP. Net kindergarten chain management system source code
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
Openeuler prize catching activities, to participate in?
Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
2022.07.02
爬虫实战(七):爬王者英雄图片
位运算介绍
随机推荐
The research group of the Hunan Organizing Committee of the 24th China Association for science and technology visited Kirin Xin'an
线性基
吞吐量Throughout
R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
最多可以参加的会议数目[贪心 + 优先队列]
ASP.NET幼儿园连锁管理系统源码
实训九 网络服务的基本配置
PMP practice once a day | don't get lost in the exam -7.7
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
what‘s the meaning of inference
Jerry's headphones with the same channel are not allowed to pair [article]
AD域组策略管理
歌单11111
杰理之关于 TWS 配对方式配置【篇】
LeetCode 535(C#)
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry
R language uses ggplot2 function to visualize the histogram distribution of counting target variables that need to build Poisson regression model, and analyzes the feasibility of building Poisson regr
Browse the purpose of point setting
R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值