错误一:RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device(‘cpu’) to map your storages to the CPU.

解决方法:在torch.load(xxx)后面添加map_location=torch.device('cpu')或者map_location='cpu'

示例
在这里插入图片描述
在这里插入图片描述

state_dict = torch.load(self.model_path)

在torch.load括号后面添加map_location=torch.device('cpu')或者map_location='cpu'

在这里修改如下:

state_dict = torch.load(self.model_path,map_location='cpu')
或
state_dict = torch.load(self.model_path,map_location='cpu')

修改之后,运行可能会出现以下错误:

错误二:AssertionError: Torch not compiled with CUDA enabled

解决方法:去掉所有的.cuda()

示例
在这里插入图片描述
点击蓝色部分字体,进入代码,定位到出错位置,可以看到这边转换为cuda运行,将其注释掉即可
在这里插入图片描述
注释掉,并保存
在这里插入图片描述
继续运行程序,找出.cuda(),并将其去掉
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Logo

Agent 垂直技术社区,欢迎活跃、内容共建,欢迎商务合作。wx: diudiu5555

更多推荐