torch.meshgrid()函数解析
torch.meshgrid()函数解析
torch.meshgrid()的功能是生成网格,可以用于生成坐标。函数输入两个数据类型相同的一维张量,两个输出张量的行数为第一个输入张量的元素个数,列数为第二个输入张量的元素个数,当两个输入张量数据类型不同或维度不是一维时会报错。
其中第一个输出张量填充第一个输入张量中的元素,各行元素相同;第二个输出张量填充第二个输入张量中的元素各列元素相同。
# 【1】
import torch
a = torch.tensor([1, 2, 3, 4])
print(a)
b = torch.tensor([4, 5, 6])
print(b)
x, y = torch.meshgrid(a, b)
print(x)
print(y)结果显示:
tensor([1, 2, 3, 4])
tensor([4, 5, 6])
tensor([[1, 1, 1],[2, 2, 2],[3, 3, 3],[4, 4, 4]])
tensor([[4, 5, 6],[4, 5, 6],[4, 5, 6],[4, 5, 6]])# 【2】
import torch
a = torch.tensor([1, 2, 3, 4, 5, 6])
print(a)
b = torch.tensor([7, 8, 9, 10])
print(b)
x, y = torch.meshgrid(a, b)
print(x)
print(y)结果显示:
tensor([1, 2, 3, 4, 5, 6])
tensor([ 7, 8, 9, 10])
tensor([[1, 1, 1, 1],[2, 2, 2, 2],[3, 3, 3, 3],[4, 4, 4, 4],[5, 5, 5, 5],[6, 6, 6, 6]])
tensor([[ 7, 8, 9, 10],[ 7, 8, 9, 10],[ 7, 8, 9, 10],[ 7, 8, 9, 10],[ 7, 8, 9, 10],[ 7, 8, 9, 10]])
在YOLO V3将图像划分为单元网格的部分就用到了torch.meshgrid()函数,如下所示。
yv, xv = torch.meshgrid([torch.arange(self.ny, device=device),torch.arange(self.nx, device=device)])
self.grid = torch.stack((xv, yv), 2).view((1, 1, self.ny, self.nx, 2)).float()
torch.meshgrid()函数解析相关推荐
- Pytorch中torch.repeat()函数解析
一. torch.repeat()函数解析 1. 说明 官网:torch.tensor.repeat(),函数说明如下图所示: 2. 函数功能 torch.tensor.repeat()函数可以对张量 ...
- torch.meshgrid函数
参考资料: https://pytorch.org/docs/stable/generated/torch.meshgrid.html 在此记录下torch.meshgrid的用法,该函数常常用于生成 ...
- Pytorch中torch.unsqueeze()和torch.squeeze()函数解析
一. torch.squeeze()函数解析 1. 官网链接 torch.squeeze(),如下图所示: 2. torch.squeeze()函数解析 torch.squeeze(input, di ...
- Pytorch中torch.argmax()函数解析
一. torch.argmax()函数解析 1. 官网链接 torch.argmax(),如下图所示: 2. torch.argmax(input)函数解析 torch.argmax(input) → ...
- Pytorch中torch.numel(),torch.shape,torch.size()和torch.reshape()函数解析
一. torch.numel()函数解析 1. 官网链接 torch.numel(),如下图所示: 2. torch.numel()函数解析 torch.numel(input) → int 返回输入 ...
- numpy.transpose和torch.transpose函数解析
问题 今天在想把一个三维的[3, x, y]的tensor转为[x, y, 3]遇到一些问题,最后的解决方法是把tensor转为numpy,然后使用numpy.transpose(mytensor, ...
- MATLAB三维绘图基础meshgrid函数的用法解析
MATLAB三维绘图基础meshgrid函数的用法解析 MATLAB中meshgrid函数是用来生成网格的,函数用法是: [X,Y] = meshgrid(x,y);这种是最常用的一种用法.x ...
- 【pytorch】torch.meshgrid()==>常用于生成二维网格,比如图像的坐标点
np.meshgrid()函数常用于生成二维网格,比如图像的坐标点. x1 ,y1 = torch.meshgrid(x,y) 输入参数: 参数是两个,第一个参数我们假设是x,第二个参数假设就是y ...
- torch.meshgrid 使用探究
torch.meshgrid 的函数原型是 torch.meshgrid(*tensors, indexing=None) indexing 是 torch.meshgrid 的一个参数. torch ...
最新文章
- python培训班哪些比较好-南京Python培训机构哪家比较好
- web设计师和前端设计师的互动—前端工程师应该具备的三种思维
- ELK学习10_ELK系列--实时日志分析系统ELK 部署与运行中的问题汇总
- P7990-[USACO21DEC]Closest Cow Wins S【堆,贪心】
- 3 帮助命令、用户管理、压缩
- 服务器操作系统的安装步骤,服务器操作系统的安装步骤
- 【JS 逆向百例】层层嵌套,某加速商城 RSA 加密
- python嵌套列表法实现树_python – 将嵌套的括号树转换为嵌套列表
- iosselect简单使用(三级联动)
- 利用Kubernetes名称空间来管理内存和CPU资源(二)
- 轻松实现函数计算文件上传下载
- 蓝桥杯 ALGO-120 算法训练 学做菜
- 惠普1020plus无法连接计算机,惠普1020打印机连不上是怎么回事
- redis 删除操作命令
- python爬取英雄联盟所有皮肤_python爬取lol英雄皮肤
- Windows10安装Wing FTP Server操作说明
- java实现can通信_[MicroPython]TPYBoard v102 CAN总线通信
- Domain Adaptive在无监督语义分割上的应用
- 关于3dmax模型导入到u3d中时,坐标会旋转的问题
- python在匿名函数作和_python内置函数和匿名函数