gpt4 book ai didi

python - 训练 Keras 模型时使用稀疏数组表示标签

转载 作者:行者123 更新时间:2023-12-01 07:39:17 26 4
gpt4 key购买 nike

我正在构建一个 Keras 模型,将数据分类为 3000 个不同的类别,我的训练数据由大量样本组成,因此在用一种热编码对训练输出进行编码后,数据非常大(item_count * 3000 * 的大小) float +输入数据大小)是否可以将稀疏数组作为训练数据的输出传递给 keras,有什么建议的解决方案吗?

最佳答案

您可以通过使用稀疏_分类_交叉熵损失函数来使用基本事实的稀疏表示。

# assuming get_model() returns your Keras model with an output_shape == [None, 3000]
# assuming get_data() returns training data, with y_train having shape == [num_samples]

x_train, y_train = get_data()
model = get_model()
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, batch_size=16)

关于python - 训练 Keras 模型时使用稀疏数组表示标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56809249/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com