kZjPBD.jpg

随笔分类 -  深度学习 - torch

摘要:https://zhuanlan.zhihu.com/p/426906301 self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0 self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1 阅读全文
posted @ 2022-04-22 20:06 Through_The_Night 阅读(35) 评论(0) 推荐(0) 编辑
摘要:x = torch.tensor(2.0)x.requires_grad_(True)y = 2 * xz = 5 * x w = y + z.detach()w.backward() print(x.grad) => 2 本来应该x的梯度为7,但是detach()那一路切段了梯度的传播,导致5没有 阅读全文
posted @ 2022-04-03 21:16 Through_The_Night 阅读(66) 评论(0) 推荐(0) 编辑
摘要:def step(self): "Update parameters and rate" self._step += 1 rate = self.rate() for p in self.optimizer.param_groups: p['lr'] = rate self._rate = rate 阅读全文
posted @ 2022-04-03 16:13 Through_The_Night 阅读(134) 评论(0) 推荐(0) 编辑
摘要:import numpy as npfrom matplotlib import pyplot as plt t=np.arange(0.0,2.0,0.1)s=np.sin(t*np.pi)figure,ax=plt.subplots(1,1) ax.plot(t,s,'r*')ax.plot(t 阅读全文
posted @ 2022-03-04 15:21 Through_The_Night 阅读(33) 评论(0) 推荐(0) 编辑
摘要:1. 引言 我们都知道损失函数有很多种:均方误差(MSE)、SVM的合页损失(hinge loss)、交叉熵(cross entropy)。这几天看论文的时候产生了疑问:为啥损失函数很多用的都是交叉熵(cross entropy)?其背后深层的含义是什么?如果换做均方误差(MSE)会怎么样?下面我们 阅读全文
posted @ 2022-01-25 16:36 Through_The_Night 阅读(845) 评论(0) 推荐(0) 编辑
摘要:据pytorch的官方文档,torch.nn.functional里的cross_entropy是基于log_softmax和nll_loss实现的。没关系,通过最简单的torch原函数复现,可以较深理解当中的原理。 import torch def my_cross_entropy(input, 阅读全文
posted @ 2022-01-25 00:31 Through_The_Night 阅读(55) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示