def eval_jpg_with_faceid(pivot_dir, test_img_dir, top_merge=10):
    """
    Evaluate images using local face identification.

    Args:
        pivot_dir (str): Directory containing reference real human images.
        test_img_dir (str): Directory pointing to generated validation images for training.
            Image names follow the format xxxx_{step}_{indx}.jpg.
        top_merge (int, optional): Number of top weights to select for merging. Defaults to 10.

    Returns:
        list: List of evaluated results.

    Function:
        - Obtain faceid features locally.
        - Calculate the average feature of real human images.
        - Select top_merge weights for merging based on generated validation images.
    """
    try:
        # embedding
        face_recognition = modelscope_pipeline("face_recognition", model="bubbliiiing/cv_retinafce_recognition", model_revision="v1.0.3")
    except Exception as e:
        print(f"Load face recognition model failed. {e}")
        return [], [], []

    # get ID list
    face_image_list = (
        glob(os.path.join(pivot_dir, "*.jpg"))
        + glob(os.path.join(pivot_dir, "*.JPG"))
        + glob(os.path.join(pivot_dir, "*.png"))
        + glob(os.path.join(pivot_dir, "*.PNG"))
    )

    #  vstack all embedding
    embedding_list = []
    for img in face_image_list:
        try:
            image = Image.open(img)
            embedding = face_recognition(dict(user=image))[OutputKeys.IMG_EMBEDDING]
            if embedding is not None:
                embedding_list.append(embedding)
        except Exception as e:
            print("error at:", str(e))

    if len(embedding_list) == 0:
        print("Can't detect faces in processed images, return empty list")
        return [], [], []

    # exception cause by embedding = None
    try:
        embedding_array = np.vstack(embedding_list)
    except Exception as e:
        print(f"vstack embedding failed, caused by {str(e)}")
        return [], [], []

    #  mean, get pivot
    pivot_feature = np.mean(embedding_array, axis=0)
    pivot_feature = np.reshape(pivot_feature, [512, 1])

    # sort with cosine distance
    embedding_list = [[np.dot(emb, pivot_feature)[0][0], emb] for emb in embedding_list]
    embedding_list = sorted(embedding_list, key=lambda a: -a[0])

    top10_embedding = [emb[1] for emb in embedding_list]
    top10_embedding_array = np.vstack(top10_embedding)
    # [512, n]
    top10_embedding_array = np.swapaxes(top10_embedding_array, 0, 1)

    # sort all validation image
    result_list = []
    if not test_img_dir.endswith(".jpg"):
        img_list = (
            glob(os.path.join(test_img_dir, "*.jpg"))
            + glob(os.path.join(test_img_dir, "*.JPG"))
            + glob(os.path.join(test_img_dir, "*.png"))
            + glob(os.path.join(test_img_dir, "*.PNG"))
        )
        for img in img_list:
            try:
                # a average above all
                image = Image.open(img)
                embedding = face_recognition(dict(user=image))[OutputKeys.IMG_EMBEDDING]

                res = np.mean(np.dot(embedding, top10_embedding_array))
                result_list.append([res, img])
                result_list = sorted(result_list, key=lambda a: -a[0])
            except Exception as e:
                print("error at:", str(e))

    # pick most similar using faceid
    t_result_list = [i[1] for i in result_list][:top_merge]
    tlist = [i[1].split("_")[-2] for i in result_list][:top_merge]
    scores = [i[0] for i in result_list][:top_merge]
    return t_result_list, tlist, scores

    Evaluate images using local face identification.

    Args:
        pivot_dir (str): Directory containing reference real human images.
        test_img_dir (str): Directory pointing to generated validation images for training.
            Image names follow the format xxxx_{step}_{indx}.jpg.
        top_merge (int, optional): Number of top weights to select for merging. Defaults to 10.

    Returns:
        list: List of evaluated results.

    Function:
        - Obtain faceid features locally.
        - Calculate the average feature of real human images.
        - Select top_merge weights for merging based on generated validation images.
    
scripts/train_kohya/train_lora.py