当前位置:网站首页>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])
边栏推荐
- PV static creation and dynamic creation
- 现在股票开户可以直接在网上开吗?安全吗。
- R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置position参数配置不同分组数据点的分离程度
- 杰理之测试盒配置声道【篇】
- 【STL】vector
- ASP.NET幼儿园连锁管理系统源码
- R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
- Tips and tricks of image segmentation summarized from 39 Kabul competitions
- Introduction to bit operation
- 吞吐量Throughout
猜你喜欢

Install mysql8 for Linux X ultra detailed graphic tutorial

模拟实现string类

8 CAS

Kirin Xin'an joins Ningxia commercial cipher Association

9 原子操作类之18罗汉增强
![Jerry's headphones with the same channel are not allowed to pair [article]](/img/7d/3dcd9c7df583944e1d765b67543eb1.png)
Jerry's headphones with the same channel are not allowed to pair [article]

转置卷积理论解释(输入输出大小分析)

The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list

一张图深入的理解FP/FN/Precision/Recall

PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
随机推荐
Browse the purpose of point setting
Notes...
Introduction to bit operation
最长公共前缀(leetcode题14)
2022年投资哪个理财产品收益高?
L1-027 rental (Lua)
MySQL、sqlserver oracle数据库连接方式
注解。。。
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
Visual Studio 插件之CodeMaid自动整理代码
9 atomic operation class 18 Rohan enhancement
831. KMP字符串
解决远程rviz报错问题
杰理之快速配对,不支持取消配对【篇】
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
小试牛刀之NunJucks模板引擎
Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
tp6 实现佣金排行榜
[confluence] JVM memory adjustment
841. 字符串哈希