简体   繁体   中英

'TypeError: Expected a message Descriptor, got Descriptor' when trying to import keras

I was trying to import this

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

I got this error:

---------------------------------------------------------------------------
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

I have accidentally no idea why it suddenly did this when it was fine before. I tried the solutions for those who experienced a 'expecting bytes' error to no avail. It also seems that no one had gotten this error before.

Thank you so much for the help!

This worked for me!

  1. uninstall TensorFlow and reinstall it (tensorflow==1.0.1 for me)
  2. pip install protobuf==3.6

If you are using tensorflow on M1/M2...you may have installed a package that altered the version of protobuf required by tensorflow-deps . I recommended reinstalling the recommended package using:

For tensorflow > 2.10:

pip install protobuf==3.19.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM