Inference Providers documentation

Image Segmentation

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Image Segmentation

Image Segmentation divides an image into segments where each pixel in the image is mapped to an object.

For more details about the image-segmentation task, check out its dedicated page! You will find examples and related materials.

Recommended models

Explore all available models and find the one that suits you best here.

Using the API

from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="hf-inference",
    api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxx",
)

output = client.image_segmentation("cats.jpg", model="jonathandinu/face-parsing")

API specification

Request

Headers
authorization string Authentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page.
Payload
inputs* string The input image data as a base64-encoded string. If no parameters are provided, you can also provide the image data as a raw bytes payload.
parameters object
        mask_threshold number Threshold to use when turning the predicted masks into binary values.
        overlap_mask_area_threshold number Mask overlap threshold to eliminate small, disconnected segments.
        subtask enum Possible values: instance, panoptic, semantic.
        threshold number Probability threshold to filter out predicted masks.

Response

Body
(array) object[] A predicted mask / segment
        label string The label of the predicted segment.
        mask string The corresponding mask as a black-and-white image (base64-encoded).
        score number The score or confidence degree the model has.
< > Update on GitHub