Skip to main content

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:

  • u2netp as the default model instead of u2net
  • 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 u2net and u2netp in code, while keeping u2netp as 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 to u2netp.
  • new_session("u2net") and new_session("u2netp") are both supported in code.
  • The default build target packages only u2netp, not u2net.
  • 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 rembg package as rembg/u2netp.onnx or rembg/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 only u2netp.onnx
  • u2net - bundles only u2net.onnx
  • both - bundles both model files
  • none - bundles no model file; use this only if you will mount models through U2NET_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 u2net or u2netp at build time and the corresponding .onnx file is missing, the build fails immediately.
  • u2netp.onnx is tracked directly in the repository so the default light-model build works from a plain checkout.
  • u2net.onnx is 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 both unless 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:

  • bytes
  • PIL.Image.Image
  • numpy.ndarray

Supported output behavior:

  • remove(...) returns bytes for byte input
  • remove(...) returns a PIL.Image.Image for PIL input
  • remove(...) returns a numpy.ndarray for ndarray input
  • remove(..., 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.onnx is committed as a normal repository file so the default light-model path is easy to clone and build.
  • u2net.onnx remains optional and heavyweight; it should only be supplied intentionally.
  • The default build selection is u2netp; u2net is only packaged when explicitly selected.
  • Code support for u2net remains available when the file is mounted or included in a custom build.

References

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)

Source distribution for rembg-aws-lambda-lite 0.1.3
File Size Uploaded
rembg_aws_lambda_lite-0.1.3.tar.gz 4.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for rembg-aws-lambda-lite 0.1.3
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page