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

Reduce memory leaked by using model() instead of model.predict() #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Commits on Feb 23, 2023

  1. Reduce memory leaked by using model() instead of model.predict()

    In a long-running process invoking `nsfw_detector.predict.classify_nd()` often, we observed memory leakage consistent with what [keras-team/keras#13118][13118] suggests can be avoided through predicting via `model()` instead of `model.predict()` when combined with some memory management following invocation:
    
    ```python
    import gc
    import tensorflow.keras as keras
    from nsfw_detector import predict
    # …
    predict.classify_nd(model, image)
    gc.collect()
    keras.backend.clear_session()
    ```
    
    An alternative suggestion was to use `model.predict_on_batch(x)` instead of `model()` but we didn't try that because using `model()` solved our memory leak problem adequately.
    
    If this fix limits a use case, an alternative implementation for this fix may be to allow the caller to specify what of the three methods to use or to pass a callable that will receive the `nd_images` parameter.
    
    [13118]: keras-team/keras#13118
    colindean committed Feb 23, 2023
    Configuration menu
    Copy the full SHA
    9bd37c4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7172fc3 View commit details
    Browse the repository at this point in the history

Commits on Aug 3, 2023

  1. Configuration menu
    Copy the full SHA
    97c4877 View commit details
    Browse the repository at this point in the history