当前位置:网站首页>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])
边栏推荐
- 841. 字符串哈希
- 【RT-Thread env 工具安装】
- R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
- PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
- Command mode - unity
- AI writes a poem
- R language dplyr package select function, group_ The by function, filter function and do function obtain the third largest value of a specific numerical data column in a specified level in a specified
- 谷歌seo外链Backlinks研究工具推荐
- 华南X99平台打鸡血教程
- how to prove compiler‘s correctness
猜你喜欢
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
Make this crmeb single merchant wechat mall system popular, so easy to use!
How to share the same storage among multiple kubernetes clusters
微信公众号OAuth2.0授权登录并显示用户信息
谷歌seo外链Backlinks研究工具推荐
爬虫实战(七):爬王者英雄图片
华南X99平台打鸡血教程
杰理之关于 TWS 配对方式配置【篇】
Install mysql8 for Linux X ultra detailed graphic tutorial
Redis master-slave and sentinel master-slave switchover are built step by step
随机推荐
L1-028 judging prime number (Lua)
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
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
杰理之发起对耳配对、回连、开启可发现、可连接的轮循函数【篇】
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
what‘s the meaning of inference
648. 单词替换
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
炒股如何开户?请问一下手机开户股票开户安全吗?
# 欢迎使用Markdown编辑器
8 CAS
R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
ASP. Net gymnasium integrated member management system source code, free sharing
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
UCloud是基础云计算服务提供商
LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀
杰理之关于 TWS 交叉配对的配置【篇】
PMP practice once a day | don't get lost in the exam -7.7