解决报错:RuntimeError: Invalid device string: ‘cuda:0‘

错误再现:

在这里插入图片描述

出错原因:

os.environ['CUDA_VISIBLE_DEVICES'] = '0'
device = torch.device('cuda:0' if torch.cuda.is_available() and use_cuda else 'cpu')

应修改为:

os.environ['CUDA_VISIBLE_DEVICES'] = '0'
device = torch.device('cuda' if torch.cuda.is_available() and use_cuda else 'cpu')

至于为什么这样改,还不清楚,欢迎大佬评论区留言!

猜你喜欢

转载自blog.csdn.net/qq_44824148/article/details/121021722