当前位置:网站首页>torch.nn.functional.pad(input, pad, mode=‘constant‘, value=None)记录
torch.nn.functional.pad(input, pad, mode=‘constant‘, value=None)记录
2022-07-07 17:44:00 【ODIMAYA】
torch.nn.functional.pad该函数用来填充tensor
其中参数pad定义了四个参数,表示对输入矩阵的后两个维度(w,h–与正常的h,w相反)进行扩充:
(左边填充数, 右边填充数, 上边填充数, 下边填充数)
如果仅写两个参数,则填充的是w:
(左边填充数, 右边填充数)
如果写六个参数,则填充的是(w,h,c)三个维度:
(左边填充数, 右边填充数, 上边填充数, 下边填充数,通道填充数1,通道填充数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())
注意:
上述经常使用填充数是正数,但实际应用中也可使用负数,来缩小tensor的size,比如:
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])
边栏推荐
- R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
- Training IX basic configuration of network services
- Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
- 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
- LeetCode 648(C#)
- Interpretation of transpose convolution theory (input-output size analysis)
- Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
- LeetCode1051(C#)
- 强化学习-学习笔记8 | Q-learning
- 吞吐量Throughout
猜你喜欢

Numpy——axis

Research and practice of super-resolution technology in the field of real-time audio and video

The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list

ASP.NET幼儿园连锁管理系统源码

编译原理 实验一:词法分析器的自动实现(Lex词法分析)

谷歌seo外链Backlinks研究工具推荐

爬虫实战(七):爬王者英雄图片

CMD command enters MySQL times service name or command error (fool teaching)

转置卷积理论解释(输入输出大小分析)

PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
随机推荐
注解。。。
Experiment 1 of Compilation Principle: automatic implementation of lexical analyzer (Lex lexical analysis)
歌单11111
R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
Tp6 realize Commission ranking
杰理之开机自动配对【篇】
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
what‘s the meaning of inference
PMP每日一练 | 考试不迷路-7.7
8 CAS
ASP.NET幼儿园连锁管理系统源码
杰理之关于 TWS 交叉配对的配置【篇】
Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
Unable to link the remote redis server (solution 100%
Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
how to prove compiler‘s correctness
AI writes a poem
How to buy bank financial products? Do you need a bank card?
Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
Command mode - unity