1.概念
softMax:概率分布,将每个项的值/累加的值=每个结果出现的概率值
NLLLoss:就是把输出与Label对应的那个值拿出来,再去掉负号,再求均值
CrossEntropyLoss:就是把Softmax–Log–NLLLoss合并成一步
2.代码实现
import torch
from torchvision import transforms
from torchvision import datasets
from torch.utils.data import DataLoader
import torch.nn.functional as F
import torch.optim as optim
# prepare dataset
'''
Normalize:均值和方差
'''
batch_size = 64
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))]) # 归一化
train_dataset = datasets.MNIST(root='../dataset/mnist/', train=True, download=True, transform=transform)#trans转化
train_loader = DataLoader(train_dataset, shuffle=True, batch_size=batch_size)
test_dataset = datasets.MNIST(root='../dataset/mnist/', train=False, downlo