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

TensorFlow Object Detection验证时触发AttributeError错误求助

解决TensorFlow Object Detection验证时的AttributeError问题

错误详情

运行验证脚本时触发如下错误:

AttributeError: module 'keras._tf_keras.keras.layers' has no attribute 'experimental'

验证代码:

VERIFICATION_SCRIPT = os.path.join(paths['APIMODEL_PATH'], 'research', 'object_detection', 'builders', 'model_builder_tf2_test.py')
# Verify Installation
!python {VERIFICATION_SCRIPT}

错误原因

你安装的Keras 3.1.1是独立版本,与当前TensorFlow 2.16.x、tf-models-official 2.5.1版本不兼容。Keras 3重构了模块结构,移除了keras.layers.experimental的旧有路径,导致检测脚本无法找到该属性。

解决方案

1. 卸载独立Keras,切换到TensorFlow自带的tf_keras

执行以下命令:

pip uninstall -y keras
pip install tf-keras==2.16.0

(TensorFlow 2.16.1对应tf_keras 2.16.0为兼容版本)

2. 升级tf-models-official到兼容版本

旧版tf-models-official(2.5.1)与TensorFlow 2.16匹配度差,执行升级:

pip install --upgrade tf-models-official

若升级后出现其他依赖问题,可尝试指定精准匹配版本:

pip install tf-models-official==2.16.0

3. 重新运行验证脚本

完成上述操作后,再次执行你的验证代码即可。

内容的提问来源于stack exchange,提问作者Hugo Misael Barajas Hernández

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 19:53:10