pytorch
文章平均质量分 51
Da_Shan_
这个作者很懒,什么都没留下…
展开
-
损失函数之Diou和Ciou loss
损失函数DIoU CIoU转载 2022-07-24 16:01:45 · 389 阅读 · 0 评论 -
torch.max()和numpy.max()使用辨析
torch.max()原创 2022-07-12 16:36:24 · 498 阅读 · 0 评论 -
np.where 和 torch.where 用法
numpy.where() 有两种用法:numy.where(condition)只有condiiton,输出满足condition的元素的下标, 这里的坐标以tuple的形式给出,通常原数组有多少维,输出的tuple中就包含几个数组,分别对应符合条件元素的各维坐标torch.wheretorch.where()函数的作用是按照一定的规则合并两个tensor类型...原创 2022-06-30 15:54:09 · 517 阅读 · 0 评论 -
准确率(precision) 召回率(recall) mAP计算
precision 和 recall原创 2022-06-14 09:22:39 · 1214 阅读 · 0 评论 -
repeat()、tile() 在numpy和torch中的使用辨析
torch.repeat()原创 2022-05-29 23:24:05 · 1198 阅读 · 0 评论 -
expand() 函数在pytorch和numpy中的使用
Tensor.expand()tensor.expand()函数可以将维度值包含 1 的Tensor(如:torch.Size([1, n])或者torch.Size([n, 1]))的维度进行扩展。其具体的扩展规则如下:只能对维度值包含 1 的张量Tensor进行扩展,无需扩展的维度保持不变或置-1,即:Tensor的size必须满足:torch.Size([1, n]) 或者 torch.Size([n, 1]) 。扩展的Tensor不会分配新的内存,只是原来的基础上创建新的视图并返回;应用原创 2022-05-29 16:34:53 · 1676 阅读 · 0 评论 -
python 和 pytorch中的矩阵乘法
python和pytorch中的矩阵乘法原创 2022-05-28 23:08:54 · 573 阅读 · 0 评论 -
transpose() 函数在numpy和pytorch中的比较
transpose 在 numpy和pytorch中的比较原创 2022-05-28 17:26:40 · 279 阅读 · 0 评论 -
model.named_parameters()与model.parameters()
model.named_parameters()迭代打印model.named_parameters()将会打印每一次迭代元素的名字和param。并且可以更改参数的可训练属性from torchvision.models.shufflenetv2 import shufflenet_v2_x1_0model = shufflenet_v2_x1_0()for name, parameter in model.named_parameters(): print(name, parameter原创 2022-05-14 23:26:10 · 2512 阅读 · 0 评论 -
torch.isfinite()、torch.isinf()、torch.isnan()
torch.isfinite(tensor) 判断是否有界torch.isinf(tensor)判断是否无穷torch.isnan(tensor)判断是否为空以上三个函数都返回 bool 类型的mask举例说明:arr = torch.tensor((float('inf'), float('-inf'), float('nan')))mask1 = torch.isfinite(arr)tensor([False, False, False]) mask2 = torch.isi原创 2022-05-05 22:03:09 · 1220 阅读 · 0 评论 -
torch.chunk()
chunk可以对张量进行分块,返回一个张量列表torch.chunk(tensor, chunks, dim=0) → List of TensorsSplits a tensor into a specific number of chunks.Last chunk will be smaller if the tensor size along the given dimension dim is not divisible by chunks.(如果指定轴的元素个数被chunks除不尽,那么最后原创 2022-05-04 19:18:28 · 658 阅读 · 0 评论 -
torch.transpose()
首先transpose是为了转换矩阵维度的,在numpy和pytorch中的作用都是一样的,分别举例说明:arr = np.arange(24).reshape((2, 3, 4))[[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]]目标:将矩阵 arr 的0维度和1维度进行交换需要注意,transpose每次只能转换两个维度np.transpose(原创 2022-05-04 16:07:14 · 5141 阅读 · 0 评论 -
torch.nn.CrossEntropyLoss()
做分类任务经常用到 torch.nn.CrossEntropyLoss() 这个损失函数,之前只是简单的使用,但是对于其内部原理并不了解,现在学习一下内部原理softmax先从softmax函数开始在softmax的机制中,为获得输出层的输出(即最终的输出),我们不是将sigmoid()作用其上,而是采用的所谓softmax()。其输入为向量,输出为0~1之间的向量,其和为1。在分类任务中作为概率出现在交叉熵损失函数中。softmax(x)=exi∑jexj softmax(x) = \frac{原创 2022-05-01 11:08:52 · 874 阅读 · 0 评论 -
torch.rand 和 torch.randn
torch.rand(*size)生成在区间 [0,1) 之间的呈均匀分布的随机数torch.rand(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → TensorReturns a tensor filled with random numbers from a uniform distribution on the interval [0, 1)[0,1)The原创 2022-04-29 10:01:48 · 781 阅读 · 0 评论 -
nn.AdaptiveAvgPool2d()
自适应平均池化作用:指定输出的 H 和 W代码:input = torch.randn((1, 64, 8, 10))m = nn.AdaptiveAvgPool2d((1, 1))m1 = nn.AdaptiveAvgPool2d((None, 2))m2 = nn.AdaptiveAvgPool2d((5, 4))print(m(input).shape)print(m1(input).shape)print(m2(input).shape)torch.Size([1, 64,原创 2022-01-07 17:19:18 · 1296 阅读 · 0 评论 -
pytorch 学习
梯度消失或梯度爆炸当每一层的梯度是小于1的数,当进行反向传播时,随着网络越深,梯度越接近零反之,当每一层的梯度是大于1的数…所以通常需要对数据进行标准化处理,权重初始化,以及用BN层,在ResNet网络中使用了residual模块(残差模块)max()函数pytorch入门学习时,输出与标签常用max()函数进行比较import torchlabel = torch.tensor([0, 1, 2, 3, 4, 0])outputs = torch.tensor([[0.9, 0.4, 0原创 2022-01-03 18:53:12 · 1040 阅读 · 0 评论 -
pytorch初始化模型参数
pytorch初始化模型参数转载 2021-12-14 16:13:49 · 259 阅读 · 0 评论