MarekKowalski / FaceSwap

3D face swapping implemented in Python
MIT License
728 stars 207 forks source link

How can I Speed up the modle #8

Open seasonyang opened 6 years ago

seasonyang commented 6 years ago

The speed is very slow, and imges delay to the camera. How to optimize it to speed up it's speed?

MarekKowalski commented 6 years ago

Hi,

The current version is slow because the face alignment method (from the dlib library) requires face detection to run in every frame. I have a version which uses Deep Alignment Network, a method published in one of my other repos for face alignment. I plan to include that version in this repo, but I don't have time to work on it right now.

For now you can download this faster version from Dropbox here: https://www.dropbox.com/sh/yfq0hcu0we2hed0/AABXckFonehfgLfdzicjqqJYa?dl=0

Keep in mind that you need to install additional Python modules as detailed in the Deep Alignment Network repo. You will also need a gpu compatible with CUDA if you want it to work fast.

Let me know if that helps.

Marek

seasonyang commented 6 years ago

@MarekKowalski thank you for your help。 I have tried your idea,but when I run the new modle only using CPU,its speed is slowler than before.

MarekKowalski commented 6 years ago

Yeah, it defienietly has to run on GPU to be fast.

minhazur-piash commented 6 years ago

How can I run this program on GPU, please let me know.

MarekKowalski commented 6 years ago

Hi,

If you mean the program I linked on Dropbox then please take a look at the installation requirements in this repo: https://github.com/MarekKowalski/DeepAlignmentNetwork

Marek

minhazur-piash commented 6 years ago

Hi, Thanks for quick reply. I don't have gpu compatible with CUDA,. Can I use openCL instead, if yes please let me know what changes I have to make.

Minhaz

MarekKowalski commented 6 years ago

Hi,

No idea, look at the theano documentation and see there (theano is the library that uses the GPU).

Marek

minhazur-piash commented 6 years ago

Hi, Found out that utils.getFaceKeypoints(cameraImg, detector, predictor, prevShape2D) taking longer time and the reason behind dropping frames. Is there any workaround? Thanks. Minhaz.

MarekKowalski commented 6 years ago

Hi,

Are you using the version that I supplied above in dropbox or the version in the repo? If the one in Dropbox, I would suggest trying to enable gpu support. If you are using the other version you might want to try to perform face detection on downscaled images.

Marek

MarekKowalski commented 6 years ago

Hi,

The performance of the face alignment step (DAN) would definitely be lower than what you would get from a GPU equipped desktop computer. There would definitely be some room for performance improvements in other places, as there are some things that Python is very slow at. I am however not sure that it would be sufficiently fast.

One thing you might want to try to improve the DAN performance is to only use a single stage instead of two stages. You can specify that in the constructor parameters.

Best regards,

Marek