Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generator function for face_enhancer to save RAM #303

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

johnephillips
Copy link
Contributor

@johnephillips johnephillips commented May 17, 2023

This PR implements a generator function version of face_enhancer to save RAM by allowing for enhancing and saving images one at a time instead of storing them all in memory. This works because imageio.mimsave can work with any iterable as long as the iterable has a __len__ method. The original enhancer function works as before for backwards compatibility with the other places it is used in the codebase. Ideally other parts of the codebase would be improved with generator functions as well, since the amount of RAM saved means that SadTalker will be able to work with longer videos and run much faster; this PR is just a first step.

Some background on why this was implemented:
The linux kernel was terminating the process when running the demo notebook on a 2.5min audio file with a 800x1199px image. I found that this was because >25GB of RAM were being allocated during the face_enhancer function call because of all of the images being stored in one list (unencoded videos are huge). By using the generator instead, less than 0.5GB of RAM were needed for face_enhancer and the notebook finished successfully.

@johndpope
Copy link
Contributor

25GB of RAM -> 0.5 Gb - take a bow. 👏

@vinthony
Copy link
Collaborator

vinthony commented Jun 5, 2023

very cool! I will verify this PR, thanks for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants