当前位置:网站首页>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])
边栏推荐
- Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
- A pot of stew, a collection of common commands of NPM and yarn cnpm
- 杰理之手动配对方式【篇】
- 2022年投资哪个理财产品收益高?
- Matplotlib drawing 3D graphics
- Throughput
- 9 atomic operation class 18 Rohan enhancement
- Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
- torch.nn.functional.pad(input, pad, mode=‘constant‘, value=None)记录
- MySQL、sqlserver oracle数据库连接方式
猜你喜欢

The project manager's "eight interview questions" is equal to a meeting

LeetCode_7_5

CMD command enters MySQL times service name or command error (fool teaching)

Introduction to bit operation

648. 单词替换

Make insurance more "safe"! Kirin Xin'an one cloud multi-core cloud desktop won the bid of China Life Insurance, helping the innovation and development of financial and insurance information technolog

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

Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!

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

Research and practice of super-resolution technology in the field of real-time audio and video
随机推荐
Install mysql8 for Linux X ultra detailed graphic tutorial
UCloud是基础云计算服务提供商
杰理之测试盒配置声道【篇】
2022.07.04
8 CAS
LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
Training IX basic configuration of network services
Flink并行度和Slot详解
Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
干货分享|DevExpress v22.1原版帮助文档下载集合
R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
Detailed explanation of Flink parallelism and slot
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
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
Kirin Xin'an cloud platform is newly upgraded!
R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
R语言ggplot2可视化:使用ggpubr包的ggecdf函数可视化分组经验累积密度分布函数曲线、linetype参数指定不同分组曲线的线型
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)