当前位置:网站首页>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])
边栏推荐
- LeetCode_7_5
- 让这个 CRMEB 单商户微信商城系统火起来,太好用了!
- The project manager's "eight interview questions" is equal to a meeting
- Tips and tricks of image segmentation summarized from 39 Kabul competitions
- how to prove compiler‘s correctness
- Time tools
- Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
- 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
- 怎么在手机上买股票开户 股票开户安全吗
- 强化学习-学习笔记8 | Q-learning
猜你喜欢
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
CMD command enters MySQL times service name or command error (fool teaching)
PMP每日一练 | 考试不迷路-7.7
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
[RT thread env tool installation]
干货分享|DevExpress v22.1原版帮助文档下载集合
微信公众号OAuth2.0授权登录并显示用户信息
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
648. 单词替换
随机推荐
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip plot, set the position parameter, and configure the separation degree of different grouped
银行理财产品怎么买?需要办银行卡吗?
Tp6 realize Commission ranking
怎么在手机上买股票开户 股票开户安全吗
AD域组策略管理
8 CAS
强化学习-学习笔记8 | Q-learning
What does "true" mean
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
Nunjuks template engine
How to share the same storage among multiple kubernetes clusters
what‘s the meaning of inference
Numpy——2. Shape of array
LeetCode 515(C#)
网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
what‘s the meaning of inference
Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
Make this crmeb single merchant wechat mall system popular, so easy to use!
Command mode - unity
2022.07.02