我尝试测试tensorflow模型园的安装,并在我的PowerShell:python object_detection/builders/model_builder_tf2_test.py中执行以下命令,从而得到以下错误消息:
Traceback (most recent call last):
File "...\Documents\TensorFlow\models\research\object_detection\builders\model_builder_tf2_test.py", line 21, in <module>
import tensorflow.compat.v1 as tf
File "...\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "...\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "...\Anaconda3\lib\site-packages\tensorflow\python\eager\context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "...\Anaconda3\lib\site-packages\tensorflow\core\framework\function_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "...\Anaconda3\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "...\Anaconda3\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "...\Anaconda3\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "...\Anaconda3\lib\site-packages\tensorflow\core\framework\tensor_shape_pb2.py", line 36, in <module>
_descriptor.FieldDescriptor(
File "...\Anaconda3\lib\site-packages\google\protobuf\descriptor.py", line 560, in __new__
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates在我看来,我需要安装一个比3.19.0更晚的版本。因为_pb2.py文件中的cal。因此,我使用pip show protobuf查找了protoc的版本,并得到了以下结果:
Name: protobuf
Version: 4.21.1
Summary:
Home-page: https://developers.google.com/protocol-buffers/
Author: protobuf@googlegroups.com
Author-email: protobuf@googlegroups.com
License: 3-Clause BSD License
Location: ...\anaconda3\lib\site-packages
Requires:
Required-by: tensorflow, tensorflow-metadata, tensorflow-hub, tensorflow-datasets, tensorboard, proto-plus, googleapis-common-protos, google-api-core, apache-beam因此,已经安装了一个比3.19.0更晚的版本,但它无法工作。
为什么它不起作用,我能做些什么呢?
关于您的信息:我在这个站点上使用了tensorflow教程。
发布于 2022-10-05 19:46:47
谷歌在protobuf-4.21.0中引入了一项新的重大变革。任何晚于此的事情都行不通。您需要安装protobuf 3.20.x或早期的(如3.20.3版)。
或者,您可以设置它推荐的环境变量。我发现将它放入您的__init__.py文件很方便,如下所示:
import os
# Google introduced an incompatibility into protobuf-4.21.0
# that is not backwards compatible with many libraries.
# Once those libraries have updated to rebuild their _pb2.py files,
# this can be removed.
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"另一个解决方案是升级Tensorflow,如果他们有一个新版本,用最新的protobuf重新构建。
https://stackoverflow.com/questions/72485953
复制相似问题