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

边栏推荐
- UCORE lab2 physical memory management experiment report
- Summary of thread implementation
- Statistics 8th Edition Jia Junping Chapter 4 Summary and after class exercise answers
- Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
- MySQL数据库(四)事务和函数
- STC-B学习板蜂鸣器播放音乐
- C language learning summary (I) (under update)
- 转行软件测试必需要知道的知识
- UCORE lab7 synchronous mutual exclusion experiment report
- Which version of MySQL does php7 work best with?
猜你喜欢

Software testing interview summary - common interview questions
自动化测试中敏捷测试怎么做?

Four methods of exchanging the values of a and B
软件测试需求分析之什么是“试纸测试”
![Cadence physical library lef file syntax learning [continuous update]](/img/0b/75a4ac2649508857468d9b37703a27.jpg)
Cadence physical library lef file syntax learning [continuous update]
软件测试工作太忙没时间学习怎么办?

HackTheBox-Emdee five for life

1. Payment system

Capitalize the title of leetcode simple question

150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
随机推荐
Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
后台登录系统,JDBC连接数据库,做小案例练习
Thinking about three cups of tea
软件测试面试回答技巧
Cc36 different subsequences
STC-B学习板蜂鸣器播放音乐2.0
ucore lab8 文件系统 实验报告
The minimum number of operations to convert strings in leetcode simple problem
Iterators and generators
Face and eye recognition based on OpenCV's own model
UCORE lab1 system software startup process experimental report
The number of reversing twice in leetcode simple question
My first blog
MySQL数据库(三)高级数据查询语句
Global and Chinese market of goat milk powder 2022-2028: Research Report on technology, participants, trends, market size and share
[pointer] octal to decimal
Maximum nesting depth of parentheses in leetcode simple questions
接口测试面试题及参考答案,轻松拿捏面试官
ucore lab5用户进程管理 实验报告
Keil5 MDK's formatting code tool and adding shortcuts