当前位置:网站首页>[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)
边栏推荐
- Currently, mysql5.6 is used. Which version would you like to upgrade to?
- 软件测试Bug报告怎么写?
- With 27K successful entry ByteDance, this "software testing interview notes" has benefited me for life
- 后台登录系统,JDBC连接数据库,做小案例练习
- STC-B学习板蜂鸣器播放音乐
- 基于485总线的评分系统双机实验报告
- ucore lab5用户进程管理 实验报告
- Logstack introduction and deployment -- elasticstack (elk) work notes 019
- Report on the double computer experiment of scoring system based on 485 bus
- Mysql的事务
猜你喜欢
Fundamentals of digital circuits (II) logic algebra
软件测试面试要问的性能测试术语你知道吗?
Summary of thread implementation
Daily code 300 lines learning notes day 9
The minimum sum of the last four digits of the split digit of leetcode simple problem
What level do 18K test engineers want? Take a look at the interview experience of a 26 year old test engineer
Leetcode simple question: check whether the numbers in the sentence are increasing
转行软件测试必需要知道的知识
CSAPP homework answers chapter 789
About the garbled code problem of superstar script
随机推荐
[oiclass] share prizes
ucore lab2 物理内存管理 实验报告
Functions: Finding Roots of equations
STC-B学习板蜂鸣器播放音乐2.0
Emqtt distribution cluster and node bridge construction
ucore lab8 文件系统 实验报告
Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
ucore lab6 调度器 实验报告
Video scrolling subtitle addition, easy to make with this technique
数字电路基础(二)逻辑代数
MySQL数据库(三)高级数据查询语句
ucore lab5用户进程管理 实验报告
Pedestrian re identification (Reid) - Overview
Es full text index
ucore lab7 同步互斥 实验报告
[pointer] delete all spaces in the string s
Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share
全网最详细的postman接口测试教程,一篇文章满足你
JDBC 的四种连接方式 直接上代码
“Hello IC World”