当前位置:网站首页>[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)

边栏推荐
- MySQL数据库(四)事务和函数
- Iterators and generators
- The maximum number of words in the sentence of leetcode simple question
- Function: calculates the number of uppercase letters in a string
- How to learn automated testing in 2022? This article tells you
- Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
- [HCIA continuous update] advanced features of routing
- Maximum nesting depth of parentheses in leetcode simple questions
- {1,2,3,2,5} duplicate checking problem
- 几款开源自动化测试框架优缺点对比你知道吗?
猜你喜欢

Réponses aux devoirs du csapp 7 8 9

Software testing interview summary - common interview questions

CSAPP Shell Lab 实验报告

接口测试面试题及参考答案,轻松拿捏面试官

全网最详细的postman接口测试教程,一篇文章满足你
软件测试方法有哪些?带你看点不一样的东西
软件测试需求分析之什么是“试纸测试”
遇到程序员不修改bug时怎么办?我教你

如何成为一个好的软件测试员?绝大多数人都不知道的秘密

MySQL development - advanced query - take a good look at how it suits you
随机推荐
Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share
自动化测试你必须要弄懂的问题,精品总结
几款开源自动化测试框架优缺点对比你知道吗?
MySQL数据库(五)视 图 、 存 储 过 程 和 触 发 器
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
Differences between select, poll and epoll in i/o multiplexing
Functions: Finding Roots of equations
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
Keil5 MDK's formatting code tool and adding shortcuts
Réponses aux devoirs du csapp 7 8 9
Statistics 8th Edition Jia Junping Chapter 1 after class exercises and answers summary
Software testing interview summary - common interview questions
软件测试行业的未来趋势及规划
To brush the video, it's better to see if you have mastered these interview questions. Slowly accumulating a monthly income of more than 10000 is not a dream.
MySQL development - advanced query - take a good look at how it suits you
Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share
Pedestrian re identification (Reid) - Overview
If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
接口测试面试题及参考答案,轻松拿捏面试官
Fundamentals of digital circuits (III) encoder and decoder