'binary_crossentropy' & 'categorical_crossentropy' in keras
In model.compile(*)
of keras, I met binary_crossentropy
& categorical_crossentropy
. These two kinds of loss somehow made me confused.
Checking their underlying will reveal the mechanism of these two kinds of loss.
loss | refer to |
---|---|
binary_crossentropy | K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1) |
categorical_crossentropy | tf.nn.softmax_cross_entropy_with_logits(labels=target, logits=output) |
The problem is what is binary_crossentropy
and softmax_cross_entropy_with_logits
in TensorFlow
.
binary_crossentropy
(andtf.nn.sigmoid_cross_entropy_with_logits
under the hood) is for binary multi-label classification (labels are independent).
categorical_crossentropy
(andtf.nn.softmax_cross_entropy_with_logits
under the hood) is for multi-class classification (classes are exclusive).
ref:
python - Keras: binary_crossentropy & categorical_crossentropy confusion - Stack Overflow
https://stackoverflow.com/questions/47877083/keras-binary-crossentropy-categorical-crossentropy-confusion
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具