You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行TensorFlow目标检测训练命令时遇AttributeError错误求助

问题详情

执行的训练命令

python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_resnet101_kitti.config

报错内容

File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\util\module_wrapper.py", line 232, in _getattr
    attr = getattr(self._tfmw_wrapped_module, name)
AttributeError: module 'tensorflow_estimator.python.estimator.api._v1.estimator' has no attribute 'slim'

环境版本

  • bert-tensorflow: 1.0.1
  • tensorflow: 2.11.0
  • tensorflow-estimator: 2.11.0
  • tensorflow-intel: 2.11.0
  • tensorflow-io-gcs-filesystem: 0.29.0
  • tensorflow-object-detection-api: 0.1.1
  • Python: 3.7.9
解决方法

方法1:降级TensorFlow到兼容版本

tensorflow-object-detection-api 0.1.1基于TensorFlow 1.x开发,和TF2.x不兼容,直接降级到TF1.15.x:

pip uninstall tensorflow tensorflow-estimator tensorflow-intel -y
pip install tensorflow==1.15.5 tensorflow-estimator==1.15.1

方法2:修改代码适配TF2.x

如果不想降级,先安装tf-slim替代原有的slim模块:

pip install tf-slim

找到代码中引用estimator.slim的位置,将其替换为tf_slim,比如把:

from tensorflow_estimator.python.estimator.api._v1.estimator import slim

改为:

import tf_slim as slim

全局替换代码中所有estimator.slim调用为slim。

方法3:升级目标检测API到TF2兼容版

卸载旧版API,安装适配TF2.x的最新版本:

pip uninstall tensorflow-object-detection-api -y
pip install --upgrade tensorflow-object-detection-api

注意:新版API需要使用TF2.x格式的pipeline配置文件,需对应调整原配置文件的结构参数。

内容的提问来源于stack exchange,提问作者Fady Hanna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 17:20:43