当前位置:网站首页>torch. nn. functional. pad
torch. nn. functional. pad
2022-06-11 08:11:00 【Interval】
For a tensor Fill in . The most typical is the picture , Turned out to be 2*2 Of , Now I want to be 3*3 Of , Then you need to fill , There are many choices at this time , For example, whether to fill in the original top right or bottom left ? Or the top left ? wait .
This function can be used to implement these functions .
torch.nn.functional.pad(input, pad, mode='constant', value=0.0)
We only care about the second parameter pad, Don't worry about anything else .pad It's a tuple , The format is as follows :
(1,1) In the last dimension , Fill in the front 1 individual 0, Back filling 1 individual 0
(1,0) In the last dimension , Fill in the front 1 individual 0, No fill after .
(1,1,1,1) Indicates that the last two dimensions should be filled , And fill up, down, left and right 1 individual 0.
.....
below , According to the above 3 Cases for actual combat :
import torch
import torch.nn.functional as tnf
x = torch.tensor([[1, 2],[ 3,4]])
print(x)
print(tnf.pad(x,(1,1)))# Case study 1
print(tnf.pad(x,(1,0)))# Case study 2
print(tnf.pad(x,(1,1,1,1)))# Case study 3

That started 2*2 How to fill in 3*3 The picture of ? Suppose we fill in the right side and the bottom side 1 individual 0, So that's it :
print(x)
print(tnf.pad(x,(0,1,0,1)))

边栏推荐
- Alchemy experience (model training of deep learning) the necessity of timely adjusting training parameters for some situations (the adjustment of learning rate LR is the primary) summarizes some metho
- Shell编程笔记
- Label the mask image not obtained through labelme
- Typescript type alias
- Magnifying mirror rendering
- How to start participating in the open source community
- 代码设置ConstraintLayout的layout_constraintDimensionRatio
- 进程控制:进程等待(回收子进程)
- Sign in system design: how to draw the sign in function
- Use special characters to splice strings "+“
猜你喜欢

这几个小工具也太好用了

Return in foreach and break in for

Getting started with bladed tutorial (video)

Bubble sorting with C language

安卓初中级开发基础知识整理(面试自用)

How to do well in empty state design? Look at this comprehensive summary

C language - growth diary-04- preliminary exploration of local variables (local variables)

如何做好空状态设计?来看这份全面总结

Bladed入門教程(視頻)

Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
随机推荐
Detailed explanation of character function and string function (including simulation implementation)
彻底记住ImageView的background和src的区别
Figure seamless database integration tushare interface
Testing firebase with postman
批量拼接字符串
TypeScript-命名空间
记一次忽略@SuppressLint(“NewApi“)提示引发的血案
Shell Programming Notes
Label the mask image not obtained through labelme
Dameng user management
TypeScript-头文件使用细节
用 Keras/TensorFlow 2.9 创建深度学习模型的方法总结
Activity中,View#postDelay会导致内存泄漏,但是不会影响Activity的生命周期执行。
C. Manipulating History(贪心/哈希/思维/好题)
进程控制:进程等待(回收子进程)
自定义ViewGroup的知识点总结-持续更新
如何做好空状态设计?来看这份全面总结
ConstraintLayout中使用Guideline限制控件最大宽度
DAMENG 数据库启停
Dameng database login