def flatten_binary_logits(logits, labels, ignore_index=None):
    """Flattens predictions in the batch (binary case) Remove labels equal to
    'ignore_index'."""
    logits = logits.view(-1)
    labels = labels.view(-1)
    if ignore_index is None:
        return logits, labels
    valid = (labels != ignore_index)
    vlogits = logits[valid]
    vlabels = labels[valid]
    return vlogits, vlabels
Flattens predictions in the batch (binary case) Remove labels equal to
    'ignore_index'.
ControlNet-v1-1-nightly/annotator/uniformer/mmseg/models/losses/lovasz_loss.py