TensorFlow2.2运行目标检测API报register_filesystem_plugin属性不存在如何解决
问题描述
我正在使用TF2目标检测API,按照官方文档的「安装」和「Python包安装」步骤操作。运行环境为大学的HPC集群,通过模块系统加载的TensorFlow版本为2.2.0。
加载该TF2模块时它会自动绑定所有依赖项,完成安装步骤后,我尝试运行安装测试脚本或者实际训练任务,均报错提示 no attribute 'register_filesystem_plugin'。
据我了解,该接口是TF 2.7版本才提供的API,但受集群模块系统限制,我无法升降级TensorFlow版本。我已经尝试过多种方案,包括降级tensorflow_io,仍未解决问题。
我原本认为Object Detection API最低仅需要TF 2.2版本即可运行,为什么会调用2.7版本才有的特性?恳请各位提供解决思路,十分感谢!
完整报错栈如下:
Traceback (most recent call last): File "object_detection/model_main_tf2.py", line 32, in <module> from object_detection import model_lib_v2 File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/object_detection/model_lib_v2.py", line 30, in <module> from object_detection import inputs File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/object_detection/inputs.py", line 26, in <module> from object_detection.builders import model_builder File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/object_detection/builders/model_builder.py", line 37, in <module> from object_detection.meta_architectures import deepmac_meta_arch File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/object_detection/meta_architectures/deepmac_meta_arch.py", line 28, in <module> import tensorflow_io as tfio # pylint:disable=g-import-not-at-top File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/tensorflow_io/__init__.py", line 17, in <module> from tensorflow_io.python.api import * # pylint: disable=wildcard-import File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/tensorflow_io/python/api/__init__.py", line 19, in <module> from tensorflow_io.python.ops.io_dataset import IODataset File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/tensorflow_io/python/ops/__init__.py", line 96, in <module> plugin_ops = _load_library("libtensorflow_io_plugins.so", "fs") File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/tensorflow_io/python/ops/__init__.py", line 64, in _load_library l = load_fn(f) File "cluster/home/myname/thesis/env/lib/python3.7/site-packages/tensorflow_io/python/ops/__init__.py", line 56, in <lambda> load_fn = lambda f: tf.experimental.register_filesystem_plugin(f) is None AttributeError: module 'tensorflow._api.v2.experimental' has no attribute 'register_filesystem_plugin'
解决方案
问题根因
- 你拉取的是TensorFlow Models仓库的master分支代码,该分支的Object Detection API现在已经迭代适配更高版本的TensorFlow,官方标注的最低2.2版本要求是旧版代码的标准,新版代码引入了依赖高版本TF的组件,比如
deepmac_meta_arch模块会默认导入tensorflow_io - 你当前安装的
tensorflow_io版本和TF2.2不兼容,register_filesystem_plugin是TF2.7才提供的接口,只有0.13.0及更低版本的tensorflow_io才支持TF2.2
可行解决思路
方案1:降级到适配TF2.2的Object Detection API版本
直接拉取对应TF2.2的v2.2.0 tag版本的models仓库代码,重新安装即可,该版本完全兼容TF2.2,不会触发高版本API调用问题。
# 先卸载现有环境里已经安装的object_detection相关包 # 拉取v2.2.0版本的models仓库代码 cd models git checkout tags/v2.2.0 # 再按照该版本配套的安装文档重新编译安装object_detection即可
方案2:修改现有代码适配TF2.2
如果一定要使用当前版本的Object Detection API,可以分两步操作:
- 卸载现有不兼容的tensorflow_io版本,安装匹配TF2.2的0.13.0版本:
pip uninstall -y tensorflow-io tensorflow-io-gcs-filesystem pip install tensorflow-io==0.13.0
- 如果安装后仍有报错,可以直接修改源码跳过不需要的依赖导入:找到
object_detection/meta_architectures/deepmac_meta_arch.py文件,注释掉import tensorflow_io as tfio这行代码即可。如果你不需要使用DeepMAC相关的实例分割功能,这行导入完全不影响常规目标检测任务的运行。
方案3:自定义私有环境绕开集群模块限制
集群的模块系统只会限制全局加载的软件版本,不会限制用户目录下私有虚拟环境的包版本。你可以自己创建conda或者venv虚拟环境,在环境中直接安装2.7及以上版本的TensorFlow,彻底解决版本兼容问题。
内容的提问来源于stack exchange,提问作者Pierre
相关产品推荐
相关产品推荐

