当前位置:网站首页>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)))

边栏推荐
- Label the mask image not obtained through labelme
- Process control: process waiting (recycling child processes)
- Typescript configuring ts in koa and using koa router
- 用 Keras/TensorFlow 2.9 创建深度学习模型的方法总结
- Batch splice string
- Methods to improve training speed in deep learning and techniques to reduce video memory (suitable for entry-level trick without too many computing resources)
- Typescript declaration merge
- Training yolov4 CSP model using coco dataset
- node报错整理
- (transformation) tree, binary tree and forest transformation principle
猜你喜欢

签到体系设计:签到功能该怎么画

How to find the complementary sequence of digraph

node报错整理

Batch splice string

Process control: process waiting (recycling child processes)

TypeScript-头文件使用细节

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

【案例解读】医疗单据OCR识别助力健康险智能理赔

Data visualization and Matplotlib

Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
随机推荐
How to do well in empty state design? Look at this comprehensive summary
Image processing operation record
SylixOS SD设备驱动开发
Figure seamless database integration tushare interface
Clipping and overlapping of YUV data
Activity中,View#postDelay会导致内存泄漏,但是不会影响Activity的生命周期执行。
如何开始参与开源社区
Session and session management technology
[transfer] two-way merging and sorting of C language
TypeScript-声明合并
TypeScript-类型别名
2022.6.7 特长生模拟
Label the mask image not obtained through labelme
ConstraintLayout中使用Guideline限制控件最大宽度
Js学习基础document.write在页面中写一行文字
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
134. 加油站
A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language
Training yolov4 CSP model using coco dataset
Solve valueerror: no model found in config file