RuntimeError: Attempting to deserialize object on a CUDA device but torch.cu
时间: 2023-11-13 07:53:00 浏览: 62
RuntimeError:尝试在CUDA设备上反序列化对象,但torch.cuda.is_available()为False。如果您正在运行的是仅CPU的机器,请使用torch.load并设置map_location='cpu'将存储映射到CPU。这个错误通常发生在尝试在没有可用的CUDA设备的情况下加载已经在CUDA设备上训练过的模型。解决这个问题的方法是使用map_location参数将模型加载到CPU上。
相关问题
untimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False.
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. 如果你在一个仅有CPU的机器上运行,请使用torch.load并设置map_location=torch.device('cpu')将存储映射到CPU上解决这个问题。你可以在加载模型时添加map_location='cpu'参数,然后将模型放到CPU上进行运算。例如:
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
weights = torch.load('yolov.pt', map_location='cpu')
model = weights['model']
model = model.half().to(device)
_ = model.eval()
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False 这个错误通常发生在使用PyTorch加载保存在GPU上的模型时,但是当前环境没有可用的CUDA设备。要解决这个问题,你可以使用torch.load函数,并指定map_location参数为torch.device('cpu')或'map_location='cpu'',将模型加载到CPU上。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![apk](https://img-home.csdnimg.cn/images/20210720083646.png)