how can i change the face area to be cropped larger? #58

Open
opened 2026-01-29 21:40:15 +00:00 by claunia · 4 comments
Owner

Originally created by @nowfalsalahudeen on GitHub (Aug 27, 2021).

Originally created by @nowfalsalahudeen on GitHub (Aug 27, 2021).
Author
Owner

@shubhamcodez commented on GitHub (Aug 28, 2021):

There should be some cropping & scaling options for that or just crop before input.

@shubhamcodez commented on GitHub (Aug 28, 2021): There should be some cropping & scaling options for that or just crop before input.
Author
Owner

@xinntao commented on GitHub (Aug 29, 2021):

GFPGAN currently requires cropped and aligned face.
The cropping and aligning procedures are the same as FFHQ dataset.

I think if you want to use larger cropped face area, you also need to re-train the model~

@xinntao commented on GitHub (Aug 29, 2021): GFPGAN currently requires cropped and aligned face. The cropping and aligning procedures are the same as FFHQ dataset. I think if you want to use larger cropped face area, you also need to re-train the model~
Author
Owner

@Kazioo commented on GitHub (Oct 27, 2022):

Not sure if this is the best way to do it, but it works.
You can make the cropped area bigger, by editing lines 81 nad 82 in in utils.py.
It will improve hair and ears (if they are cut in 1.0 crop) but it will degrade the face identity.
So you may need to overlay a properly upscaled face on top of it later in editing software.

For example:

face_size=512,            crop_ratio=(1, 1)                # original, the only correct one!
face_size=420,            crop_ratio=(1.22, 1.22),
face_size=394,            crop_ratio=(1.3, 1.3),          
face_size=320,            crop_ratio=(1.6, 1.6),         # good for hair and ears, but will mess the face up really badly
@Kazioo commented on GitHub (Oct 27, 2022): Not sure if this is the best way to do it, but it works. You can make the cropped area bigger, by editing lines 81 nad 82 in in utils.py. It will improve hair and ears (if they are cut in 1.0 crop) but it will degrade the face identity. So you may need to overlay a properly upscaled face on top of it later in editing software. For example: ``` face_size=512, crop_ratio=(1, 1) # original, the only correct one! face_size=420, crop_ratio=(1.22, 1.22), face_size=394, crop_ratio=(1.3, 1.3), face_size=320, crop_ratio=(1.6, 1.6), # good for hair and ears, but will mess the face up really badly ```
Author
Owner

@Svytta commented on GitHub (Oct 26, 2024):

face_size=512,            crop_ratio=(1, 1)                # original, the only correct one!
face_size=420,            crop_ratio=(1.22, 1.22),
face_size=394,            crop_ratio=(1.3, 1.3),          
face_size=320,            crop_ratio=(1.6, 1.6),         # good for hair and ears, but will mess the face up really badly

ths u so much, this helped me a lot, i wrote a code with ur guidance that automatice this, u just need to add the new files to ur directory, ie:

D:\AI\GFPGAN\gfpgan u add the new file utils_modificado.py
D:\AI\GFPGAN u add the new file inference_gfpgan_hair.py

when u execute: python inference_gfpgan_hair.py -i inputs/upload -o Result_GFPGAN -v 1.4 -s 1 --bg_upsampler realesrgan --bg_tile 800

GFPGAN will create 2 different files:
Result_GFPGAN
> Original
> Modified

Im not really good coding un python but ultimatly it works, hopefully someday I will fix this properly

files.zip

@Svytta commented on GitHub (Oct 26, 2024): > ``` > face_size=512, crop_ratio=(1, 1) # original, the only correct one! > face_size=420, crop_ratio=(1.22, 1.22), > face_size=394, crop_ratio=(1.3, 1.3), > face_size=320, crop_ratio=(1.6, 1.6), # good for hair and ears, but will mess the face up really badly > ``` ths u so much, this helped me a lot, i wrote a code with ur guidance that automatice this, u just need to add the new files to ur directory, ie: D:\AI\GFPGAN\gfpgan u add the new file utils_modificado.py D:\AI\GFPGAN u add the new file inference_gfpgan_hair.py when u execute: python inference_gfpgan_hair.py -i inputs/upload -o Result_GFPGAN -v 1.4 -s 1 --bg_upsampler realesrgan --bg_tile 800 GFPGAN will create 2 different files: Result_GFPGAN > Original > Modified Im not really good coding un python but ultimatly it works, hopefully someday I will fix this properly [files.zip](https://github.com/user-attachments/files/17529660/files.zip)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#58