当前位置:网站首页>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])
边栏推荐
- 8 CAS
- 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
- Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
- The DBSCAN function of FPC package of R language performs density clustering analysis on data, checks the clustering labels of all samples, and the table function calculates the two-dimensional contin
- 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
- Number - number (Lua)
- 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
- LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
- RESTAPI 版本控制策略【eolink 翻译】
- LeetCode 515(C#)
猜你喜欢

PMP practice once a day | don't get lost in the exam -7.7

Welcome to the markdown editor

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

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

Install mysql8 for Linux X ultra detailed graphic tutorial

AD域组策略管理

【STL】vector

开源OA开发平台:合同管理使用手册

Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference

一张图深入的理解FP/FN/Precision/Recall
随机推荐
what‘s the meaning of inference
Welcome to the markdown editor
Specify the version of OpenCV non-standard installation
Research and practice of super-resolution technology in the field of real-time audio and video
Number - number (Lua)
CMD command enters MySQL times service name or command error (fool teaching)
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
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
L1-023 output gplt (Lua)
转置卷积理论解释(输入输出大小分析)
L1-025 positive integer a+b (Lua)
Interpretation of transpose convolution theory (input-output size analysis)
R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
Mysql, sqlserver Oracle database connection mode
The research group of the Hunan Organizing Committee of the 24th China Association for science and technology visited Kirin Xin'an
Tp6 realize Commission ranking
Nunjuks template engine
杰理之测试盒配置声道【篇】
华南X99平台打鸡血教程