【常用库】【pytorch】基本部件
基本元件
1. 卷积
2. batchnorm
loss函数
torch.nn.MSELoss()
>>> a = torch.rand(3)
>>> a
tensor([0.2161, 0.2227, 0.9175])
>>> b = torch.rand(3)
>>> b
tensor([0.6976, 0.9149, 0.4918])
>>> mse = torch.nn.MSELOSS()
>>> mse(a, b)
tensor(0.2974)
>>> ((0.2161-0.6976)**2 + (0.2227-0.9149)**2 + (0.9175-0.4918)**2)/3
0.2974011933333333
MSELoss是求高斯距一个函数。
1. 均方误差函数(Mean Squared Eqation)
torch.nn.CrossEntropyLoss()
1.描述两个概率分布间的距离
2.交叉熵函数
import torch.nn as nn
loss = nn.CrossEntropyLoss()
input = torch.randn(3, 5, requires_grad=True)
target = torch.empty(3, dtype=torch.long).random_(5)
output = loss(input, target)
output.backward()
分类问题用Cross Entropy
回归问题用MSE
基本运算
加减乘除