当前位置:网站首页>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])
边栏推荐
- The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
- 杰理之开机自动配对【篇】
- Visual Studio 插件之CodeMaid自动整理代码
- R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
- Key points of anti reptile: identifying reptiles
- 干货分享|DevExpress v22.1原版帮助文档下载集合
- L1-019 who falls first (Lua)
- Jürgen Schmidhuber回顾LSTM论文等发表25周年:Long Short-Term Memory. All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversarial RL. Soccer learn
- 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
- Training IX basic configuration of network services
猜你喜欢
Make this crmeb single merchant wechat mall system popular, so easy to use!
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
谷歌seo外链Backlinks研究工具推荐
杰理之关于 TWS 配对方式配置【篇】
Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
ASP. Net kindergarten chain management system source code
Nunjuks template engine
Introduction to bit operation
2022.07.05
随机推荐
R语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
UCloud是基础云计算服务提供商
解决远程rviz报错问题
杰理之发起对耳配对、回连、开启可发现、可连接的轮循函数【篇】
ASP.NET幼儿园连锁管理系统源码
How to open an account for stock speculation? Excuse me, is it safe to open a stock account by mobile phone?
RESTAPI 版本控制策略【eolink 翻译】
The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
杰理之关于 TWS 交叉配对的配置【篇】
干货分享|DevExpress v22.1原版帮助文档下载集合
我的创作纪念日
微信公众号OAuth2.0授权登录并显示用户信息
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
Research and practice of super-resolution technology in the field of real-time audio and video
凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
9 atomic operation class 18 Rohan enhancement
[confluence] JVM memory adjustment
位运算介绍
指定opencv非标准安装的版本
Kirin Xin'an cloud platform is newly upgraded!