lllyasviel/Fooocus · error · FaceWarpException

facial_pts and reference_pts must have the same shape

Error message

facial_pts and reference_pts must have the same shape

What it means

After transposing both inputs to (K,2), warp_and_crop_face requires facial_pts and reference_pts to have identical shapes — a transform needs a 1:1 correspondence between source and target points. A landmark-count mismatch raises FaceWarpException.

Source

Thrown at extras/facexlib/detection/align_trans.py:208

    ref_pts = np.float32(reference_pts)
    ref_pts_shp = ref_pts.shape
    if max(ref_pts_shp) < 3 or min(ref_pts_shp) != 2:
        raise FaceWarpException('reference_pts.shape must be (K,2) or (2,K) and K>2')

    if ref_pts_shp[0] == 2:
        ref_pts = ref_pts.T

    src_pts = np.float32(facial_pts)
    src_pts_shp = src_pts.shape
    if max(src_pts_shp) < 3 or min(src_pts_shp) != 2:
        raise FaceWarpException('facial_pts.shape must be (K,2) or (2,K) and K>2')

    if src_pts_shp[0] == 2:
        src_pts = src_pts.T

    if src_pts.shape != ref_pts.shape:
        raise FaceWarpException('facial_pts and reference_pts must have the same shape')

    if align_type == 'cv2_affine':
        tfm = cv2.getAffineTransform(src_pts[0:3], ref_pts[0:3])
    elif align_type == 'affine':
        tfm = get_affine_transform_matrix(src_pts, ref_pts)
    else:
        tfm = get_similarity_transform_for_cv2(src_pts, ref_pts)

    face_img = cv2.warpAffine(src_img, tfm, (crop_size[0], crop_size[1]))

    return face_img

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Use reference points with the same K as the detector output (RetinaFace 5-point -> get_reference_facial_points output)
  2. Convert landmark formats explicitly (e.g. 68->5 point subset) before alignment
  3. Assert src_pts.shape == ref_pts.shape before calling warp_and_crop_face

Example fix

// before
img5 = warp_and_crop_face(img, retinaface_5pts, ref_68pts)

// after
ref5 = get_reference_facial_points((512,512), 0.25, (0,0), True)
img5 = warp_and_crop_face(img, retinaface_5pts, ref5)
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np
src = np.asarray(facial_pts, dtype=np.float32).reshape(-1, 2)
ref = np.asarray(reference_pts, dtype=np.float32).reshape(-1, 2)
assert src.shape == ref.shape, f'point count mismatch: {src.shape} vs {ref.shape}'

Try / catch

from extras.facexlib.detection.align_trans import FaceWarpException
try:
    img = warp_and_crop_face(img, src, ref)
except FaceWarpException:
    skip_frame_and_log(img_id)  # fallback for bad detection

Prevention

When it happens

Trigger: Combining a 5-point detector output (e.g. RetinaFace) with a reference layout built for a different number of points (68-point dlib layout, 98-point layout), or K mismatches after reshaping.

Common situations: Swapping landmark detectors without regenerating the reference points; mixing 5-point and 68-point pipelines; reference computed for a different crop size convention that changed K.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/b93a729feba92d25. Report an issue: GitHub.