def safe_get_box_mask_keypoints(image, retinaface_result, crop_ratio, face_seg, mask_type):
    """
    Inputs:
        image                   Input image
        retinaface_result       The detection results of retinaface
        crop_ratio              The proportion of facial clipping and expansion
        face_seg                Facial segmentation model
        mask_type               The type of facial segmentation methods, one is loop and the other is skin, and the result of facial segmentation is the skin or frame of the face

    Outputs:
        retinaface_box          After box amplification, the box relative to the original image
        retinaface_keypoints    Points relative to the original image
        retinaface_mask_pil     Segmentation Results
    """
    h, w, c = np.shape(image)
    if len(retinaface_result["boxes"]) != 0:
        retinaface_boxs = []
        retinaface_keypoints = []
        retinaface_mask_pils = []
        for index in range(len(retinaface_result["boxes"])):
            # Obtain the box of reinface and expand it
            retinaface_box = np.array(retinaface_result["boxes"][index])
            face_width = retinaface_box[2] - retinaface_box[0]
            face_height = retinaface_box[3] - retinaface_box[1]
            retinaface_box[0] = np.clip(np.array(retinaface_box[0], np.int32) - face_width * (crop_ratio - 1) / 2, 0, w - 1)
            retinaface_box[1] = np.clip(np.array(retinaface_box[1], np.int32) - face_height * (crop_ratio - 1) / 2, 0, h - 1)
            retinaface_box[2] = np.clip(np.array(retinaface_box[2], np.int32) + face_width * (crop_ratio - 1) / 2, 0, w - 1)
            retinaface_box[3] = np.clip(np.array(retinaface_box[3], np.int32) + face_height * (crop_ratio - 1) / 2, 0, h - 1)
            retinaface_box = np.array(retinaface_box, np.int32)
            retinaface_boxs.append(retinaface_box)

            # Detect key points
            retinaface_keypoint = np.reshape(retinaface_result["keypoints"][index], [5, 2])
            retinaface_keypoint = np.array(retinaface_keypoint, np.float32)
            retinaface_keypoints.append(retinaface_keypoint)

            # mask part
            retinaface_crop = image.crop(np.int32(retinaface_box))
            retinaface_mask = np.zeros_like(np.array(image, np.uint8))
            if mask_type == "skin":
                retinaface_sub_mask = face_seg(retinaface_crop)
                retinaface_mask[retinaface_box[1] : retinaface_box[3], retinaface_box[0] : retinaface_box[2]] = np.expand_dims(
                    retinaface_sub_mask, -1
                )
            else:
                retinaface_mask[retinaface_box[1] : retinaface_box[3], retinaface_box[0] : retinaface_box[2]] = 255
            retinaface_mask_pil = Image.fromarray(np.uint8(retinaface_mask))
            retinaface_mask_pils.append(retinaface_mask_pil)

        retinaface_boxs = np.array(retinaface_boxs)
        argindex = np.argsort(retinaface_boxs[:, 0])
        retinaface_boxs = [retinaface_boxs[index] for index in argindex]
        retinaface_keypoints = [retinaface_keypoints[index] for index in argindex]
        retinaface_mask_pils = [retinaface_mask_pils[index] for index in argindex]
        return retinaface_boxs, retinaface_keypoints, retinaface_mask_pils

    else:
        retinaface_box = np.array([])
        retinaface_keypoints = np.array([])
        retinaface_mask = np.zeros_like(np.array(image, np.uint8))
        retinaface_mask_pil = Image.fromarray(np.uint8(retinaface_mask))

        return retinaface_box, retinaface_keypoints, retinaface_mask_pil

    Inputs:
        image                   Input image
        retinaface_result       The detection results of retinaface
        crop_ratio              The proportion of facial clipping and expansion
        face_seg                Facial segmentation model
        mask_type               The type of facial segmentation methods, one is loop and the other is skin, and the result of facial segmentation is the skin or frame of the face

    Outputs:
        retinaface_box          After box amplification, the box relative to the original image
        retinaface_keypoints    Points relative to the original image
        retinaface_mask_pil     Segmentation Results
    
scripts/easyphoto_utils/face_process_utils.py