File ~\AppData\Roaming\Python\Python310\site-packages\google\protobuf\descriptor.py:561 in __new__
时间: 2023-09-26 15:06:34 浏览: 204
这个错误通常是由于安装的 protobuf 版本与使用的代码不兼容引起的。请检查您安装的 protobuf 版本是否与您的代码兼容。如果您使用的是旧版本的代码,请尝试安装旧版本的 protobuf。如果您使用的是新代码,请升级 protobuf 版本。您还可以尝试从源代码重新安装 protobuf,以确保它与您的代码兼容。
相关问题
File ~\AppData\Roaming\Python\Python310\site-packages\keras\saving\legacy\saved_model\layer_serialization.py:23 from keras.saving.legacy.saved_model import save_impl File ~\AppData\Roaming\Python\Python310\site-packages\keras\saving\legacy\saved_model\save_impl.py:34 from keras.saving.legacy.saved_model import load as keras_load File ~\AppData\Roaming\Python\Python310\site-packages\keras\saving\legacy\saved_model\load.py:29 from keras.protobuf import saved_metadata_pb2 File ~\AppData\Roaming\Python\Python310\site-packages\keras\protobuf\saved_metadata_pb2.py:14 from keras.protobuf import versions_pb2 as keras_dot_protobuf_dot_versions__pb2 File ~\AppData\Roaming\Python\Python310\site-packages\keras\protobuf\versions_pb2.py:19 _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'keras.protobuf.versions_pb2', globals()) File ~\anaconda4\lib\site-packages\google\protobuf\internal\builder.py:108 in BuildTopDescriptorsAndMessages module[name] = BuildMessage(msg_des) File ~\anaconda4\lib\site-packages\google\protobuf\internal\builder.py:85 in BuildMessage message_class = _reflection.GeneratedProtocolMessageType( TypeError: A Message class can only inherit from Message, not (<class 'google.protobuf.message.Message'>,)
这个错误是由于 protobuf 库的版本不兼容导致的。建议你升级 protobuf 库的版本,或者降低 Keras 的版本。你可以尝试执行以下命令升级 protobuf 库:
```
pip install protobuf --upgrade
```
如果还是不能解决问题,你可以考虑降低 Keras 的版本。你可以执行以下命令来降低 Keras 的版本:
```
pip install keras==2.2.4
```
希望这些解决方案可以帮助到你。
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
根据错误信息,您的代码尝试在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并配置了正确的环境。
阅读全文