Skip to content

[BUG]: Memory Leak on inference #118

@mbegue-cr

Description

@mbegue-cr

Before You Report a Bug, Please Confirm You Have Done The Following...

  • I have updated to the latest version of the packages.
  • I have searched for both existing issues and closed issues and found none that matched my issue.

RetinaFace's Version

0.0.17

Python Version

3.11.11

Operating System

No response

Dependencies

tensorflow==2.16.2

Reproducible example

from retinaface import RetinaFace
# 423MB of Real Memory used after this line

url = "https://media.cnn.com/api/v1/images/stellar/prod/210610161942-05-g7-through-history.jpg?q=w_1160,c_fill/f_webp"

faces = RetinaFace.detect_faces(url)
# 1.45 GB Real Memory used after this line
faces = RetinaFace.detect_faces(url)
faces = RetinaFace.detect_faces(url)
faces = RetinaFace.detect_faces(url)
# 1.59GB Real Memory use after this call.
# Real Memory size for this python process increases after each call

Relevant Log Output

No response

Expected Result

I expect that any intermediate variables and tensors be cleared from memory after each detect_faces call. Furthermore, I inspected the retinaface model and we clearly have trainable=False, so I don't think we're accumulating gradients.
This is not desirable at all especially if I want to run hundreds of face detection calls in a single python session.

What happened instead?

After importing retinaface there is 423MB of Real Memory used for that python process.
After the first detect_faces call, 1.45GB Real memory is used for that process.
After several detect_faces calls, the memory steadily increases monotonically.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions