Rembg U2-Net

REMBG_U2NET

Fast background removal that returns the subject of a photo on a transparent background, or as a black-and-white mask.

Utilitiesbackground-removalimage-segmentationcutoutlightweightapache-2.0Fine-tunable
Rembg U2-Net: Utilities model on Kainguru

About Rembg U2-Net

Capabilities

  • Fast — a compact network that works on a 320x320 copy of the photo
  • Cutout or mask — the subject on a transparent background (RGBA PNG), or white on black (grayscale PNG)
  • Full-size results — the cutout or mask has the photo's own width and height
  • Fine-tunable — train it on your own image and mask pairs through the API

Good to know

  • Photos up to 50 MB and 50 megapixels, as PNG, JPEG or WebP; the network works on a 320x320 copy and the mask is scaled back to the photo's size, so very fine detail such as single hairs comes out soft.
  • Each mask is stretched to the full range: the photo's surest subject pixel becomes white and its surest background pixel black, so a photo without a clear subject still gets a full-contrast mask.
  • Fine-tuning takes 4 to 500 image/mask pairs, each up to 50 MB and 50 megapixels. A mask has its image's size, white for the subject and black for the background; a cutout with a transparent background also works as a mask.
  • Fine-tuning works through the API only for now, as the web form cannot write the manifest yet: (1) upload each image and mask with POST /v1/files/upload/{fileType} (JPEG, PNG or WEBP) and keep the URL each upload returns; (2) write a JSONL file with one {"file": "...", "mask": "..."} line per pair, holding that image URL and mask URL, and upload it with POST /v1/files/upload/JSONL; (3) start the fine-tune with POST /v1/fine-tuning, its dataset set to all the image, mask and manifest URLs.
  • Training works on 320x320 copies, mirrors half of them, and stops after 5,000 steps or 9 hours, whichever comes first, keeping what it learned.

Attribution

U^2-Net by Xuebin Qin, Zichen Zhang, Chenyang Huang, Masood Dehghan, Osmar R. Zaiane and Martin Jagersand, released under the Apache License 2.0; the weights as exported by the rembg project (MIT License).

Rembg U2-Net inputs and output

NameTypeRequiredDefaultDetails
imagefileYes—The photo to cut out: PNG, JPEG or WebP, up to 50 MB and 50 megapixels.
1–2048 characters · image/png, jpeg, webp
outputtextNocutoutcutout: the photo on a transparent background (RGBA PNG); mask: the subject in white on black (grayscale PNG).
Allowed: cutout, mask

Output. Returns PNG image: PNG at the photo's size: the cutout (RGBA) or the mask (grayscale).

Run Rembg U2-Net with the API

Send your API key in the X-API-Key header. The run is asynchronous: submit it, then poll it until it finishes. Create an API key.

cURL
curl -X POST "https://api.kainguru.com/api/v1/executions?mlFlowId=REMBG_U2NET" \
  -H "X-API-Key: kg_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "image": "https://example.com/input.png",
    "output": "cutout"
  },
  "outputFormat": "json"
}'

# Poll until the execution reaches a terminal state
curl "https://api.kainguru.com/api/v1/executions/{executionId}" \
  -H "X-API-Key: kg_your_api_key"
Python
from kainguru import KainguruClient

with KainguruClient(api_key="kg_your_api_key", base_url="https://api.kainguru.com/api") as client:
    submitted = client.executions.execute(
        "REMBG_U2NET",
        {
          "image": "https://example.com/input.png",
          "output": "cutout"
        },
        output_format="json",
    )
    result = client.executions.await_completion(submitted.id)
    print(result.execution.output)

Fine-tune Rembg U2-Net

You can fine-tune Rembg U2-Net on your own data and run the tuned model through the same API. Dataset: 4 to 500 images, one mask per image (same size; white = subject, black = background, or a cutout with a transparent background) and a JSONL manifest with one {"file": "...", "mask": "..."} object per line, each value the URL that file's upload returned.

The steps are in the docs.

Rembg U2-Net pricing

Price per image: 0.0874 credits ($0.000874). The price is shown again before every run; all prices are on the pricing page.

Licence and source

BiRefNet General: Utilities model on Kainguru
Utilities

BiRefNet General

Removes the background from a photo and returns the subject on a transparent background, or as a black-and-white mask.

Fine-tunable
InSPyReNet: Utilities model on Kainguru
Utilities

InSPyReNet

Removes the background from a photo with fine detail at hair and edges, and returns the subject on a transparent…

Fine-tunable
SAM 2.1 Hiera Large: Utilities model on Kainguru
Utilities

SAM 2.1 Hiera Large

Click or draw a box on an object and get back a mask outlining it.

Fine-tunable
Grounded SAM 2: Utilities model on Kainguru
Utilities

Grounded SAM 2

Outlines the things you name in a picture, such as "red car, person with a helmet", with a mask and a box for each one.

Fine-tunable
MODNet Portrait Matting: Utilities model on Kainguru
Utilities

MODNet Portrait Matting

Cuts people out of photos with a soft alpha matte that keeps hair and fine edges, and returns the cutout or the matte…

Fine-tunable
Prithvi-EO 2.0 Sen1Floods11: Utilities model on Kainguru
Utilities

Prithvi-EO 2.0 Sen1Floods11

Maps water and floods from satellite images: send a Sentinel-2 GeoTIFF and get a water mask at the image's size, with…

Fine-tunable