def create_annotation(args, imname, pred_mask, class_id, score, classes, is_valid = True):
    """Creates annotation object following the COCO API ground truth format"""

    ann = dict()
    ann['image_id'] = imname
    ann['category_id'] = class_id
    ann['category_name'] = classes[class_id]

    # if the mask is all 0s after thresholding we don't use it either
    ann['segmentation'] = pred_mask
    ann['score'] = score
    if is_valid:
        return ann
    else:
        return None