Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Alignment with Cuda fails #36

Closed
Eleganze opened this issue Apr 5, 2018 · 1 comment
Closed

Alignment with Cuda fails #36

Eleganze opened this issue Apr 5, 2018 · 1 comment

Comments

@Eleganze
Copy link

Eleganze commented Apr 5, 2018

Any obvious reason why alignment with Cuda enabled fails on larger resolution images? The model itself gives incredible results, so its so frustrating that the alignment tool doesnt work with GPU enabled.

I tried using the updated alignment tool from the deepfake/faceswap repo but I guess the .json output is different.

Maybe it could be rewritten to fit the format dfaker needs? Alignment on 56 core CPU (Dual xenon) takes forever compared to GPU

@dfacct
Copy link

dfacct commented Apr 7, 2018

If you comment line 22 and uncomment lines 79-80 of align_images_masked.py, you will find it speeds up alignment dramatically and works with high resolution images. The problem is that the aligned face is sourced from an 800px copy of the original, which looks pretty awful if the face is far from the camera.

I've never written Python before, but I made some changes that perform get_landmarks on an 800px copy then upscales the landmarks so the aligned face is sourced from the original and maintains sharpness. I tested it with 6000x4000px images and it worked fine with my 1060. I also perform 90º rotations until a face is found. I'm not sure if this is worth adding to the main repository, but check my fork if you want to try it out, it's much faster if using GPU and still reasonably accurate:
https://github.com/dfacct/df/blob/master/align_images_masked.py

I added 4 optional arguments:
--fast-mode (creates an 800px copy before performing get_landmarks, then upscales landmarks so the aligned image is sourced from the orginal)
--fast-mode-size default 800 (in pixels, smaller = faster/less accurate)
--try-rotated (rotates the image by 90º, 180º, and 270º, stopping when a face is found. Will increase overall processing time but will likely find more faces)
--use-gpu (disables monkey_patch_face_detector and utilizes GPU)

Try this command and tinker with the fast-mode-size argument to find the best speed/accuracy balance.
python align_images_masked.py c:\source-images --fast-mode --fast-mode-size 800 --try-rotated --use-gpu

@dfaker dfaker closed this as completed Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants