Skip to content
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

AttributeError: 'list' object has no attribute 'kps' #2723

Open
DeepthiSudharsan opened this issue Jan 27, 2025 · 1 comment
Open

AttributeError: 'list' object has no attribute 'kps' #2723

DeepthiSudharsan opened this issue Jan 27, 2025 · 1 comment

Comments

@DeepthiSudharsan
Copy link

DeepthiSudharsan commented Jan 27, 2025

Below is the code I was trying to run and the error I got:

import numpy as np
import os
import glob
import cv2
from PIL import Image

import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image

app = FaceAnalysis(name="buffalo_l")
app.prepare(ctx_id=0, det_size=(640,640))
img = cv2.imread("friends.png")
rob = cv2.imread("rob.png")
faces = app.get(img)
rob_faces = app.get(rob)
swapper = insightface.model_zoo.get_model('../inswapper_128.onnx',download=False,download_zip=False)
res = img.copy()
for face in faces:
    res = swapper.get(res,faces,rob_faces,paste_back=True)

Facing the below issue, while running the above code:

Error:

aimg, M = face_align.norm_crop2(img, target_face.kps, self.input_size[0])
AttributeError: 'list' object has no attribute 'kps'

Any help on this regard would be greatly appreciated. Thanks!

@tejaprojects
Copy link

tejaprojects commented Feb 14, 2025

faces = app.get(img)
returns a list of faces, with each face having its own 'kps'
You need to access individual face's 'kps' via faces[i].kps
Even if there is only one face detected, app.get(img) returns a list of one element.

faces = app.get(img)
If there's only one face detected, then use faces[0] instead of faces
i.e. faces.kps raises error, but not faces[0].kps

In your case, both faces and rob_faces are lists.
You can paste rob_faces[0] (say) onto faces[0] or any other individual faces[i] or all of them (in your case) like:
swapper.get(res, face, rob_faces[0], paste_back = True)

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

2 participants