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

Keras技术求助:无法从keras.models导入Input类的报错问题

解决ImportError: cannot import name 'Input' from 'keras.models'

问题根源

Input类属于Keras的层(layers)模块,并非模型(models)模块,错误地从keras.models导入不属于该模块的API,因此触发ImportError。

解决方案

直接修改导入语句,从正确的模块导入:

# 正确导入方式
from keras.layers import Input

如果项目使用的是TensorFlow整合版的Keras,也可以使用以下兼容性更好的导入方式:

from tensorflow.keras.layers import Input

验证

导入后可通过以下代码快速验证是否正常工作:

# 创建简单输入张量测试
input_tensor = Input(shape=(10,))
print(input_tensor.shape)

内容的提问来源于stack exchange,提问作者Abhishek Jain

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 17:30:40