Semantic Segmentation

Run inference on semantic segmentation models hosted on Roboflow.

Linux or MacOS

Retrieving JSON predictions for a local file called YOUR_IMAGE.jpg:

base64 YOUR_IMAGE.jpg | curl -d @- \
"https://segment.roboflow.com/your-model/42?api_key=YOUR_KEY"

Inferring on an image hosted elsewhere on the web via its URL (don't forget to URL encode it):

curl -X POST "https://segment.roboflow.com/your-model/42?\
api_key=YOUR_KEY&\
image=https%3A%2F%2Fi.imgur.com%2FPEEvqPN.png"

Windows

You will need to install curl for Windows and GNU's base64 tool for Windows. The easiest way to do this is to use the git for Windows installer which also includes the curl and base64 command line tools when you select "Use Git and optional Unix tools from the Command Prompt" during installation.

Then you can use the same commands as above.

Response Object Format

The hosted API inference route returns a JSON object containing an array of predictions. Each prediction has the following properties:

  • segmentation_mask = base64 encoded single channel image with dimensions equal to the input image where each pixel value corresponds to a class ID

  • class_map = object that maps class IDs to class names

  • image = an object with the input image dimensions

    • height = height of the input image in number of pixels

    • width = width of the input image in number of pixels

// an example JSON object
{
    "segmentation_mask": "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAAAAADRE4smAAAIqElEQVR4nO3dyXbb2BJFQfCt+v9f5htYstWwQXNB3pMZMaiaeMkAcjMBSpa0LAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACRLu8+gJf4cZbX9xzFlBoEcPMUNfChfgB3z1ADy1I/gEfnp4ClegDPzk4CpQNYc27tE/jfuw/gPKvarvwCWKXuBVh9Zr2XQNkNsL7suq+BNYqe/bbT6rwDam6AjVkXfRWsUjKAzQNtXEDJALbrW0DFAPZMs20BBQNoO8td6gWwc/5dsykXwO5BNi2gXAD79SxAAP+0LKBaAC2HeESxAMx/q1oBHJx/x3xqBXBUwwJKBXB8fv0KKBUA21UKYMTLt90KqBQAOxQKoN2Ld4g6AQyaf7eM6gTALgL4qdkKKBPAuLn1KqBMAOwjgOaqBDByb7e6B1QJgJ0E0FyRAF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ev71Aphj985xFGuUC2CKaz/DMaxUL4DhVz9omjsUDOD9kpKpGMC96/+quSTNv2QAdyYQNZeXKRnATS+bf1ZoNQO4MYOssbxOzQDGjnvbDxcOK61oAL+Gdmgsu78POUDVAMaKG+t6ZQN4z8zySqn7lY5vZ/aa3wOcN/7CG2D0NFZ8uMT5F94Ay+gfEfrsUkXOv3YAn6c3aDSPr1Xm/KsHMNj9qxU6/srPAGe4O+bY+dsAW926YLnjF8AOPy9Z8vgFsNffn0H/1qMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACARv4PAgMMHbaPKVQAAAAASUVORK5CYII=",
    "class_map": {
        "0": " background",
        "1": " object"
    },
    "image": {
        "width": 1232,
        "height": 821
    }
}

API Reference

Using the Inference API

POST https://segment.roboflow.com/:datasetSlug/:versionNumber

You can POST a base64 encoded image directly to your model endpoint. Or you can pass a URL as the image parameter in the query string if your image is already hosted elsewhere.

Path Parameters

NameTypeDescription

datasetSlug

string

The url-safe version of the dataset name. You can find it in the web UI by looking at the URL on the main project view or by clicking the "Get curl command" button in the train results section of your dataset version after training your model.

version

number

The version number identifying the version of of your dataset

Query Parameters

NameTypeDescription

image

string

URL of the image to add. Use if your image is hosted elsewhere. (Required when you don't POST a base64 encoded image in the request body.) Note: don't forget to URL-encode it.

confidence

number

A threshold for the returned predictions on a scale of 0-100. A lower number will return more predictions. A higher number will return fewer high-certainty predictions. Default: 50

api_key

string

Your API key (obtained via your workspace API settings page)

Request Body

NameTypeDescription

string

A base64 encoded image. (Required when you don't pass an image URL in the query parameters).

{
    "segmentation_mask": "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAAAAADRE4smAAAIqElEQVR4nO3dyXbb2BJFQfCt+v9f5htYstWwQXNB3pMZMaiaeMkAcjMBSpa0LAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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n/kheAKQ4VGMDmAv5+UVY6vyUGsHGQf38FiPnfUP97Az/mb/q3RW6AHdM0/zsyAzgyz6e/JuLHH9//N0UIDWBrAbuDqT7/2ADs9EFiA9j0UP/9j254VZdfAMEB7F0C1xcuj4A1lRzA7gL4JzoAszwuO4DJC5j76P4ID2DlNa7/LLdbegBrC5DAHSUuzKbf67DxI1/3X6OEO0D+BliW07/OV/rLiCUCOHFG1y//LalIAGfNqPDkP5R4Bvj05GSOTLPsD4suswGWpfjN+iSlAphLRo0CWGXHHSBj/gLorlMA+x946y6AagGkXPZ5FAvgHIUXQLkAzrjwpT5X8lO1AE5Qev71Aphj985xFGuUC2CKaz/DMaxUL4DhVz9omjsUDOD9kpKpGMC96/+quSTNv2QAdyYQNZeXKRnATS+bf1ZoNQO4MYOssbxOzQDGjnvbDxcOK61oAL+Gdmgsu78POUDVAMaKG+t6ZQN4z8zySqn7lY5vZ/aa3wOcN/7CG2D0NFZ8uMT5F94Ay+gfEfrsUkXOv3YAn6c3aDSPr1Xm/KsHMNj9qxU6/srPAGe4O+bY+dsAW926YLnjF8AOPy9Z8vgFsNffn0H/1qMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACARv4PAgMMHbaPKVQAAAAASUVORK5CYII=",
    "class_map": {
        "0": " background",
        "1": " object"
    },
    "image": {
        "width": 1232,
        "height": 821
    }
}

Last updated