当前位置:网站首页>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])
边栏推荐
- 现在股票开户可以直接在网上开吗?安全吗。
- el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
- What does "true" mean
- Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
- Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
- tp6 实现佣金排行榜
- 杰理之按键发起配对【篇】
- L1-023 output gplt (Lua)
- Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
- L1-027 rental (Lua)
猜你喜欢

爬虫实战(七):爬王者英雄图片

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

位运算介绍

杰理之相同声道的耳机不允许配对【篇】

编译原理 实验一:词法分析器的自动实现(Lex词法分析)
Make this crmeb single merchant wechat mall system popular, so easy to use!

谷歌seo外链Backlinks研究工具推荐

Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
![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]

PV static creation and dynamic creation
随机推荐
Install mysql8 for Linux X ultra detailed graphic tutorial
PV static creation and dynamic creation
Longest common prefix (leetcode question 14)
9 atomic operation class 18 Rohan enhancement
How to share the same storage among multiple kubernetes clusters
浏览积分设置的目的
[confluence] JVM memory adjustment
项目经理『面试八问』,看了等于会了
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
A pot of stew, a collection of common commands of NPM and yarn cnpm
实训九 网络服务的基本配置
解决rosdep的报错问题
The project manager's "eight interview questions" is equal to a meeting
模拟实现string类
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
杰理之关于 TWS 声道配置【篇】
Number - number (Lua)
L1-023 output gplt (Lua)
Make this crmeb single merchant wechat mall system popular, so easy to use!
Redis master-slave and sentinel master-slave switchover are built step by step