当前位置:网站首页>Grid in pytorch_ How to use sample
Grid in pytorch_ How to use sample
2022-07-28 17:50:00 【Zhang Feifei~】
https://blog.csdn.net/qq_34914551/article/details/107559031
import torch
from torch.nn import functional as F
inp = torch.ones(1, 1, 4, 4)
# The goal is to get a Length and width are 20 Of tensor
out_h = 20
out_w = 20
# grid The generation method of is equivalent to mesh_grid
# This is generated directly [-1,1] Of grid coordinate , In practical application, it is necessary to unify the corresponding pixel coordinates of the image to [-1,1]
new_h = torch.linspace(-1, 1, out_h).view(-1, 1).repeat(1, out_w)
print("new_h shape:",new_h.shape)
print(new_h) # new_h shape: torch.Size([20, 20])
new_w = torch.linspace(-1, 1, out_w).repeat(out_h, 1)
print("new_w shape:", new_w.shape)
print(new_w) #new_w shape: torch.Size([20, 20])
grid = torch.cat((new_h.unsqueeze(2), new_w.unsqueeze(2)), dim=2)
print(grid.shape) #torch.Size([20, 20, 2])
grid = grid.unsqueeze(0)
print(grid.shape) # torch.Size([1, 20, 20, 2])
outp = F.grid_sample(inp, grid=grid, mode='bilinear')
print(outp.shape) #torch.Size([1, 1, 20, 20])
边栏推荐
- IO的操作
- Visual object class introduces Pascal VOC dataset
- .net MVC understanding
- [阅读笔记] For:Object Detection with Deep Learning: The Definitive Guide
- 关于非递归和递归分别实现求第n个斐波那契数
- 编译原理学习笔记3(自上而下语法分析)
- Generation and use of dynamic link library (error summary)
- 点云处理--voxel filter
- Jerry ac1082/1074/1090 development record
- Arya professional web automated test platform
猜你喜欢

Three ways to dynamically call WebService.Net

如何安装ps的滤镜插件
![[p5.js learning notes] local variable (let) and global variable (VaR) declaration](/img/37/82cdf73eb6527fb2da5bc550c33223.png)
[p5.js learning notes] local variable (let) and global variable (VaR) declaration

Can‘t use an undefined value as an ARRAY reference at probe2symbol

从0到1:基于云开发的投票小程序开发笔记

MySQL高级-MVCC(超详细整理)

数字滤波器(六)--设计FIR滤波器

es6 Promise

Understanding of virtual (virtual method) in C and its difference from abstract (abstract method)

【p5.js学习笔记】局部变量(let)与全局变量(var)声明
随机推荐
2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
软件测试前景如何?
mmdetection3D---(1)
【p5.js学习笔记】码绘的基础知识
[unity] timeline learning notes (VII): Custom clip
On the non recursive and recursive implementation of finding the nth Fibonacci number respectively
Database performance analysis and optimization (internal training materials of Aite future team)
内部类、常用类
Openpcd安装过程记录
编译原理学习笔记3(自上而下语法分析)
[阅读笔记] For:Object Detection with Deep Learning: The Definitive Guide
[p5.js actual combat] my self portrait
Technical aspects passed easily, HR: those with only three years of experience in large factories are not worth 20K
Jerry ac1082/1074/1090 development record
Sql Server STUFF与FOR XML PATH
【Unity】三张图让你看懂ShaderGraph编辑器
leetcode系统性刷题(五)-----动态规划
方法、函数
数字滤波器(五)--设计IIR滤波器
leetcode系统性刷题(二)------贪心、回溯、递归