当前位置:网站首页>[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)
边栏推荐
- What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
- Why can swing implement a form program by inheriting the JFrame class?
- [pointer] solve the last person left
- MySQL数据库(五)视 图 、 存 储 过 程 和 触 发 器
- 软件测试面试要问的性能测试术语你知道吗?
- [Ogg III] daily operation and maintenance: clean up archive logs, register Ogg process services, and regularly back up databases
- Don't you even look at such a detailed and comprehensive written software test question?
- Quaternion -- basic concepts (Reprint)
- 软件测试需求分析之什么是“试纸测试”
- [pointer] octal to decimal
猜你喜欢
[200 opencv routines] 98 Statistical sorting filter
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
Es full text index
Software testing interview summary - common interview questions
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Nest and merge new videos, and preset new video titles
自动化测试你必须要弄懂的问题,精品总结
CSAPP homework answers chapter 789
Leetcode simple question: check whether two strings are almost equal
150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
随机推荐
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
几款开源自动化测试框架优缺点对比你知道吗?
ucore lab7 同步互斥 实验报告
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
Cadence physical library lef file syntax learning [continuous update]
JDBC 的四种连接方式 直接上代码
Stc-b learning board buzzer plays music
自动化测试你必须要弄懂的问题,精品总结
遇到程序员不修改bug时怎么办?我教你
软件测试有哪些常用的SQL语句?
Functions: Finding Roots of equations
How to transform functional testing into automated testing?
Pointer -- output all characters in the string in reverse order
Leetcode simple question: check whether two strings are almost equal
全网最详细的postman接口测试教程,一篇文章满足你
150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
UCORE lab1 system software startup process experimental report
pytest
CSAPP Shell Lab 实验报告
Four methods of exchanging the values of a and B