Keras多个二进制输出 [英] Keras multiple binary outputs

查看:129
本文介绍了Keras多个二进制输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我更好地理解这个问题.

Can someone help me understand a bit better this problem.

我必须训练一个神经网络,该神经网络应该输出200个相互独立的类别,这些类别中的每一个都是从0到1的百分比.对我来说,这似乎是一个binary_crossentropy问题,但是我在互联网上看到的每个示例都使用binary_crossentropy具有单个输出.因为我的输出应该是200,所以如果我应用binary_crossentropy,那是正确的吗?

I must train a neural network which should output 200 mutually independent categories, each of these categories is a percentage ranging from 0 to 1. To me this seems like a binary_crossentropy problem but every example i see on the internet uses binary_crossentropy with a single output. Since my output should be 200, if i apply binary_crossentropy, would that be correct?

这就是我的想法,这是正确的方法还是我应该更改它?

This is what i have in mind, is that a correct approach or should i change it?

inputs = Input(shape=(input_shape,))
hidden = Dense(2048, activation='relu')(inputs)
hidden = Dense(2048, activation='relu')(hidden)
output = Dense(200, name='output_cat', activation='sigmoid')(hidden)
model = Model(inputs=inputs, outputs=[output])
loss_map = {'output_cat': 'binary_crossentropy'}
model.compile(loss=loss_map, optimizer="sgd", metrics=['mae', 'accuracy'])

推荐答案

对于多个类别分类问题,应使用categorical_crossentropy而不是binary_crossentropy.这样,当您的模型对输入进行分类时,它将给出所有200个类别之间的概率分散.接收到最高概率的类别将是该特定输入的输出.

For multiple category classification problems, you should use categorical_crossentropy rather than binary_crossentropy. With this, when your model classifies an input, it is going give a dispersion of probabilities between all 200 categories. The category that receives the highest probability will be the output for that particular input.

当您致电model.predict()时,您会看到此信息.例如,如果仅在一个输入上调用此函数并打印结果,则将看到200个百分比的结果(总计为1).希望这200个百分比中的一个比其他百分比高得多,这表明该模型认为对于特定的输入来说,这是正确的输出(类别)的可能性很大.

You can see this when you call model.predict(). If you were to call this function only on one input, for example, and print the results, you will see a result of 200 percentages (in total summing to 1). The hope is that one of those 200 percentages would be vastly higher than the others, which signals that the model thinks that there is a strong probability that this is the correct output (category) for this particular input.

此视频可能有助于阐明预测内容.打印预测开始于3:17左右,但是要获得完整的背景信息,您需要从头开始.

This video may help clarify the prediction piece. Printing out the predictions starts around 3:17, but to get the full context, you'll need to start from the beginning.

这篇关于Keras多个二进制输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆