pytorch
程序员阿德
这个作者很懒,什么都没留下…
展开
-
pytorch loss = loss_func(output, label) 报错
在运行损失函数时 loss = loss_func(output, label) 时报了两个错 :1.RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target'这是因为label必须是 LongTensor 类型, 之前是 :lab...原创 2019-01-25 11:42:55 · 6395 阅读 · 1 评论 -
AttributeError: Can't get attribute 'Net' on module '__main__'
在使用pytorch加载模型时报错:torch.save(old_model, PATH)new_model = torch.load(PATH)AttributeError: Can't get attribute 'Net' on <module '__main__'> 解决办法:1、将类的定义添加到加载模型的这个py文件中,这个方法有点。。。2、使用官...原创 2019-01-31 13:07:37 · 32483 阅读 · 13 评论 -
训练模型时损失函数为nan
参考如下:https://oldpan.me/archives/careful-train-loss-nan-infhttps://blog.csdn.net/qq_38906523/article/details/81357895https://blog.csdn.net/u013732444/article/details/73344628https://blog.csdn.n...原创 2019-03-05 19:07:13 · 3326 阅读 · 0 评论 -
cudnn.benchmark = True
一般情况下需要在训练前加上如下这句: 1 torch.backends.cudnn.benchmark = true 据说这样可以增加程序的运行效率。那到底有没有这样的效果,或者什么情况下应该这样做呢?解决办法总的来说,大部分情况下,设置这个 flag 可以让内置的 cuDNN 的 auto-tuner 自动寻找最适合当前配置的高效算法,来达到优...原创 2019-04-19 17:22:15 · 285 阅读 · 0 评论 -
RuntimeError: CUDA error: an illegal memory access was encountered
使用pytorch进行文字识别时出现标题上的错误。1、在训练前添加如下语句:torch.backends.cudnn.benchmark = True没用2、将 batch_size 从 64 改为 32。没用3、在训练前添加如下语句:torch.cuda.set_device(id)我只有一个显卡,所以id=0,解析查看:https://di...原创 2019-04-19 20:03:05 · 18171 阅读 · 4 评论