python - 具有大量类别的 tflearn 标签编码

标签 python tflearn

我正在尝试调整 Convolutional Neural Net example of tflearn使用约 12000 个不同的类标签和超过 100 万个训练示例进行分类。在对标签进行一次性编码时,标签的数量显然是内存消耗的一个问题。我首先将字符串标签映射到连续整数,然后将它们作为列表传递给 to_categorical() 函数。以下代码会导致 MemoryError:

trainY = to_categorical(trainY, nb_classes=n_classes)

我是否必须像这样对标签进行编码,或者我应该使用与交叉熵不同的损失函数?我可以使用 tflearn 进行批量训练 - 我可以将生成器传递给 DNN.fit() 函数吗?

感谢您的建议!

最佳答案

在回归层link ,您可以指定输入的标签应在运行时进行 one-hot 编码

tflearn.layers.regression(incoming_net,
                          loss = 'categorical_crossentropy',
                          batch_size = 64,
                          to_one_hot = True,
                          n_classes = 12000)

这样你就不应该出现内存错误,因为标签在训练时会分批编码。

关于python - 具有大量类别的 tflearn 标签编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43279331/

相关文章:

python - tensorflow 和广播数学运算中的分段激活函数

python - 操作元组列表

python - pandas iterrows 和循环计数器的问题

python - 使用 python 发送 key 在 selenium 中不起作用

python-3.x - 值错误 : The passed save_path is not a valid checkpoint: C:\Users\User\model. tflearn

python - 属性错误 : 'generator' object has no attribute 'next'

python - turtle.onclick() 不能正常工作

python - 当我使用 tflearn 预测测试用例时,它显示 "Cannot feed value of shape (32, 32, 3) for Tensor u' input/X : 0', which has shape ' (? , 32, 32, 3)"

python - 运行时错误 : Attempted to use a closed Session in tflearn

python - 余弦相似度的 tflearn 自定义损失函数