InSPyReNet

INSPYRENET

Removes the background from a photo with fine detail at hair and edges, and returns the subject on a transparent background or as a black-and-white mask.

Utilitiesbackground-removalimage-segmentationcutouthigh-resolutionmitFine-tunable
InSPyReNet: Utilities model on Kainguru

About InSPyReNet

Capabilities

  • Fine edges — a soft mask that follows hair, fur and thin structures
  • 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 1024x1024 copy and the mask is scaled back to the photo's size.
  • 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 1024x1024 copies, mirrors half of them, and stops after 5,000 steps or 9 hours, whichever comes first, keeping what it learned.

Attribution

InSPyReNet by Taehun Kim, Kunhee Kim, Joonyeong Lee, Dongmin Cha, Jiho Lee and Daijin Kim, released under the MIT License, Copyright (c) 2021 Taehun Kim. Its Swin Transformer backbone is Copyright (c) 2021 Microsoft, MIT License.

InSPyReNet 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 InSPyReNet 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=INSPYRENET" \
  -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(
        "INSPYRENET",
        {
          "image": "https://example.com/input.png",
          "output": "cutout"
        },
        output_format="json",
    )
    result = client.executions.await_completion(submitted.id)
    print(result.execution.output)

Fine-tune InSPyReNet

You can fine-tune InSPyReNet 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.

InSPyReNet pricing

Price per image: 0.05225 credits ($0.0005225). 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
Rembg U2-Net: Utilities model on Kainguru
Utilities

Rembg U2-Net

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

Fine-tunable
Cloth Segmentation U2-Net: Utilities model on Kainguru
Utilities

Cloth Segmentation U2-Net

Finds the clothes a person wears in a photo and returns a mask for the upper body, the lower body and full-body…

Fine-tunable
EoMT Large COCO Panoptic: Utilities model on Kainguru
Utilities

EoMT Large COCO Panoptic

Splits a picture into its objects and regions, such as people, cars, sky and road, with a label and a mask for each one.

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