[英]Multi-class multi-label classification in Keras
I am trying to train a multi-task multi-label classifier using Keras.我正在尝试使用 Keras 训练多任务多标签分类器。 The output layer is a fork of two outputs.
输出层是两个输出的分支。 The task of each output layer is to predict the categories of its task.
每个输出层的任务是预测其任务的类别。 The y vectors are OneHot encoded.
y 向量是 OneHot 编码的。
I am using a custom generator for my data that yields the y
arrays in a list to the fit_generator
function我正在为我的数据使用自定义生成器,该生成器将列表中的
y
数组生成到fit_generator
函数
I am using a categorigal_crossentropy
loss function at each layer我在每一层都使用了
categorigal_crossentropy
损失函数
fork1.compile(loss={'O1': 'categorical_crossentropy', 'O2': 'categorical_crossentropy'},
optimizer=optimizers.Adam(lr=0.001),
metrics=['accuracy'])
The problem: The loss doesn't decrease with this setup.问题:这种设置不会减少损失。 However, if I train each task separately, I have low loss and high accuracy.
但是,如果我单独训练每个任务,我的损失低,准确率高。 So what could be the problem ?
那么问题出在哪里呢?
To perform multilabel categorical classification (where each sample can have several classes), end your stack of layers with a Dense layer with a number of units equal to the number of classes and a sigmoid activation, and use binary_crossentropy as the loss.要执行多标签分类分类(其中每个样本可以有多个类),请使用 Dense 层结束您的层堆栈,该层的单位数等于类数和 sigmoid 激活,并使用 binary_crossentropy 作为损失。 Your targets should be k-hot encoded.
你的目标应该是 k-hot 编码的。
Regarding the multi-output model, training such a model requires the ability to specify different loss functions for different heads of the network requiring a different training procedure.关于多输出模型,训练这样的模型需要能够为需要不同训练过程的网络的不同头部指定不同的损失函数。
You should provide more info in order to give a clear indication of what you want to achieve.您应该提供更多信息,以便清楚地表明您想要实现的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.