当前位置:网站首页>[pytorch] simple use of interpolate
[pytorch] simple use of interpolate
2022-07-06 15:09:00 【Ann, Dad, Chris】
interpolate It is used for interpolation , Common use is for up sampling (upsampling); Of course, you can also take samples (downsampling)
The official introduction is as follows
The parameter list is as follows
Easy to use
The following is a brief introduction to use
size and scale_factor You only need to provide one of the two parameters ;
The difference between them is ,size Specifies the interpolated shape; and scale_factor Just provide a coefficient to multiply or subtract ;
mode Mainly refers to the interpolation algorithm , The default is "nearest", It is similar to repeat operation , That is, copy the latest element to realize interpolation , But it must be applied to the input tensor is 4 Dimensional ;
Another common value is “linear”, It does linear interpolation
The following is a simple example
Examples 1
scale_factor Is to specify the expansion factor of the last two dimensions , As below scale_factor=(2,2), It's an input tensor shape The last two dimensions of , Times, respectively, 2;
import torch
from torch.nn import functional as F
x=torch.randint(1,10, (1, 3,2,2)).type(torch.float)
print(x)
x = F.interpolate(x, scale_factor=(2,2), mode='nearest')
print(x, x.shape)
Examples 2
If scale_factor Whether it is OK to enter only one dimension ? Tolerable .
The following example scale_factor=(2), Its effect is scale_factor=(2,2)
import torch
from torch.nn import functional as F
x=torch.randint(1,10, (1, 3,2,2)).type(torch.float)
print(x)
x = F.interpolate(x, scale_factor=(2), mode='nearest')
print(x, x.shape)
Examples 3
Don't use scale_factor, While using size;
In the following example , adopt size=(4,4), Specifies the final two-dimensional target size of the input tensor ; In fact, in this example , Its function is the same as the above example .
import torch
from torch.nn import functional as F
x=torch.randint(1,10, (1, 3,2,2)).type(torch.float)
print(x)
x = F.interpolate(x,size=(4,4), mode='nearest') print(x, x.shape)
Examples 4
Use mode=‘linear’; Note that the input tensor needs to be 3 dimension , Then interpolation only works on the last dimension
import torch
from torch.nn import functional as F
x=torch.randint(1,10, (3,2,2)).type(torch.float)
print(x)
x = F.interpolate(x,size=4, mode='linear') #, scale_factor=(2)
print(x, x.shape)
Examples 5
Use scale_factor, The effect same as above
import torch
from torch.nn import functional as F
x=torch.randint(1,10, (3,2,2)).type(torch.float)
print(x)
x = F.interpolate(x,scale_factor=2, mode='linear')
print(x, x.shape)
边栏推荐
- 安全测试入门介绍
- 刷视频的功夫,不如看看这些面试题你掌握了没有,慢慢积累月入过万不是梦。
- Using flask_ Whooshalchemyplus Jieba realizes global search of flask
- [oiclass] maximum formula
- China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
- 软件测试面试回答技巧
- How to transform functional testing into automated testing?
- Leetcode simple question: check whether the numbers in the sentence are increasing
- UCORE lab7 synchronous mutual exclusion experiment report
- What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
猜你喜欢
The number of reversing twice in leetcode simple question
Daily code 300 lines learning notes day 9
What is the transaction of MySQL? What is dirty reading and what is unreal reading? Not repeatable?
数字电路基础(二)逻辑代数
CSAPP家庭作業答案7 8 9章
ucore lab7 同步互斥 实验报告
软件测试面试要问的性能测试术语你知道吗?
UCORE lab1 system software startup process experimental report
Query method of database multi table link
MySQL development - advanced query - take a good look at how it suits you
随机推荐
Sorting odd and even subscripts respectively for leetcode simple problem
数字电路基础(二)逻辑代数
Global and Chinese markets of MPV ACC ECU 2022-2028: Research Report on technology, participants, trends, market size and share
UCORE lab2 physical memory management experiment report
Investment operation steps
Sleep quality today 81 points
“Hello IC World”
Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL数据库(五)视 图 、 存 储 过 程 和 触 发 器
Investment should be calm
Video scrolling subtitle addition, easy to make with this technique
HackTheBox-Emdee five for life
Should wildcard import be avoided- Should wildcard import be avoided?
STC-B学习板蜂鸣器播放音乐2.0
Emqtt distribution cluster and node bridge construction
Function: string storage in reverse order
Global and Chinese markets of cobalt 2022-2028: Research Report on technology, participants, trends, market size and share
Fundamentals of digital circuits (III) encoder and decoder
Face and eye recognition based on OpenCV's own model
Leetcode simple question: check whether the numbers in the sentence are increasing