Argmax作用:令output=[0.2, 0.3]横向找到最大值转换为更直观的类别结果Preds=[1]
分类模型的正确率问题
一、利用GPU训练
(1) .cuda()
if torch.cuda.is_available()
tudui = tudui.cuda()
loss_fn = loss_fn.cuda()
imgs = imgs.cuda()
targets = targets.cuda()
(2).device()
# 定义训练的设备
device = torch.device("cpu")
# device = torch.device("cuda:0")
# device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tudui.to(device)
loss_fn =loss_fn.to(device)
imgs = imgs.to(device)
targets = targets.to(device)
二、利用GPU训练——google colab
三、完整的模型验证(测试,demo)套路
即利用已经训练好的模型,然后给它提供输入
# 注
# 采用gpu训练的东西,要映射到cpu上
model = torch.load("tudui_29_gpu.pth", map_location=torch.device('cpu'))