仅对两个类使用categorical

仅对两个类使用categorical

本文介绍了仅对两个类使用categorical_crossentropy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计算机视觉和深度学习文献通常说,对于二元(两类)问题,应使用binary_crossentropy;对于两类以上的问题,应使用categorical_crossentropy.现在我想知道:是否有理由不将后者用于两类问题?

Computer vision and deep learning literature usually say one should use binary_crossentropy for a binary (two-class) problem and categorical_crossentropy for more than two classes. Now I am wondering: is there any reason to not use the latter for a two-class problem as well?

推荐答案

  • categorical_crossentropy:
    • 每个样本仅接受一个正确的类别
    • 将仅"获取真实的神经元,并与该神经元进行交叉熵计算
      • categorical_crossentropy:
        • accepts only one correct class per sample
        • will take "only" the true neuron and make the crossentropy calculation with that neuron
          • 每个样本接受许多正确的类别
          • 将对所有神经元"进行交叉熵计算,考虑到每个神经元可以是0和1两类.

          两类问题可以建模为:

          • 2-神经元输出只有一个正确的类别:softmax + categorical_crossentropy
          • 1-neuron输出,一类为0,另一类为1:sigmoid + binary_crossentropy
          • 2-neuron output with only one correct class: softmax + categorical_crossentropy
          • 1-neuron output, one class is 0, the other is 1: sigmoid + binary_crossentropy

          说明

          请注意,在分类交叉熵(第一个方程式)中,对于真正的神经元而言,项y_true仅是1,从而使所有其他神经元等于零.

          Notice how in categorical crossentropy (the first equation), the term y_true is only 1 for the true neuron, making all other neurons equal to zero.

          可以将等式简化为:ln(y_pred[correct_label]).

          The equation can be reduced to simply: ln(y_pred[correct_label]).

          现在请注意二进制交叉熵(图片中的第二个方程)如何具有两个术语,一个用于将1视为正确的类别,另一个用于将0视为正确的类别.

          Now notice how binary crossentropy (the second equation in the picture) has two terms, one for considering 1 as the correct class, another for considering 0 as the correct class.

          这篇关于仅对两个类使用categorical_crossentropy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 09:32