Zejun-Yang / AniPortrait

AniPortrait: Audio-Driven Synthesis of Photorealistic Portrait Animation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gradio demo crops/zooms in on face

mitchellfox opened this issue · comments

commented

Regarding the latest commit which includes a gradio demo, when using vid2vid I noticed that with the gradio demo it is cropping/zooming in on the face in the output, it also modifies the source photo to be cropped/zoomed in on the face. Whereas, in huggingface demo the output retained the body from the source image and scaled instead of cropping.

Is there a parameter or config where this can be switched back to scaling instead of cropping?

Thanks for your amazing work!

It is something to do with this

https://huggingface.co/spaces/ZJYang/AniPortrait_official/blob/main/src/utils/crop_face_single.py

in this main repo it is https://github.com/Zejun-Yang/AniPortrait/blob/main/src/utils/util.py#L131 set at 1.5

def crop_face(img, lmk_extractor, expand=1.5):
result = lmk_extractor(img) # cv2 BGR

if result is None:
    return None

It doesnt crop it if the ref image is close to the dimensions of the ref video

eg1.mp4
512x512_0832.mp4

sdgirlcropped512

but will seemingly go too far when it isnt

512x512_0837.mp4

sdgirl512

when I changed expand in crop_single to 1.1 it resulted in this, even more zoomed in, so it is do with cropfacesingle in the huggingface app. I guess somewhere in the main repo there is an equivalent

512x512_0923.mp4

Expand 3

512x512_0937.mp4

Our purpose in cropping the image is to ensure that the face occupies a larger proportion in the image. You can delete this line of code to disable cropping.

ref_image_np = crop_face(ref_image_np, lmk_extractor)