当前位置:网站首页>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])
边栏推荐
- openEuler 有奖捉虫活动,来参与一下?
- Welcome to the markdown editor
- 项目经理『面试八问』,看了等于会了
- How to open an account for stock speculation? Excuse me, is it safe to open a stock account by mobile phone?
- Redis master-slave and sentinel master-slave switchover are built step by step
- Solve the error reporting problem of rosdep
- Training IX basic configuration of network services
- 编译器优化那些事儿(4):归纳变量
- 干货分享|DevExpress v22.1原版帮助文档下载集合
- A pot of stew, a collection of common commands of NPM and yarn cnpm
猜你喜欢
干货分享|DevExpress v22.1原版帮助文档下载集合
Welcome to the markdown editor
微信公众号OAuth2.0授权登录并显示用户信息
ASP.NET幼儿园连锁管理系统源码
Detailed explanation of Flink parallelism and slot
9 原子操作类之18罗汉增强
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
Nunjuks template engine
关于ssh登录时卡顿30s左右的问题调试处理
2022.07.05
随机推荐
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
杰理之开机自动配对【篇】
Openeuler prize catching activities, to participate in?
杰理之相同声道的耳机不允许配对【篇】
ASP. Net kindergarten chain management system source code
Semantic slam source code analysis
how to prove compiler‘s correctness
Interpretation of transpose convolution theory (input-output size analysis)
位运算介绍
[Verilog advanced challenge of Niuke network question brushing series] ~ multi bit MUX synchronizer
openEuler 资源利用率提升之道 01:概论
Ucloud is a basic cloud computing service provider
Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
A pot of stew, a collection of common commands of NPM and yarn cnpm
注解。。。
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin diagram, set the palette parameter to customize the filling color of violin diagrams at different
凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
【STL】vector