解决GPU--CPU转换以及加载多GPU模型后使用pytorch的DataParallel()时出现的错误

1、解决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=‘cpu’ to map your storages to the CPU.

参考链接:
https://www.cnblogs.com/xiaodai0/p/10413711.html

改为:torch.load(“0.9472_0048.weights”,map_location=‘cpu’)

2、解决RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0])

参考链接:https://blog.csdn.net/qq_37088976/article/details/98186931?utm_medium=distribute.pc_relevant_t0.none-task-blog-searchFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-searchFromBaidu-1.control

model = nn.DataParallel(model,device_ids=[0,1]) 
device = torch.device("cuda:0" ) 
model.to(device)

或者:

model = nn.DataParallel(model,device_ids=[0]) 
device = torch.device("cuda:0" ) 
model.to(device)

总结一下自己遇到的错误及解决方案~
帮助大家更快解决Bug!

你可能感兴趣的:(#,笔记)