Add Segmentation Annotations
curl --request POST \
--url https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"segmentations": [
{
"reference_id": "<string>",
"mask_url": "<string>",
"annotations": [],
"type": "mask",
"annotation_id": "<string>"
}
],
"update": false
}
'import requests
url = "https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation"
payload = {
"segmentations": [
{
"reference_id": "<string>",
"mask_url": "<string>",
"annotations": [],
"type": "mask",
"annotation_id": "<string>"
}
],
"update": False
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
segmentations: [
{
reference_id: '<string>',
mask_url: '<string>',
annotations: [],
type: 'mask',
annotation_id: '<string>'
}
],
update: false
})
};
fetch('https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'segmentations' => [
[
'reference_id' => '<string>',
'mask_url' => '<string>',
'annotations' => [
],
'type' => 'mask',
'annotation_id' => '<string>'
]
],
'update' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation"
payload := strings.NewReader("{\n \"segmentations\": [\n {\n \"reference_id\": \"<string>\",\n \"mask_url\": \"<string>\",\n \"annotations\": [],\n \"type\": \"mask\",\n \"annotation_id\": \"<string>\"\n }\n ],\n \"update\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"segmentations\": [\n {\n \"reference_id\": \"<string>\",\n \"mask_url\": \"<string>\",\n \"annotations\": [],\n \"type\": \"mask\",\n \"annotation_id\": \"<string>\"\n }\n ],\n \"update\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"segmentations\": [\n {\n \"reference_id\": \"<string>\",\n \"mask_url\": \"<string>\",\n \"annotations\": [],\n \"type\": \"mask\",\n \"annotation_id\": \"<string>\"\n }\n ],\n \"update\": false\n}"
response = http.request(request)
puts response.read_body{
"dataset_id": "ds_bw6de8s84pe0vbn6p5zg",
"annotations_processed": 2,
"annotations_ignored": 0,
"annotations_errored": 0
}{}Ground Truth Annotations
Add Segmentation Annotations
POST
/
dataset
/
{dataset_id}
/
annotate_segmentation
Add Segmentation Annotations
curl --request POST \
--url https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"segmentations": [
{
"reference_id": "<string>",
"mask_url": "<string>",
"annotations": [],
"type": "mask",
"annotation_id": "<string>"
}
],
"update": false
}
'import requests
url = "https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation"
payload = {
"segmentations": [
{
"reference_id": "<string>",
"mask_url": "<string>",
"annotations": [],
"type": "mask",
"annotation_id": "<string>"
}
],
"update": False
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
segmentations: [
{
reference_id: '<string>',
mask_url: '<string>',
annotations: [],
type: 'mask',
annotation_id: '<string>'
}
],
update: false
})
};
fetch('https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'segmentations' => [
[
'reference_id' => '<string>',
'mask_url' => '<string>',
'annotations' => [
],
'type' => 'mask',
'annotation_id' => '<string>'
]
],
'update' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation"
payload := strings.NewReader("{\n \"segmentations\": [\n {\n \"reference_id\": \"<string>\",\n \"mask_url\": \"<string>\",\n \"annotations\": [],\n \"type\": \"mask\",\n \"annotation_id\": \"<string>\"\n }\n ],\n \"update\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"segmentations\": [\n {\n \"reference_id\": \"<string>\",\n \"mask_url\": \"<string>\",\n \"annotations\": [],\n \"type\": \"mask\",\n \"annotation_id\": \"<string>\"\n }\n ],\n \"update\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.scale.com/v1/nucleus/dataset/{dataset_id}/annotate_segmentation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"segmentations\": [\n {\n \"reference_id\": \"<string>\",\n \"mask_url\": \"<string>\",\n \"annotations\": [],\n \"type\": \"mask\",\n \"annotation_id\": \"<string>\"\n }\n ],\n \"update\": false\n}"
response = http.request(request)
puts response.read_body{
"dataset_id": "ds_bw6de8s84pe0vbn6p5zg",
"annotations_processed": 2,
"annotations_ignored": 0,
"annotations_errored": 0
}{}Click for Python SDK
Dataset.annotate(
annotations: List[SegmentationAnnotation],
update: bool,
asynchronous: bool
) -> Union[dict, AsyncJob]
DatasetItem you are annotating. A DatasetItem can be referenced by either its internal ID, or the reference ID you provided when uploading the image.
Nucleus automatically enforces the constraint that each DatasetItem can have at most one ground truth segmentation mask. As a consequence, if during upload a duplicate mask is detected for a given image, by default it will be ignored. You can change this behavior by setting the optional update boolean to true, which will replace the existing segmentation with the new mask specified in the request body.Authorizations
Body
application/json