当前位置:网站首页>[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)
边栏推荐
- 软件测试有哪些常用的SQL语句?
- Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
- The maximum number of words in the sentence of leetcode simple question
- Wang Shuang's detailed learning notes of assembly language II: registers
- The latest query tracks the express logistics and analyzes the method of delivery timeliness
- Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
- UCORE lab7 synchronous mutual exclusion experiment report
- Using flask_ Whooshalchemyplus Jieba realizes global search of flask
- Global and Chinese market of pinhole glossmeter 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
想跳槽?面试软件测试需要掌握的7个技能你知道吗
Report on the double computer experiment of scoring system based on 485 bus
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
软件测试面试要问的性能测试术语你知道吗?
Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
Want to learn how to get started and learn software testing? I'll give you a good chat today
CSAPP家庭作業答案7 8 9章
Capitalize the title of leetcode simple question
遇到程序员不修改bug时怎么办?我教你
随机推荐
Function: calculates the number of uppercase letters in a string
DVWA exercise 05 file upload file upload
遇到程序员不修改bug时怎么办?我教你
JDBC 的四种连接方式 直接上代码
{1,2,3,2,5} duplicate checking problem
Pointer -- output all characters in the string in reverse order
Pointer -- eliminate all numbers in the string
Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
What level do 18K test engineers want? Take a look at the interview experience of a 26 year old test engineer
Investment should be calm
Leetcode simple question: check whether two strings are almost equal
软件测试方法有哪些?带你看点不一样的东西
Currently, mysql5.6 is used. Which version would you like to upgrade to?
Thinking about three cups of tea
HackTheBox-Emdee five for life
Global and Chinese market for antiviral coatings 2022-2028: Research Report on technology, participants, trends, market size and share
王爽汇编语言学习详细笔记一:基础知识
pytest
Investment operation steps