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

Keras调用model.fit传入Sequence输入时提示不支持y参数报错

报错根因

触发ValueError: \y` argument is not supported when using `keras.utils.Sequence` as input的核心原因是model.fit()传参错位: 你调用fit时使用位置传参,Keras接口定义中fit的第二个位置参数是训练集对应的标签参数y,你传入的第二个位置值是验证集test_set(属于keras.utils.Sequence`类型),而当输入x为Sequence类型时,数据集本身已经内置标签,接口不支持额外传入y参数,因此直接抛出错误。

修复方案

不要靠位置顺序传参,所有非训练集x的参数都使用关键字形式显式指定,修正后的拟合代码如下:

# fit the model
# Run the cell. It will take some time to execute
r = model.fit(
    training_set,
    validation_data=test_set,
    epochs=10,
    steps_per_epoch=len(training_set),
    validation_steps=len(test_set)
)
额外注意事项
  • 凡是用keras.utils.Sequence及其子类(比如ImageDataGenerator生成的目录迭代器)作为模型输入时,不需要单独传入标签y,数据集迭代时会自动返回(样本, 标签)对。
  • 调用Keras模型接口时,除了第一个输入数据参数外,其余参数尽量用参数名=值的关键字形式传参,避免参数顺序记错导致的错位报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.01 05:12:16