CE loss in fine-tuning does not work for binary classification

Hi, I am trying to fine-tune a Yolox with a single class and want to use a (binary-)cross-entropy loss for the objectness score and classification logit outputs. I’ve tried setting the ce loss type in the post_quantization_optimization(finetune, ...) instruction, but when I do, I get a warning that I should use a binary_cross_entropy loss instead for outputs of shapes such as 1x80x80x1. However, there is no such option available ( I am using DFC v 3.28.0) and when using ce the distillation loss of these layers is just 0. Am I doing something wrong?

Hey @stwerner ,

The Hailo DFC currently doesn’t support binary_cross_entropy as a loss function option in post_quantization_optimization(finetune, ...). The only supported loss types are:

{ce, l2, l2rel, cosine}

Where ce means categorical cross-entropy, which works for multi-class classification but not for binary classification with logits per anchor (as in YOLOX).

If you use loss_types=['ce'] for binary outputs, you may get a zero distillation loss due to:

  • Incompatibility between softmax vs. sigmoid interpretation
  • Mismatched label formatting
  • Missing activation before logits

Recommended Solutions

Since binary_cross_entropy isn’t supported:

  1. Restructure your output to work with ce loss (convert to multi-class with 2 classes)

  2. Use l2 or l2rel loss as an alternative:

post_quantization_optimization(
    finetune,
    loss_types=['l2', 'l2', 'l2'],
    loss_layer_names=['obj_head', 'cls_head', 'bbox_head'],
    policy='enabled',
    dataset_size=2048,
    learning_rate=0.0002,
    epochs=8
)

This approach is valid when classification loss doesn’t work due to architecture-specific shapes.

Hi @omria , thanks for the response. Would be great to also have an option for binary_cross_entropy ! :slight_smile:

1 Like

Thanks for your suggestion. I’ll share this with our R&D team so they can determine the priority level.
Appreciate your input!