dfaker / df

Larger resolution face masked, weirdly warped, deepfake,
Mozilla Public License 2.0
479 stars 135 forks source link

Alignment with Cuda fails #36

Closed Eleganze closed 4 years ago

Eleganze commented 6 years ago

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 commented 6 years ago

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