首页 > 解决方案 > 模块“tensorflow”没有属性“contrib”

问题描述

我正在尝试使用 Tensorflow Object-Detection-API 训练我自己的自定义对象检测器

我在我的谷歌计算引擎中使用“pip install tensorflow”安装了 tensorflow。然后我按照该站点上的所有说明进行操作:https ://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html

当我尝试使用 train.py 时,我收到以下错误消息:

回溯(最后一次调用):文件“train.py”,第 49 行,从 object_detection.builders import dataset_builder 文件“/usr/local/lib/python3.6/dist-packages/object_detection-0.1->py3.6 .egg/object_detection/builders/dataset_builder.py”,第 27 行,从 object_detection.data_decoders 导入 tf_example_decoder 文件“/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection /data_decoders/tf_example_decoder.py",第 27 行,在 slim_example_decoder = tf.contrib.slim.tfexample_decoder AttributeError: 模块 'tensorflow' 没有属性 'contrib'

当我尝试学习 tensorflow 版本时,我也会得到不同的结果。

python3 -c '将张量流导入为 tf; 打印(tf。版本)':2.0.0-dev20190422

当我使用

pip3 显示张量流:

名称:tensorflow 版本:1.13.1 总结:TensorFlow是一个开源的机器学习框架,适合所有人。主页:https ://www.tensorflow.org/ 作者:Google Inc. 作者电子邮件:opensource@google.com 许可证:Apache 2.0 位置:/usr/local/lib/python3.6/dist-packages 要求: gast, astor, absl-py, tensorflow-estimator, keras-preprocessing, grpcio, 六, keras-applications, wheel, numpy, tensorboard, protobuf, termcolor

    sudo python3 train.py --logtostderr --train_dir=training/ -- 
    pipeline_config_path=training/ssd_inception_v2_coco.config

我应该怎么做才能解决这个问题?除了以下内容,我找不到有关此错误消息的任何信息:tensorflow 'module' object has no attribute 'contrib'

标签: tensorflow

解决方案


tf.contrib从 TF 2.0 alpha 开始已移出 TF。
看看这些 tf 2.0 发行说明https://github.com/tensorflow/tensorflow/releases/tag/v2.0.0-alpha0
您可以使用tf_upgrade_v2脚本 将 TF 1.x 代码升级到 TF 2.x :/ /www.tensorflow.org/alpha/guide/upgrade


推荐阅读