function check_segment_validity(
    mask_labels,
    mask_probs,
    k,
    mask_threshold = 0.5,
    overlap_mask_area_threshold = 0.8
) {
    // mask_k is a 1D array of indices, indicating where the mask is equal to k
    const mask_k = [];
    let mask_k_area = 0;
    let original_area = 0;

    const mask_probs_k_data = mask_probs[k].data;

    // Compute the area of all the stuff in query k
    for (let i = 0; i < mask_labels.length; ++i) {
        if (mask_labels[i] === k) {
            mask_k.push(i);
            ++mask_k_area;
        }

        if (mask_probs_k_data[i] >= mask_threshold) {
            ++original_area;
        }
    }
    let mask_exists = mask_k_area > 0 && original_area > 0;

    // Eliminate disconnected tiny segments
    if (mask_exists) {
        // Perform additional check
        let area_ratio = mask_k_area / original_area;
        mask_exists = area_ratio > overlap_mask_area_threshold;
    }

    return [mask_exists, mask_k]
}
Checks whether the segment is valid or not.
@param {Int32Array} mask_labels Labels for each pixel in the mask.
@param {Tensor[]} mask_probs Probabilities for each pixel in the masks.
@param {number} k The class id of the segment.
@param {number} mask_threshold The mask threshold.
@param {number} overlap_mask_area_threshold The overlap mask area threshold.
@returns {[boolean, number[]]} Whether the segment is valid or not, and the indices of the valid labels.
@private