当前位置:网站首页>torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
2022-07-07 19:57:00 【ODIMAYA】
torch.nn.functional.pad This function is used to fill tensor
The parameter pad Four parameters are defined , Represents the last two dimensions of the input matrix (w,h– And normal h,w contrary ) To expand :
( Left padding number , Number of padding on the right , Number of top fills , The number of bottom fills )
If you only write two parameters , Then fill in w:
( Left padding number , Number of padding on the right )
If you write six parameters , Then fill in (w,h,c) Three dimensions :
( Left padding number , Number of padding on the right , Number of top fills , The number of bottom fills , Number of channel fills 1, Number of channel fills 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())
Be careful :
The above often used padding number is a positive number , However, negative numbers can also be used in practical applications , To shrink tensor Of size, such as :
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])
边栏推荐
- 2022.07.04
- 最多可以参加的会议数目[贪心 + 优先队列]
- Ucloud is a basic cloud computing service provider
- The research group of the Hunan Organizing Committee of the 24th China Association for science and technology visited Kirin Xin'an
- 一张图深入的理解FP/FN/Precision/Recall
- R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
- 实训九 网络服务的基本配置
- R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
- Kirin Xin'an cloud platform is newly upgraded!
- ASP. Net gymnasium integrated member management system source code, free sharing
猜你喜欢

项目经理『面试八问』,看了等于会了

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

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

RESTAPI 版本控制策略【eolink 翻译】

模拟实现string类

mock.js从对象数组中任选数据返回一个数组

关于ssh登录时卡顿30s左右的问题调试处理

微信公众号OAuth2.0授权登录并显示用户信息

Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry

Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse
随机推荐
Openeuler prize catching activities, to participate in?
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
杰理之关于 TWS 声道配置【篇】
Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
【Confluence】JVM内存调整
现在股票开户可以直接在网上开吗?安全吗。
LeetCode 515(C#)
R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
Mysql, sqlserver Oracle database connection mode
My creation anniversary
mock.js从对象数组中任选数据返回一个数组
[confluence] JVM memory adjustment
Kirin Xin'an joins Ningxia commercial cipher Association
9 atomic operation class 18 Rohan enhancement
Flink并行度和Slot详解
索引总结(突击版本)
开源OA开发平台:合同管理使用手册
杰理之相同声道的耳机不允许配对【篇】
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
最多可以参加的会议数目[贪心 + 优先队列]