Giter Site home page Giter Site logo

rembg-lambda's People

Contributors

peterheb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

d-simon

rembg-lambda's Issues

[Suggestion] update documentation to add a link to `rembg-aws-lambda`

Hello, this is just a suggestion in regards to the following line in the Dockerfile:

RUN mkdir .u2net && curl -L https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net.onnx -o .u2net/u2net.onnx

The good news is that this download step can be circumvented, if such is desired -- keep in mind the following approach is pure Python and has no CLI support, however.

In case it is helpful for other Python developers, I've created an almost identical project for AWS environments, rembg-aws-lambda. It strips down some code, such as alpha matting, dependencies, CLI, and downloading the *.onnx files. The PyPI package contains u2net.onnx already, so installing it or setting env variables as NUMBA_CACHE_DIR and U2NET_HOME is not required anymore.

The project can be installed with:

pip install rembg-aws-lambda

Re. any cold start issues, they should be eliminated by this variant package. I have done extensive testing before this previously, and determined that the cold start issue(s) to be primarly due to:

  1. downloading the *.onnx files into the /tmp directory each time
  2. import statement for pymatting - as this package heavily utilizes decorators such as @njit, which uses numba to cache function optimizations. As this saves it into NUMBA_CACHE_DIR which should ideally point to /tmp for AWS Lambda Docker images (the only writable directory on the container), this takes a lot of time on each cold start as /tmp directory is clean (empty) at this point.

I have tested this out and determined that an AWS Lambda function (deployed w/ Docker, see a sample Dockerfile) using an X86_64 architecture and 1769 MB memory to be optimal. Remember to also set OMP_NUM_THREADS=2 in the environment, to take advantage of multiprocessing/threads as well.

The initial run on AWS Lambda with the above specs appears to take ~45 seconds on an initial run, but is much faster (< 10 seconds) on subsequent executions.

Check it out, I'd be curious to hear your thoughts. I can also create a PR to add a note in the documentation to mention this approach, as needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.