PyTorch学习第七天

本文介绍了如何在PyTorch中利用GPU进行模型训练,包括cuda()函数的应用、设备设置以及模型在GPU和CPU间的映射。重点讲述了在GoogleColab中的GPU训练实践,并提到了模型验证时将GPU训练的模型加载到CPU上的步骤。
摘要由CSDN通过智能技术生成

        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'))

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值