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

Google Colab导入AutoKeras遇AttributeError问题求助

解决AutoKeras导入时的AttributeError问题

问题情况

在Google Colab中导入autokeras库时触发错误:AttributeError: module 'keras_tuner.engine' has no attribute 'tuner'。已执行!pip install autokeras,并更新了tensorflow、autokeras、keras及keras-tuner,但问题仍未解决。

错误详情

import autokeras as ak
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-85d187d68977> in <cell line: 1>()
----> 1 import autokeras as ak

4 frames
/usr/local/lib/python3.10/dist-packages/autokeras/__init__.py in <module>
     15 import keras_nlp
     16 
---> 17 from autokeras.auto_model import AutoModel
     18 from autokeras.blocks import BertBlock
     19 from autokeras.blocks import CategoricalToNumerical

/usr/local/lib/python3.10/dist-packages/autokeras/auto_model.py in <module>
     27 from autokeras import graph as graph_module
     28 from autokeras import pipeline
---> 29 from autokeras import tuners
     30 from autokeras.engine import head as head_module
     31 from autokeras.engine import node as node_module

/usr/local/lib/python3.10/dist-packages/autokeras/tuners/__init__.py in <module>
     13 # limitations under the License.
     14 
---> 15 from autokeras.tuners.bayesian_optimization import BayesianOptimization
     16 from autokeras.tuners.greedy import Greedy
     17 from autokeras.tuners.hyperband import Hyperband

/usr/local/lib/python3.10/dist-packages/autokeras/tuners/bayesian_optimization.py in <module>
     15 import keras_tuner
     16 
---> 17 from autokeras.engine import tuner as tuner_module
     18 
     19 

/usr/local/lib/python3.10/dist-packages/autokeras/engine/tuner.py in <module>
     28 
     29 
---> 30 class AutoTuner(keras_tuner.engine.tuner.Tuner):
     31     """A Tuner class based on KerasTuner for AutoKeras.
     32 

AttributeError: module 'keras_tuner.engine' has no attribute 'tuner'

解决方案

原因

keras-tuner最新版本的模块结构发生变更,当前安装的AutoKeras版本仍依赖旧的模块路径,导致属性查找失败。

修复步骤

  • 卸载冲突版本:
    !pip uninstall -y autokeras keras-tuner
    
  • 安装经过验证的兼容版本组合:
    !pip install autokeras==1.1.0 keras-tuner==1.4.7
    
  • 重启Colab运行时(点击顶部菜单Runtime -> Restart runtime)
  • 重新执行import autokeras as ak即可正常导入

内容的提问来源于stack exchange,提问作者Kaitlin Rentmeester

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 23:11:38