尝试导入keras时,“TypeError:需要消息描述符,但获得了描述符”

yzuktlbb  于 2023-01-09  发布在  其他
关注(0)|答案(2)|浏览(251)

我想把这个

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Conv2D, Flatten, Dense
from tensorflow.keras.callbacks import EarlyStopping

我得到这个错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-5869267b9269> in <module>
----> 1 from tensorflow.keras import Sequential
      2 from tensorflow.keras.layers import Conv2D, Flatten, Dense
      3 from tensorflow.keras.callbacks import EarlyStopping

~\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     26 
     27 # pylint: disable=g-bad-import-order
---> 28 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     29 from tensorflow.python.tools import module_util as _module_util
     30 

~\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
     50 
     51 # Protocol buffers
---> 52 from tensorflow.core.framework.graph_pb2 import *
     53 from tensorflow.core.framework.node_def_pb2 import *
     54 from tensorflow.core.framework.summary_pb2 import *

~\Anaconda3\lib\site-packages\tensorflow\core\framework\graph_pb2.py in <module>
     14 
     15 
---> 16 from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
     17 from tensorflow.core.framework import function_pb2 as tensorflow_dot_core_dot_framework_dot_function__pb2
     18 from tensorflow.core.framework import versions_pb2 as tensorflow_dot_core_dot_framework_dot_versions__pb2

~\Anaconda3\lib\site-packages\tensorflow\core\framework\node_def_pb2.py in <module>
     14 
     15 
---> 16 from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
     17 
     18 

~\Anaconda3\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py in <module>
     14 
     15 
---> 16 from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
     17 from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
     18 from tensorflow.core.framework import types_pb2 as tensorflow_dot_core_dot_framework_dot_types__pb2

~\Anaconda3\lib\site-packages\tensorflow\core\framework\tensor_pb2.py in <module>
     14 
     15 
---> 16 from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
     17 from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
     18 from tensorflow.core.framework import types_pb2 as tensorflow_dot_core_dot_framework_dot_types__pb2

~\Anaconda3\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py in <module>
     90 ResourceHandleProto = _reflection.GeneratedProtocolMessageType('ResourceHandleProto', (_message.Message,), dict(
     91   DESCRIPTOR = _RESOURCEHANDLEPROTO,
---> 92   __module__ = 'tensorflow.core.framework.resource_handle_pb2'
     93   # @@protoc_insertion_point(class_scope:tensorflow.ResourceHandleProto)
     94   ))

TypeError: Expected a message Descriptor, got Descriptor

我无意中不知道为什么它突然这样做时,它以前是好的。我尝试了解决方案,为那些谁经历了一个"期待字节"错误无济于事。它也似乎没有人得到这个错误之前。
非常感谢你的帮助!

0s7z1bwu

0s7z1bwu1#

如果您在M1/M2上使用tensorflow...您可能安装了一个软件包,该软件包更改了tensorflow-deps所需的protobuf版本。我建议使用以下命令重新安装推荐的软件包:
对于tensorflow 〉2.10:

pip install protobuf==3.19.1
nsc4cvqm

nsc4cvqm2#

这对我很有效!
1.卸载TensorFlow并重新安装(tensorflow==1.0.1对我来说)

  1. pip install protobuf==3.6

相关问题