rembg-aws-lambda-lite
Minimal rembg fork for Lambda-style CPU inference.
This repository is a modified fork of rnag/rembg-aws-lambda. It keeps the original MIT license and copyright notices, but narrows the package to the lightweight u2netp model path.
Why this fork exists
This fork is not universally better than rnag/rembg-aws-lambda. It is better for a narrower use case: CPU-only AWS Lambda deployments that want explicit model packaging, lighter default artifacts, and current Python support.
Compared with the upstream fork, this repository adds:
u2netpas the default model instead ofu2net- build-time model packaging selection through
REMBG_PACKAGE_MODELS - explicit failure when a selected model file is missing or still only a Git LFS pointer
- support for both
u2netandu2netpin code, while keepingu2netpas the default packaging target - a normal tracked default light-model asset, instead of forcing Git LFS for the lightweight path
- Python support through
3.12 - CPU-first ONNX Runtime provider selection, which fits Lambda inference better than taking every available local provider
Compared with the upstream README and packaging behavior, this fork also documents an important operational constraint more honestly: model selection at runtime and model packaging at build time are separate concerns.
What changed
new_session()now defaults tou2netp.new_session("u2net")andnew_session("u2netp")are both supported in code.- The default build target packages only
u2netp, notu2net. - Python support is updated for Python through
3.12. - The package no longer relies on runtime model downloads.
Supported runtime
- CPU only
- AWS Lambda base images such as
public.ecr.aws/lambda/python:3.12 - Local development on Python through
3.12
Installation
pip install rembg-aws-lambda-lite
This fork expects the requested model file to be present either:
- inside the installed
rembgpackage asrembg/u2netp.onnxorrembg/u2net.onnx, or - in the directory pointed to by
U2NET_HOME
If the requested model file is missing, new_session() raises FileNotFoundError immediately.
Build-time model selection
Bundled model selection is controlled at build time with REMBG_PACKAGE_MODELS.
Supported values:
u2netp- default, bundles onlyu2netp.onnxu2net- bundles onlyu2net.onnxboth- bundles both model filesnone- bundles no model file; use this only if you will mount models throughU2NET_HOME
Examples:
REMBG_PACKAGE_MODELS=u2netp python -m build
REMBG_PACKAGE_MODELS=u2net python -m build
REMBG_PACKAGE_MODELS=both python -m build
REMBG_PACKAGE_MODELS=none python -m build
Docker example:
ARG REMBG_PACKAGE_MODELS=u2netp
ENV REMBG_PACKAGE_MODELS=${REMBG_PACKAGE_MODELS}
RUN python -m pip install --no-cache-dir . --target "${LAMBDA_TASK_ROOT}"
Important:
- Runtime model selection does not change packaged contents.
- If you request
u2netoru2netpat build time and the corresponding.onnxfile is missing, the build fails immediately. u2netp.onnxis tracked directly in the repository so the default light-model build works from a plain checkout.u2net.onnxis still a heavyweight optional path. If you select it and the file is only a Git LFS pointer in your checkout, the build fails until you fetch the real object.- If you care about Lambda cold starts, do not build with
bothunless you actually need a single artifact to contain both models.
Library usage
from rembg import new_session, remove
session = new_session()
cutout = remove(input_image, session=session)
Explicit model selection:
from rembg import new_session
session = new_session("u2netp")
If you need the larger model and have supplied the file:
from rembg import new_session
session = new_session("u2net")
Supported input types:
bytesPIL.Image.Imagenumpy.ndarray
Supported output behavior:
remove(...)returns bytes for byte inputremove(...)returns aPIL.Image.Imagefor PIL inputremove(...)returns anumpy.ndarrayfor ndarray inputremove(..., only_mask=True)returns the predicted mask
Provider selection
This fork is intended for CPU-only Lambda use. By default it prefers CPUExecutionProvider when ONNX Runtime exposes multiple providers.
If you need to override that behavior, set REMBG_ONNX_PROVIDERS to a comma-separated list of ONNX Runtime provider names:
REMBG_ONNX_PROVIDERS=CPUExecutionProvider python your_script.py
Docker smoke test
FROM public.ecr.aws/lambda/python:3.10
ENV OMP_NUM_THREADS=1
ENV REMBG_PACKAGE_MODELS=u2netp
RUN python -m pip install --no-cache-dir rembg-aws-lambda-lite --target "${LAMBDA_TASK_ROOT}" \
&& python -c "from rembg import new_session; new_session('u2netp')"
The default u2netp smoke test works from a plain checkout because the light model is stored directly in the repository. A u2net or both build still requires the heavyweight model object to be present locally.
Development notes
u2netp.onnxis committed as a normal repository file so the default light-model path is easy to clone and build.u2net.onnxremains optional and heavyweight; it should only be supplied intentionally.- The default build selection is
u2netp;u2netis only packaged when explicitly selected. - Code support for
u2netremains available when the file is mounted or included in a custom build.
References
- Original upstream fork: https://github.com/rnag/rembg-aws-lambda
- Original
rembg: https://github.com/danielgatis/rembg - U-2-Net paper: https://arxiv.org/abs/2005.09007
- U-2-Net repository: https://github.com/xuebinqin/U-2-Net
License
Licensed under the MIT License.
Release files for rembg-aws-lambda-lite 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rembg_aws_lambda_lite-0.1.3.tar.gz | 4.3 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rembg_aws_lambda_lite-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.5 MB
Release files / rembg_aws_lambda_lite-0.1.3.tar.gz
| Download URL | rembg_aws_lambda_lite-0.1.3.tar.gz |
|---|---|
| Size | 4.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd87396c73ab65042038f9a61ffca803ddff8f86527dbbf9e82b52aab29beeb7
|
|
BLAKE2b-256 checksum How to use checksums |
9eb67ada11446a35219aa5edd214e47f508112599d1b73e2cbf05099300ab8cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency logRelease files / rembg_aws_lambda_lite-0.1.3-py3-none-any.whl
| Download URL | rembg_aws_lambda_lite-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ac14c86259fb832360791a1600eed0a1832a4a36820fa51a4633ca1a2737837
|
|
BLAKE2b-256 checksum How to use checksums |
7cc099115994f39eba6ca13992cc18185c6bb037f9ee180825dd34bad9596070
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 12, 2026.
Transparency log