Cloth Segmentation U2-Net

CLOTH_SEGMENTATION_U2NET

Finds the clothes a person wears in a photo and returns a mask for the upper body, the lower body and full-body garments such as dresses, each as a mask at the photo's size with its box and score.

Utilitiesimage-segmentationclothingfashiongarment-masksvirtual-try-onmitFine-tunable
Cloth Segmentation U2-Net: Utilities model on Kainguru

About Cloth Segmentation U2-Net

Capabilities

  • Three garment classes — upper body (shirts, jackets), lower body (trousers, skirts) and full body (dresses, jumpsuits)
  • Masks, boxes and scores — a mask at the picture's size, its box and the model's confidence for each class found
  • No prompt — send a photo and get the masks back
  • Fine-tunable — train it on your own photos and label maps through the API

Good to know

  • Pictures are PNG, JPEG or WebP, up to 20 MB and 40 megapixels, at least 32 pixels a side and at most 8 times longer than wide. The model sees the picture squashed to 768 x 768 pixels; masks have the picture's size as displayed, scaled down to 2048 pixels on the longer side.
  • A class that covers under 0.05 percent of the picture is not returned, so a photo with no clothes comes back with no segment.
  • Each mask comes in the JSON as COCO run-length encoding, {"size": [height, width], "counts": "..."}; pycocotools' mask.decode turns it into a 0/1 array (1 = the garment). When the masks would take a response past 800 KB, as only very detailed ones do, they come at half the size or less; boxes stay in the picture's pixels.
  • Fine-tuning takes one ZIP (at most 4 GB and 5000 entries, no password) with 4 to 1000 pictures, a label map for each and manifest.jsonl with one {"file": "photos/a.jpg", "mask": "labels/a.png"} line per pair; paths are relative to the manifest. A label map is a grayscale or palette PNG of its picture's size as displayed whose pixel values are the classes 0 background, 1 upper body, 2 lower body, 3 full body; 255 leaves a pixel out.
  • Training resizes every pair to 768 x 768 once, mirrors half of the pictures, and stops after 5,000 steps or 9 hours, whichever comes first, keeping what it learned. The classes stay these four.
  • The model was trained on fashion photos of one person each; groups, flat-lay clothes and unusual crops are harder.

Attribution

Cloth segmentation by Levin Dabhi (levindabhi/cloth-segmentation), released under the MIT License, Copyright (c) 2021 Levin Dabhi; the network is 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).

Cloth Segmentation U2-Net inputs and output

NameTypeRequiredDefaultDetails
imagefileYes—The picture: PNG, JPEG or WebP, up to 20 MB and 40 megapixels. Masks have its size, scaled down to 2048 pixels on the longer side.
1–2048 characters · image/png, jpeg, webp

Output. JSON: {"width", "height", "segments": [{"label", "score", "box", "mask"}]}, a segment for each of upper_body, lower_body and full_body found; box [x0, y0, x1, y1] in pixels, mask a COCO RLE {"size": [h, w], "counts"}.

Run Cloth Segmentation 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=CLOTH_SEGMENTATION_U2NET" \
  -H "X-API-Key: kg_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "image": "https://example.com/input.png"
  },
  "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(
        "CLOTH_SEGMENTATION_U2NET",
        {
          "image": "https://example.com/input.png"
        },
        output_format="json",
    )
    result = client.executions.await_completion(submitted.id)
    print(result.execution.output)

Fine-tune Cloth Segmentation U2-Net

You can fine-tune Cloth Segmentation U2-Net on your own data and run the tuned model through the same API. Dataset: One ZIP (at most 4 GB, no password) with 4 to 1000 pictures, a label map for each (a PNG whose pixel values are the classes 0 to 3) and a manifest.jsonl with one {"file", "mask"} line per pair. More rules: Good to know, in the README.

The steps are in the docs.

Cloth Segmentation 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
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
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
MoGe-2 ViT-L Normal: Utilities model on Kainguru
Utilities

MoGe-2 ViT-L Normal

Estimates metric depth, surface normals and the camera's field of view from a single photo of any scene, indoors or out.

Fine-tunable