pytorch
Immortal stars
这个作者很懒,什么都没留下…
展开
-
nn.embedding
来源于博主: https://zhuanlan.zhihu.com/p/647536930,感觉写的清晰明了!原创 2023-09-15 09:24:13 · 177 阅读 · 0 评论 -
Detectron2 安装踩坑
设备:NVIDIA GeForce RTX 3090。原创 2023-09-13 17:00:32 · 1215 阅读 · 2 评论 -
VIT算法模型源码调试时:ModuleNotFoundError: No module named ‘utils.scheduler‘
ModuleNotFoundError: No module named 'utils.scheduler'原创 2022-12-13 09:21:33 · 310 阅读 · 1 评论 -
详解 torch.max 函数
torch.max(input) → Tensor返回输入tensor中所有元素的最大值例子:import torcha = torch.randn(1, 3) # a是随机生成的,每次运行结果都不一样a_max = torch.max(a)print(a_max)输出:tensor([[-0.6409, 0.4322, -0.6669]])tensor(0.4322)torch.max(input, dim, max=None, max_indices=None) -原创 2022-05-02 10:38:53 · 1348 阅读 · 0 评论 -
RuntimeError: CUDA out of memory.
在学习3D点云:Pointnet2时出现以下错误:RuntimeError: CUDA out of memory. Tried to allocate 256.00 MiB (GPU 0; 11.00 GiB total capacity; 1.90 GiB already allocated; 7.46 GiB free; 2.03 GiB reserved in total by PyTorch)在配置参数是batch_size设定是的太大,由于硬件限制,改小一些可以运行了。网上还有一篇博客写原创 2022-02-15 19:21:57 · 1098 阅读 · 0 评论 -
Pytorch框架之tensor.equal和tensor.eq--判断相等
行人重识别Relation-Aware Global Attention的部分代码。 N = dist_mat.size(0) # 8 is_pos = labels.expand(N, N).eq(labels.expand(N, N).t()) #print(is_pos.shape) is_neg = labels.expand(N, N).ne(labels.expand(N, N).t()) #print(is_neg.shape)一、测试eq()函数:import torch原创 2022-02-14 11:07:39 · 1328 阅读 · 0 评论 -
pytorch中卷积函数参数
对于pytorch深度学习框架,二维卷积nn.Conv2d对于宽度和高度都进行卷积运算,其定义如下:class torch.nn.Conv2d(in_channels, out_channels, kennel_size, stride=1, padding=0, dilation=1, groups=1, bias=true)in_channels(int) 输入特征图的通道数out_channels(int) 输出特征图的通道数kenal_size(int or tuple) 卷积核大小st原创 2022-02-13 22:17:13 · 973 阅读 · 0 评论 -
Pytorch——tensor.expand_as()函数
行人重识别Relation-Aware Global Attention的部分代码。 W_ys = self.W_spatial(ys) # W_ys的维度是[8, 1, 64, 32] 是空间位置特征权重 # print(W_ys.shape) # x的维度是[8, 256, 64, 32] if not self.use_channel: out = F.sigmoid(W_ys.expand_as(x)) * x # 位置特征,不同特征图,位置相同的 re原创 2022-02-13 21:52:23 · 1129 阅读 · 0 评论 -
permute函数
permute():将tensor的维度换位。permute(多维数组,[维数换位顺序])比如:a=rand(2,3,4); %a是一个三维数组,各维的长度分别为:2,3,4permute(a,[2,1,3]) %实现了交换第一维和第二维,a变成3*2*4的矩阵原创 2022-02-13 16:26:08 · 1083 阅读 · 0 评论 -
torch.long()
torch.long():向下取整>>> b1 = torch.rand(3,3)>>> b1tensor([[0.7498, 0.2052, 0.9352], [0.1171, 0.2046, 0.1682], [0.3003, 0.7483, 0.0089]])>>> b1.long()tensor([[0, 0, 0], [0, 0, 0], [0, 0, 0]]).原创 2022-02-10 17:19:26 · 12353 阅读 · 4 评论 -
Pytorch使用 nn.ModuleList() 和nn.Sequential()编写神经网络模型
一、使用传统方法创建模型import numpy as npimport torchimport torch.nn as nn#准备数据data=np.linspace(-2*np.pi,2*np.pi,400) # -2PI 到 2PI 区间分成400份的所有点x=torch.tensor(data.reshape(400,-1),dtype=torch.float)y=torch.tensor(np.sin(data.reshape(400,-1)),dtype=torch.float转载 2022-02-05 09:20:56 · 558 阅读 · 0 评论 -
F.pad函数
1. F.pad函数定义F.pad是pytorch内置的tensor扩充函数,便于对数据集图像或中间层特征进行维度扩充,下面是pytorch官方给出的函数定义。torch.nn.functional.pad(input, pad, mode='constant', value=0)函数变量说明:input需要扩充的tensor,可以是图像数据,抑或是特征矩阵数据pad扩充维度,用于预先定义出某维度上的扩充参数mode扩充方法,’constant‘, ‘reflect’ or ‘repl原创 2022-02-03 12:40:25 · 1014 阅读 · 1 评论 -
pytorch中squeeze()和unsqueeze()函数介绍
一、unsqueeze()函数 1. 首先初始化一个a 可以看出a的维度为(2,3) 2. 在第二维增加一个维度,使其维度变为(2,1,3) 可以看出a的维度已经变为(2,1,3)了,同样如果需要在倒数第二个维度上增加一个维度,那么使用b.unsqueeze(-2) 二、squeeze()函数介绍 1. 首先得到一个维度为(1,2,3)的tensor(张量) 由图中可以看出c的维度为(1,...转载 2022-02-03 11:03:44 · 334 阅读 · 0 评论