Pytorch中torch.load()加载预训练权重报错

我用GPU训练了一个模型,想在本机(只有CPU)加载测试时出错:

    raise RuntimeError('Attempting to deserialize object on a CUDA '
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()添加 map_location=torch.device('cpu') 参数即可

 

posted @ 2021-11-01 19:07  Rogn  阅读(1926)  评论(0编辑  收藏  举报