def flatten_binary_scores(scores, labels, ignore=None):
    """
    Flattens predictions in the batch (binary case).
    Remove labels according to 'ignore'.
    """
    scores = paddle.reshape(scores, [-1])
    labels = paddle.reshape(labels, [-1])
    labels.stop_gradient = True
    if ignore is None:
        return scores, labels
    valid = labels != ignore
    valid_mask = paddle.reshape(valid, (-1, 1))
    indexs = paddle.nonzero(valid_mask)
    indexs.stop_gradient = True
    vscores = paddle.gather(scores, indexs[:, 0])
    vlabels = paddle.gather(labels, indexs[:, 0])
    return vscores, vlabels

    Flattens predictions in the batch (binary case).
    Remove labels according to 'ignore'.
    
paddleseg/models/losses/lovasz_loss.py