def faceid_SCRFD(target_image_dir: str) -> Callable:
    """The closure returns the Face ID reward function given a user ID. It uses SCRFD to detect the face and then
    use CurricularFace to extract the face feature. SCRFD requires the extra package mmcv-full.

    Args:
        target_image_dir (str): The directory of processed face image files (.jpg) given a user ID.
    """
    face_recognition = pipeline(Tasks.face_recognition, model="damo/cv_ir101_facerecognition_cfglint")
    target_image_files = Path(target_image_dir).glob("*.jpg")
    target_images = [Image.open(f).convert("RGB") for f in target_image_files]
    target_embs = [face_recognition(t)[OutputKeys.IMG_EMBEDDING][0] for t in target_images]  # (M, 512)
    target_mean_emb = np.mean(np.vstack(target_embs), axis=0)  # (512,)

    # Redundant parameters are for backward compatibility.
    def __call__(src_images: Union[List[Image.Image], np.array, torch.Tensor], prompts: List[str]) -> Tuple[np.array, dict]:
        src_images = _convert_images(src_images)
        src_embs = []  # (N, 512)
        for s in src_images:
            try:
                emb = face_recognition(s)[OutputKeys.IMG_EMBEDDING][0]
            except Exception as e:  # TypeError
                print("Catch Exception in the reward function faceid_retina: {}".format(e))
                emb = np.array([0] * 512)
                print("No face is detected or the size of the detected face size is not enough. Set the embedding to zero.")
            finally:
                src_embs.append(emb)
        faceid_list = np.dot(src_embs, target_mean_emb)

        return faceid_list

    return __call__
The closure returns the Face ID reward function given a user ID. It uses SCRFD to detect the face and then
    use CurricularFace to extract the face feature. SCRFD requires the extra package mmcv-full.

    Args:
        target_image_dir (str): The directory of processed face image files (.jpg) given a user ID.
    
scripts/train_kohya/ddpo_pytorch/rewards.py