![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pytorch
文章平均质量分 76
凡心curry
给予你诗意的理性
展开
-
pytorch损失函数与优化器
目录损失函数优化器模型建立总结 损失函数 torch.nn 中存在很多封装好的损失函数。比如均方差损失,用 torch.nn.MSELoss() 表示。 import torch import torch.nn as nn # 初始化数据集 X = torch.tensor([1, 2, 3, 4], dtype=torch.float32) Y = torch.tensor([2, 4, 6, 8], dtype=torch.float32) w = torch.tensor(0.0, dtype=to原创 2021-05-09 10:37:26 · 605 阅读 · 4 评论 -
pytorch神经网络算法
目录正向传播算法反向传播算法梯度下降算法人工实现pytorch实现 正向传播算法 设函数的输入数据为 xxx,参数为 www ,输出为 losslossloss。 正向传播过程如下: y^=x∗w\hat{y} = x*w y^=x∗w s=y−y^s = y-\hat{y}s=y−y^ loss=s2loss = s^2loss=s2 import torch def forward(x, y, w): # 其中 x,y 为输入数据,w为该函数所需要的参数 y_predicted原创 2021-05-08 20:59:01 · 467 阅读 · 2 评论 -
pytorch梯度计算
目录张量梯度梯度计算停止梯度梯度清空 张量 pytorch定义张量: import torch # 利用 torch.empty() 初始化指定大小的张量,如果不指定值的话,内容为随机值 # 传入的参数为想创建的张量大小 x = torch.empty(1) # scalar,大小为 1*1 的张量 print(x.size()) x = torch.empty(3) # vector, 1D,大小为 1*3 的张量 print(x.size()) x = torch.empty(2, 3) # m原创 2021-05-08 20:04:47 · 466 阅读 · 1 评论