Keras 中的类型错误:传递 shuffle= "batch"即使已经提供了 shuffle= "batch"



我正在尝试使用 fit(( 方法和 tf.keras 训练我的模型,因为输入数据来自 hdf5 文件,所以我将参数 shuffle='batch' 传递给 fit(( 方法。但是在第一个纪元结束后,会出现以下错误:

TypeError: TypeError while preparing batch. If using HDF5 input data, pass shuffle="batch".

这是我的fit((方法:

model.fit(
    x=features_train,
    y=topics_train,
    batch_size=16384,
    epochs=35,
    callbacks=create_callbacks(),
    validation_data=(features_val, topics_val),
    shuffle='batch'
)

变量features_trainfeatures_val取自 hdf5 文件。

通过将features_val转换为numpy数组来解决它。

features_val_arr = np.array(features_val)
model.fit(
    x=features_train,
    y=topics_train,
    batch_size=16384,
    epochs=35,
    callbacks=create_callbacks(),
    validation_data=(features_val_arr, topics_val),
    shuffle='batch'
)

最新更新