8000 about the dataset · Issue #13 · mapooon/PetFace · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

about the dataset #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
garychan22 opened this issue Mar 21, 2025 · 3 comments
Open

about the dataset #13

garychan22 opened this issue Mar 21, 2025 · 3 comments

Comments

@garychan22
Copy link

does the dataset only include the cropped faces? will the original image be provided? thanks for the great work!

@mapooon
Copy link
Owner
mapooon commented Apr 18, 2025

Thank you for your interest in our work.
Currently, we do not plan to release the original images.

@jveitchmichaelis
Copy link
jveitchmichaelis commented Apr 30, 2025

@mapooon What crop parameters were used in the dataset generation? I would like to try the model on novel data, but I assume I need to pre-process all my images with the alignment that the model expects (here, "dog" for example). I'd be happy to submit a PR with my re-ID script so others can benefit.

I've been able to run most of the pre-processing steps with my own images (AnyFace keypoint generation), but it's not clear from the paper or repository how you choose the crop aside from the output being 224x224 after the keypoint alignment step. The bounding box from AnyFace is not square in most cases, and many of the photos in the dataset are more zoomed out than if the box was used directly.

I've been able to roughly replicate using a crop of size: min(width//2, height//2, 2*interocular_distance) and modifying the alignment function. I guess the input image needs to be vaguely the same proportions as the target for the transform to work reliably, so I pick something that's a bit bigger than the size of the animal and constrain to the image if it's too big.

def crop(image_path, box, keypoints):
    out = []
    image = Image.open(image_path)

    if keypoints.shape[-1] == 2:
        keypoints = np.expand_dims(keypoints, 0)
    
    for (b, k) in zip(box, keypoints):
        x, y, w, h = b
        kp_mean = np.mean(k, axis=0)
        x_c, y_c = float(kp_mean[0]), float(kp_mean[1])

        # Let crop size be 2x eye distance (or half-image-size, whichever is smaller)
        eye_width = abs(k[1][0] - k[0][0])
        crop_radius = int(min(image.width // 2, image.height // 2, 2 * eye_width))

        left = int(x_c - crop_radius)
        upper = int(y_c - crop_radius)
        right = int(x_c + crop_radius)
        lower = int(y_c + crop_radius)
        
        cropped = image.crop((left, upper, right, lower))

        # Shift keypoints to cropped coordinate frame
        k_cropped = k - np.array([left, upper])

        out.append((cropped, k_cropped))

    return out

def align(img, lmk, src, size):
    M, _ = cv2.estimateAffinePartial2D(src, lmk, method=cv2.LMEDS)
    img_aligned = cv2.warpAffine(img, M[:2], (size, size), flags=cv2.INTER_AREA)
    
    return img_aligned

An example of how this is used:

# I have a custom class to load AnyFace as an ONNX model
anyface = KeypointExtractor(onnx_path)
keypoints, box = anyface.predict(test_image_path, visualize=False)

# Crop image + shifted keypoints
cropped, kp = crop(test_image_path, box, keypoints)[0]

# Alignment
img = np.array(cropped)
h,w=img.shape[:2]
src = kp

target = "dog.npy"
tgt = np.load(target).reshape((5,2))

img_aligned = Image.fromarray(align(img,tgt,src,224))

I wasn't able to get a projective warp to work as in the face_align.py script. The resulting crop is not centered on the face, but an affine transform above works. For example:

Image

AnyFace keypoints + crop as above:

Image

Approximate warp to target face keypoints:

Image

Compared to a random example in the dataset:

Image
Image

@mapooon
Copy link
Owner
mapooon commented May 1, 2025

@jveitchmichaelis Thank you for reporting your issue.
But could you open a new issue thread so that those who have similar issues can easily find? (It's ok to just copy with a proper title)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0