
PyTorch
糖公子没来过
学生一枚
展开
-
测试test
argmaxWhen to testtest once per several batch test once per epoch epoch V.S. step?原创 2021-09-14 15:43:24 · 65 阅读 · 0 评论 -
激活函数与GPU加速
激活函数simplyGPU accelerated注意,在0.3版本之前是用的.cpu()或.cuda()方法,到了0.4以及1.0版本之后变成了.to(device)方法,这样的话如果想要更改cpu或gpu的使用只需要改变device中的参数即可,方便了很多,比较推荐torch.device('cuda:0')表示在第一个GPU上进行加速,如果有不同的GPU,可以使用不同的索引代表不同的GPU...原创 2021-09-14 15:21:17 · 230 阅读 · 0 评论 -
PyTorch全连接层
nn.Linearrelu?conciselyinherit from nn.Module init layer in __init__ implement forward()step 1step 2step 3nn.ReLU v.s. F.relu()class-style API 因此需要先实例化 function-style API 因此可以直接传参 Train...原创 2021-09-14 15:01:06 · 673 阅读 · 0 评论 -
多分类问题实例
Network Architecturew1, b1 = torch.randn(200, 784, requires_grad=True),\ torch.zeros(200, requires_grad=True)w2, b2 = torch.randn(200, 200, requires_grad=True),\ torch.zeros(200, requires_grad=True)w3, b3 = torch.randn(10, 200, re...原创 2021-09-14 11:19:09 · 389 阅读 · 0 评论 -
2D函数优化实例
一个简单函数的优化问题plotdef himmelblau(x): return (x[0] ** 2 + x[1] - 11) ** 2 + (x[0] + x[1] ** 2 - 7) ** 2x = np.arange(-6, 6, 0.1)y = np.arange(-6, 6, 0.1)print('x,y range:', x.shape, y.shape)X, Y = np.meshgrid(x, y)print('X,Y maps:', X.shap...原创 2021-09-14 10:16:38 · 182 阅读 · 0 评论 -
PyTorch基础操作
创建TensorImport from numpytorch.from_numpy(a)Import from Listtorch.tensor() 中仅可以给出具体的数值,也就是tensor中的数值但是 torch.FloatTensor() 中既可以给具体的数值(通过List方式给出),也可以不加 [] 而给出tensor的“dim”,比如torch.FloatTensor(3, 4),使用时最好使用后者,以便与torch.tensor()方法区分开uniniti原创 2021-09-13 22:30:48 · 528 阅读 · 0 评论 -
Auto-Encoders
原创 2021-09-13 10:54:45 · 148 阅读 · 0 评论 -
卷积神经网络CNN
原创 2021-09-11 22:09:42 · 83 阅读 · 0 评论 -
Momentum and Learning rate decay
Momentum 原理上面的是梯度下降方法的核心公式,第三个式子是加了Momentum势能的公式可以发现Momentum只是在原本公式的基础上加上了一项“上一步的向量”,也就是说在Momentum中这一步往哪边走走多少不光取决于梯度下降的计算结果,还取决于上一步的方向和大小无Momentum的普通梯度下降方法的直观理解可以看到轨迹在一开始比较散乱,而且最终也并没有找到全局最优解,只是找到了一个局部最优点有Momentum的普通梯度下降方法的直观理解可以看到加上势能这一项之后,轨.原创 2021-09-10 10:18:36 · 107 阅读 · 0 评论 -
PyTorch之MLP反向传播
Chain ruleMulti-output PerceptronMulti-Layer Perceptron原创 2021-09-07 11:14:39 · 192 阅读 · 0 评论 -
创建tensor
Import from numpyImport from List原创 2021-09-06 09:55:12 · 85 阅读 · 0 评论 -
PyTorch学习之线性回归练习+手写数字识别初体验
线性回归练习loss = (WX + b - y)^2def compute_error_for_line_given_points(b, w, points): totalError = 0 for i in range(0, len(points)): x = points[i, 0] y = points[i, 1] totalError += (y - (w * x + b)) ** 2 return totalErr原创 2021-09-04 11:22:49 · 335 阅读 · 0 评论