当前位置:网站首页>Up sampling deconvolution operation
Up sampling deconvolution operation
2022-07-29 07:43:00 【benben044】
In this paper, the reference :
https://www.jianshu.com/p/b48bf190fe61
Understand transpose convolution - Alicyclic - Blog Garden
Deep parsing what is transposed convolution - Electronic enthusiast network
https://blog.csdn.net/weixin_41620490/article/details/105885663
Commonly used down sampling is through convolution and pooling , Keep reducing the image size , Reduce the sampling points of the matrix .
Upsampling is performed by deconvolution or interpolation , Constantly expand the image size , Increase the sampling points of the matrix .
Convolution itself is a feature extraction , The process of data compression .
Deconvolution is a special forward convolution , First pass the supplement according to a certain proportion 0 To expand the size of the input image , Then rotate the convolution kernel , Then forward convolution . But this deconvolution is not the inverse process of convolution , Once the convolution operation is over , It cannot be restored by deconvolution . Deconvolution should be transposed convolution more accurately .
How to understand transpose ?
Let's start with convolution .

For the convolution operation above ,
Input input by 4*4,kernel by 3*3,stride by 1,padding by 0. Then the convolution is :
Mathematical derivation can be achieved by sliding kernel Calculate each value separately , But the computer calculates the value at one time .
First, convert the input into N*1, For Ben input by 16*1, as follows :

Transform convolution kernel into 4*16 The sparse matrix of , As shown in the figure below :

Matrix multiplication 4*1 The process of the result is as follows :

Constructed by convolution kernel 4*16 The sparse matrix of , bring 4*4 -> 16*1 The input of gets directly 4*1 -> 2*2 Result .
The upsampling is the opposite , We hope 2*2 -> 4*1 The input of gets 16*1 -> 4*4 Result , At this point, you need to use 16*4 Matrix , From positive 4*16 The matrix becomes 16*4 The transpose matrix of , Hence the name transpose matrix .

How to calculate the output size ?
First, the calculation formula of convolution output size is given :

After transformation, we get :
Exchange in and out Value , Then the size of the transposed convolution is :

pytorch How to calculate transpose convolution ?
First , The code of convolution operation is as follows :
import torch
import torch.nn as nn
model = nn.Conv2d(in_channels=1, out_channels=1, kernel_size=2,stride=1,padding=0)
x = torch.tensor([[[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]]]).unsqueeze(0)
model.weight.data = torch.tensor([[[[1.,1.],[1.,1.]]]])
model.bias.data = torch.zeros(1)
print(model(x))The output is :
tensor([[[[12., 16.],
[24., 28.]]]], grad_fn=<ThnnConv2DBackward>)
The code of transpose convolution operation is as follows :
import torch
import torch.nn as nn
model = nn.ConvTranspose2d(in_channels=1, out_channels=1, kernel_size=3,stride=1,padding=0)
x = torch.tensor([[[12,16],[24,28]]], dtype=torch.float32).unsqueeze(0)
model.weight.data = torch.tensor([[[[1,1,1],[1,1,1],[1,1,1]]]], dtype=torch.float32)
model.bias.data = torch.zeros(1)
print(model(x))
The output is :
tensor([[[[12., 28., 28., 16.],
[36., 80., 80., 44.],
[36., 80., 80., 44.],
[24., 52., 52., 28.]]]], grad_fn=<SlowConvTranspose2DBackward>)
边栏推荐
- MapReduce steps of each stage
- OA项目之会议通知(查询&是否参会&反馈详情)
- zip gzip tar压缩进阶版
- 你学习·我奖励,21天学习挑战赛 | 等你来战
- MySQL 45 讲 | 07 行锁功过:怎么减少行锁对性能的影响?
- Meeting notice of OA project (Query & whether to attend the meeting & feedback details)
- RoBERTa:A Robustly Optimized BERT Pretraining Approach
- Reflect reflect
- 《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》
- Sort out the two NFT pricing paradigms and four solutions on the market
猜你喜欢

IonIcons图标大全

Prometheus与Grafana

【WPF】通过动态/静态资源实现语言切换
![【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK](/img/bf/c0e03f1bf477730f0b3661b3256d1d.png)
【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK

MySQL 45讲 | 08 事务到底是隔离的还是不隔离的?

Meeting notice of OA project (Query & whether to attend the meeting & feedback details)

STM32 operation w25q256 w25q16 SPI flash
功能自动化测试实施的原则以及方法有哪些?
![[MySQL] - [subquery]](/img/81/0880f798f0f41724fd485ae82d142d.png)
[MySQL] - [subquery]

207. Curriculum
随机推荐
do end用法的妙处
I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test
[summer daily question] Luogu p6336 [coci2007-2008 2] bijele
监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
Write some DP
性能更佳、使用更简单的懒加载IntersectionObserverEntry(观察者)
[untitled] format save
[summer daily question] Luogu p1601 a+b problem (high precision)
MySQL 45讲 | 08 事务到底是隔离的还是不隔离的?
Embroidery of little D
UPC 小C的王者峡谷
State machine DP 3D
Amazon cloud assistant applet is coming!
Gin abort cannot prevent subsequent code problems
【暑期每日一题】洛谷 P6408 [COCI2008-2009#3] PET
What is the function of fileappender in logback?
MySQL 45 讲 | 07 行锁功过:怎么减少行锁对性能的影响?
技术分享| 快对讲综合调度系统
BeanUtils.setProperty()
Cfdiv1+2-bash and a high math puzzle- (gcd+ summary of segment tree single point interval maintenance)