D:\Downloads\Anaconda\python.exe "D:\Downloads\Pycharm\Mycode\Binding gesture\demo.py" Traceback (most recent call last): File "D:\Downloads\Pycharm\Mycode\Binding gesture\demo.py", line 407, in <module> handRecognize = HandRecognize() File "D:\Downloads\Pycharm\Mycode\Binding gesture\demo.py", line 115, in __init__ self.modelGCN.load_state_dict(torch.load('demo/saveModel/handsModel.pth')) File "C:\Users\CHL\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 809, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "C:\Users\CHL\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 1172, in _load result = unpickler.load() File "C:\Users\CHL\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 1142, in persistent_load typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location)) File "C:\Users\CHL\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 1116, in load_tensor wrap_storage=restore_location(storage, location), File "C:\Users\CHL\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 217, in default_restore_location result = fn(storage, location) File "C:\Users\CHL\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 182, in _cuda_deserialize device = validate_cuda_device(location) File "C:\Users\CHL\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 166, in validate_cuda_device 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. 进程已结束,退出代码1
时间: 2023-07-17 07:03:21 浏览: 202
解决PyCharm的Python.exe已经停止工作的问题
5星 · 资源好评率100%
根据错误信息,您的代码尝试在CUDA设备上反序列化对象,但是`torch.cuda.is_available()`返回False,这意味着您的系统上没有可用的CUDA设备。因此,您应该使用`torch.load`函数的`map_location`参数将模型加载到CPU上。
您可以尝试修改加载模型的代码,如下所示:
```python
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
model = torch.load('demo/saveModel/handsModel.pth', map_location=device)
```
这样,在有可用的CUDA设备时,模型将被加载到CUDA设备上;如果没有可用的CUDA设备,则模型将被加载到CPU上。
尝试使用上述代码加载模型,看看是否可以解决问题。如果仍然遇到错误,请确保您已正确安装CUDA并配置了正确的环境。
阅读全文