danielgatis / rembg

Rembg is a tool to remove images background
MIT License
15.39k stars 1.75k forks source link

[FEATURE] Use downloaded model on Cloud Function #638

Open BenjaminRbt opened 1 month ago

BenjaminRbt commented 1 month ago

First, thanks a lot for this amazing tool!

Use case

Following the issue @maumarteau raised, I would like to know if it is planned (or not) to be able to use a given model locally.

In my use case, I use a Google Cloud Function which is hosting a Python script to use this background removal feature. However, when there is no Cloud Function available, it has to start and when it is run, it downloads the model:

Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net.onnx' to file '/tmp/.u2net/u2net.onnx'.

With a progress bar to let us know when it is ready to be used (related sourcecode: sam.py:275). Once the model is downloaded, the background removal is done and I am able to retrieve a processed image (yay!).

Problem

Because of this Cloud Function cold start, it requires to wait the model to be download, which is quite long in some use case. If the Cloud Function is already available, it is quite fast, but the policy to keep awake the Cloud Function does not allow me to keep this Cloud Function for ever.

Solution

Suggested solution:

Thanks a lot!