当前位置:网站首页>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>)
边栏推荐
- Joseph Ring problem
- 输出1234无重复的三位数
- Cross domain problems when downloading webapi interface files
- [summer daily question] Luogu P6500 [coci2010-2011 3] zbroj
- Prepare esp32 environment
- Sort out the two NFT pricing paradigms and four solutions on the market
- 状态机dp(简单版)
- 受欢迎的牛 G
- Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL
- Use of gcc/g++
猜你喜欢
[summer daily question] Luogu p7760 [coci2016-2017 5] tuna
2022 Shenzhen Cup Title A: get rid of "scream effect" and "echo room effect" and get out of the "information cocoon room"
QT连接两个qslite数据库报错QSqlQuery::exec: database not open
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
国内数字藏品的乱象与未来
207.课程表
关于大龄读博的几点回答?
207. Curriculum
MySQL 45讲 | 08 事务到底是隔离的还是不隔离的?
美智光电IPO被终止:年营收9.26亿 何享健为实控人
随机推荐
技术分享| 快对讲综合调度系统
[summer daily question] Luogu p1601 a+b problem (high precision)
How to get to the deep-water area when the industrial Internet goes?
As long as flutter is data, it will be judged null
Write some DP
[FPGA tutorial case 42] image case 2 - realize image binarization processing through Verilog, and conduct auxiliary verification through MATLAB
What are the common error types and solutions of black box testing?
Logback log level introduction
UPC 小C的王者峡谷
【深度学习】数据准备-pytorch自定义图像分割类数据集加载
使用自定义注解校验list的大小
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
For the application challenge of smart city, shengteng AI gives a new solution
美智光电IPO被终止:年营收9.26亿 何享健为实控人
CFdiv1+2-Bash and a Tough Math Puzzle-(线段树单点区间维护gcd+总结)
gin abort不能阻止后续代码的问题
分析25个主要DeFi协议的路线图 预见DeFi未来的七大趋势
Amaze UI 图标查询
Android面试题 | 怎么写一个又好又快的日志库?
MySQL 45 talk | 07 line lock merits and demerits: how to reduce the impact of line lock on performance?