Create Annotations | Clarifai Docs
GPU Shortage?Make the most out of your GPUs with Compute Orchestration. Learn More
On this page
Label your data
Annotations (also known as labels) describe your inputs. When you add inputs to your app, we will create an input level annotation for each input. This input level annotation contains any data you provided in POST /inputs call. Models in your default workflow can also write annotations.
Once your input is successfully indexed, you can add additional annotations, such as concepts and bounding boxes.
You can label your inputs by calling the POST /annotations endpoint. For example, you can add concept(s) to an image, draw a bounding box, or label concept(s) in a video frame.
When you add an annotation, the app's default workflow will be run by default. This means that any newly added annotations will be immediately available for AI based search and training.
tip
You can add from 1 up to 128 annotations in a single API call.
Each annotation should contain at most one region. If it is a video, each annotation should contain 1 frame. If there are multiple regions in a frame you want to label, you can add multiple annotations for each region and each annotation will be contained within the same frame but in a different region.
Annotate Images With Concepts
Below is an example of how to annotate a concept present anywhere in an image.
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- cURL
#################################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate the image.
# Change these strings to run your own example.
#################################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the image you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[\
resources_pb2.Annotation(\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present\
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present\
]\
)\
)\
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the image you want to annotate
const INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [\
{\
"input_id": INPUT_ID,\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
"data": {\
"concepts": [\
{\
"id": CONCEPT_ID_1,\
"value": 1\
},\
{\
"id": CONCEPT_ID_2,\
"value": 0\
}\
]\
}\
}\
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [\
{\
input_id: INPUT_ID,\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
data: {\
concepts: [\
{ id: CONCEPT_ID_1, value: 1 },\
{ id: CONCEPT_ID_2, value: 0 }\
]\
}\
\
}\
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
// annotate the image. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the image you want to annotate
static final String INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
).addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
);
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the image you want to annotate
$INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([\
"user_app_id" => $userDataObject,\
"annotations" => [\
new Annotation([\
"input_id" => $INPUT_ID,\
"data" => new Data([\
"concepts" => [\
new Concept(["id" => $CONCEPT_ID_1, "value" => 1.]),\
new Concept(["id" => $CONCEPT_ID_2, "value" => 0.])\
]\
])\
])\
]\
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [\
{\
"input_id": "YOUR_INPUT_ID_HERE",\
"data": {\
"concepts": [\
{\
"id": "tree",\
"value": 1\
},\
{\
"id": "water",\
"value": 0\
}\
]\
}\
}\
]
}'
Annotate Images With Multiple Concepts
Below is an example of how to annotate an image with multiple concepts in a single API call. You can provide the concepts in a list and iterate through it.
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
USER_ID = 'YOUR_USER_ID_HERE'
Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE' APP_ID = 'YOUR_APP_ID_HERE'
Change these based on the image you want to annotate with multiple concepts
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73" CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six']
channel = ClarifaiChannel.get_grpc_channel() stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
# We use Python list comprehension to iterate through the list of concepts
resources_pb2.Concept(id=str(i), value=1.) for i in CONCEPT_IDS_LIST
]
)
)
]
),
metadata=metadata
)
<!--index.html file-->
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the image you want to annotate with multiple concepts
const INPUT_ID = "c99f1b557d1d43d1916b46f8ce4a0487";
const CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six'];
// We use a map function to iterate through the list of concepts
const myFunction = () => {
return CONCEPT_IDS_LIST.map((concept)=>({"id":concept,"value":1}));
}
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [\
{\
"input_id": INPUT_ID,\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
"data": {\
"concepts": myFunction()\
}\
}\
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
</script>
//index.js file
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [\
{\
input_id: INPUT_ID,\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
data: {\
concepts: myFunction()\
}\
\
}\
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
Annotate New Bounding Boxes in an Image
Below is an example of how to label a new rectangular bounding box for a region.
These are the bounding box coordinates you need to provide:
top_row—The top left of the bounding box normalized to the data dimension to be within [0-1.0];
left_col—The left column of the bounding box normalized to the data dimension to be within [0-1.0];
bottom_row—The bottom row of the bounding box normalized to the data dimension to be within [0-1.0];
right_col—The right col of the bounding box normalized to the data dimension to be within [0-1.0].
Python (gRPC)
JavaScript (REST)
Node.js (gRPC)
Java (gRPC)
PHP (gRPC)
cURL
########################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate
# new bounding boxes. Change these strings to run your own example.
#########################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the new bounding boxes you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
CONCEPT_ID_3 = "bike"
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[\
resources_pb2.Annotation(\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
regions=[\
resources_pb2.Region(\
region_info=resources_pb2.RegionInfo(\
bounding_box=resources_pb2.BoundingBox( # draw a bounding box\
top_row=0,\
left_col=0,\
bottom_row=0.5,\
right_col=0.5\
)\
),\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.\
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.\
]\
)\
)\
]\
)\
\
),\
resources_pb2.Annotation(\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
regions=[\
resources_pb2.Region(\
region_info=resources_pb2.RegionInfo(\
bounding_box=resources_pb2.BoundingBox( # draw another bounding box\
top_row=0.6,\
left_col=0.6,\
bottom_row=0.8,\
right_col=0.8\
)\
),\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id=CONCEPT_ID_3, value=1.), # 1 means true, this concept is present.\
]\
)\
)\
]\
)\
\
)\
]
),
metadata=metadata
)
```javascript
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// new bounding boxes. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the new bounding boxes you want to annotate
const INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [\
{\
"input_id": INPUT_ID,\
"data": {\
"regions": [\
{\
"region_info": {\
"bounding_box": {\
"top_row": 0,\
"left_col": 0,\
"bottom_row": 0.5,\
"right_col": 0.5\
}\
},\
"data": {\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
"concepts": [\
{\
"id": CONCEPT_ID_1,\
"value": 1\
},\
{\
"id": CONCEPT_ID_2,\
"value": 0\
}\
]\
}\
}\
]\
}\
\
}, {\
"input_id": INPUT_ID,\
"data": {\
"regions": [\
{\
"region_info": {\
"bounding_box": {\
"top_row": 0.6,\
"left_col": 0.6,\
"bottom_row": 0.8,\
"right_col": 0.8\
}\
},\
"data": {\
"concepts": [\
{\
"id": CONCEPT_ID_3,\
"value": 1\
}\
]\
}\
}\
]\
}\
\
}\
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// new bounding boxes. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the new bounding boxes you want to annotate
const INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [\
{ // label a region in this image\
input_id: INPUT_ID,\
data: {\
regions: [\
{\
region_info: {\
bounding_box: { // draw a bounding box\
top_row: 0,\
left_col: 0,\
bottom_row: 0.5,\
right_col: 0.5\
}\
},\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
data: {\
concepts: [\
{ id: CONCEPT_ID_1, value: 1 },\
{ id: CONCEPT_ID_2, value: 0 }\
]\
},\
}\
]\
}\
\
}, { // label another region in this image\
input_id: INPUT_ID,\
data: {\
regions: [\
{\
region_info: {\
bounding_box: { // draw another bounding box\
top_row: 0.6,\
left_col: 0.6,\
bottom_row: 0.8,\
right_col: 0.8\
}\
},\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
data: {\
concepts: [\
{ id: CONCEPT_ID_3, value: 1 },\
]\
},\
}\
]\
}\
\
}\
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
public class ClarifaiExample {
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the new bounding boxes you want to annotate
static final String INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "bike";
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder() // label a region in this image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setBoundingBox( // draw a bounding box
BoundingBox.newBuilder()
.setTopRow(0f)
.setLeftCol(0f)
.setBottomRow(0.5f)
.setRightCol(0.5f)
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
)
.build()
).addAnnotations( // label another region in this image
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setBoundingBox( // draw another bounding box
BoundingBox.newBuilder()
.setTopRow(0.6f)
.setLeftCol(0.6f)
.setBottomRow(0.8f)
.setRightCol(0.8f)
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
).build()
).build()
);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the new bounding boxes you want to annotate
$INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
$CONCEPT_ID_3 = "bike";
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\BoundingBox;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Region;
use Clarifai\Api\RegionInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([\
"user_app_id" => $userDataObject,\
"annotations" => [\
new Annotation([\
"input_id" => $INPUT_ID,\
"data" => new Data([\
"regions" => [\
new Region([\
"region_info" => new RegionInfo([\
"bounding_box" => new BoundingBox([ // draw a bounding box\
"top_row" => 0,\
"left_col" => 0,\
"bottom_row" => 0.5,\
"right_col" => 0.5\
])\
]),\
"data" => new Data([\
"concepts" => [\
new Concept([ "id" => $CONCEPT_ID_1, "value" => 1. ]), // 1 means true, this concept is present\
new Concept([ "id" => $CONCEPT_ID_2, "value" => 0. ]), // 0 means false, this concept is not present\
]\
])\
])\
]\
])\
]),\
new Annotation([\
"input_id" => $INPUT_ID,\
"data" => new Data([\
"regions" => [\
new Region([\
"region_info" => new RegionInfo([\
"bounding_box" => new BoundingBox([ // draw another bounding box\
"top_row" => 0.6,\
"left_col" => 0.6,\
"bottom_row" => 0.8,\
"right_col" => 0.8\
])\
]),\
"data" => new Data([\
"concepts" => [\
new Concept([ "id" => $CONCEPT_ID_3, "value" => 1. ]), // 1 means true, this concept is present\
]\
])\
])\
]\
])\
])\
]\
]),
$metadata
)->wait();
?>
# Draw two bounding boxes in the same region
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [\
{\
"input_id": "YOUR_INPUT_ID_HERE",\
"data": {\
"regions": [\
{\
"region_info": {\
"bounding_box": {\
"top_row": 0,\
"left_col": 0,\
"bottom_row": 0.5,\
"right_col": 0.5\
}\
},\
"data": {\
"concepts": [\
{\
"id": "tree",\
"value": 1\
},\
{\
"id": "water",\
"value": 0\
}\
]\
}\
}\
]\
}\
}, {\
"input_id": "YOUR_INPUT_ID_HERE",\
"data": {\
"regions": [\
{\
"region_info": {\
"bounding_box": {\
"top_row": 0.6,\
"left_col": 0.6,\
"bottom_row": 0.8,\
"right_col": 0.8\
}\
},\
"data": {\
"concepts": [\
{\
"id": "bike",\
"value": 1\
}\
]\
}\
}\
]\
}\
}\
]
}'
Annotate Polygons in an Image
Below is an example of how to provide annotations within any polygon-shaped region of an image.
These are the list of points that connect together to form a polygon:
row—The row location of the point. This has a [0.0-1.0] range with 0.0 being top row and 1.0 being the bottom row;
col—The column location of the point. This has a [0.0-1.0] range with 0.0 being left col and 1.0 being the right col;
z—Depth, if applicable, of the point.
Python (gRPC)
JavaScript (REST)
Node.js (gRPC)
Java (gRPC)
PHP (gRPC)
cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate
# a polygon. Change these strings to run your own example.
#########################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the polygon you want to annotate
INPUT_ID = "ca8666e974ac4c2c8dfbd7df1e7cbc44"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
CONCEPT_ID_3 = "bike"
from clarifai_grpc.grpc.api.status import status_code_pb2
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
# The userDataObject is created in the overview and is required when using a PAT
user_app_id=userDataObject,
annotations=[\
resources_pb2.Annotation(\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
regions=[\
resources_pb2.Region(\
region_info=resources_pb2.RegionInfo(\
polygon=resources_pb2.Polygon( # draw a polygon\
points=[\
resources_pb2.Point(row=0.30), # row location of the point, with a [0.0-1.0] range\
resources_pb2.Point(col=0.50), # column location of the point, with a [0.0-1.0] range\
resources_pb2.Point(z=0.50) # depth, if applicable, of the point\
]\
)\
),\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id=CONCEPT_ID_1, value=1), # 1 means true, this concept is present\
resources_pb2.Concept(id=CONCEPT_ID_2, value=0) # 0 means false, this concept is not present\
]\
)\
)\
]\
)\
\
),\
resources_pb2.Annotation(\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
regions=[\
resources_pb2.Region(\
region_info=resources_pb2.RegionInfo(\
polygon=resources_pb2.Polygon( # draw another polygon\
points=[\
resources_pb2.Point(row=0.60),\
resources_pb2.Point(col=0.80),\
resources_pb2.Point(z=0.50)\
]\
)\
),\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id=CONCEPT_ID_3, value=1), # 1 means true, this concept is present\
]\
)\
)\
]\
)\
\
)\
]
),
metadata=metadata
)
```javascript
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// a polygon. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the polygon you want to annotate
const INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [\
{\
"input_id": INPUT_ID,\
"data": {\
"regions": [\
{\
"region_info": {\
"polygon": {\
"points": [\
{\
"row": 0.30\
},\
{\
"col": 0.50\
},\
{\
"z": 0.50\
}\
]\
}\
},\
"data": {\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
"concepts": [\
{\
"id": CONCEPT_ID_1,\
"value": 1\
},\
{\
"id": CONCEPT_ID_2,\
"value": 0\
}\
]\
}\
}\
]\
}\
\
}, {\
"input_id": INPUT_ID,\
"data": {\
"regions": [\
{\
"region_info": {\
"polygon": {\
"points": [\
{\
"row": 0.60\
},\
{\
"col": 0.80\
},\
{\
"z": 0.50\
}\
\
]\
\
}\
},\
"data": {\
"concepts": [\
{\
"id": CONCEPT_ID_3,\
"value": 1\
}\
]\
}\
}\
]\
}\
\
}\
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// a polygon. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the polygon you want to annotate
const INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [\
{ // label a region in this image\
input_id: INPUT_ID,\
data: {\
regions: [\
{\
region_info: {\
polygon: { // draw a polygon\
points: [\
{\
row: 0.30 // row location of the point, with a [0.0-1.0] range\
},\
{\
col: 0.50 // column location of the point, with a [0.0-1.0] range\
},\
{\
z: 0.50 // depth, if applicable, of the point\
}\
]\
}\
},\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
data: {\
concepts: [\
{ id: CONCEPT_ID_1, value: 1 },\
{ id: CONCEPT_ID_2, value: 0 }\
]\
},\
}\
]\
}\
\
}, { // label another region in this image\
input_id: INPUT_ID,\
data: {\
regions: [\
{\
region_info: {\
polygon: { // draw another polygon\
points: [\
{\
row: 0.60\
},\
{\
col: 0.80\
},\
{\
z: 0.50\
}\
\
]\
}\
},\
// 1 means true, this concept is present\
// 0 means false, this concept is not present\
data: {\
concepts: [\
{ id: CONCEPT_ID_3, value: 1 },\
]\
},\
}\
]\
}\
\
}\
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
public class ClarifaiExample {
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the polygon you want to annotate
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "bike";
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder() // label a region in this image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setPolygon( // draw a polygon
Polygon.newBuilder()
.addPoints(Point.newBuilder().setRow(0.3f)) // row location of the point, with a [0.0-1.0] range
.addPoints(Point.newBuilder().setCol(0.5f)) // column location of the point, with a [0.0-1.0] range
.addPoints(Point.newBuilder().setZ(0.5f)) // depth, if applicable, of the point
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
)
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
)
.build()
)
.addAnnotations( // label another region in this image
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setPolygon( // draw another polygon
Polygon.newBuilder()
.addPoints(Point.newBuilder().setRow(0.6f))
.addPoints(Point.newBuilder().setCol(0.8f))
.addPoints(Point.newBuilder().setZ(0.5f))
.build()
)
.build()
)
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
).build()
).build()
);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the polygon you want to annotate
$INPUT_ID = "a8748df4938447e4844b2f505c8eaaef";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
$CONCEPT_ID_3 = "bike";
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Point;
use Clarifai\Api\Polygon;
use Clarifai\Api\Region;
use Clarifai\Api\RegionInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [\
{\
"input_id": "YOUR_INPUT_ID_HERE",\
"data": {\
"regions": [\
{\
"region_info": {\
"polygon": {\
"points": [\
{\
"row": 0.30\
},\
{\
"col": 0.50\
},\
{\
"z": 0.50\
}\
]\
}\
},\
"data": {\
"concepts": [\
{\
"id": "YOUR_CONCEPT_ID_1",\
"value": 1\
},\
{\
"id": "YOUR_CONCEPT_ID_2",\
"value": 0\
}\
]\
}\
}\
]\
}\
\
}, {\
"input_id": "YOUR_INPUT_ID_HERE",\
"data": {\
"regions": [\
{\
"region_info": {\
"polygon": {\
"points": [\
{\
"row": 0.60\
},\
{\
"col": 0.80\
},\
{\
"z": 0.50\
}\
\
]\
\
}\
},\
"data": {\
"concepts": [\
{\
"id": "YOUR_CONCEPT_ID_3",\
"value": 1\
}\
]\
}\
}\
]\
}\
\
}\
]
}'
Annotate Existing Regions in an Image
When you add an input, detection models (such as Face Detection or General Detection) will detect regions in your image where there appear to be relevant objects. You can get the IDs of these detected regions by listing model's annotations.
Your labels should be contained within Region.data. Each annotation can only have 1 region. If you want to label multiple regions, it is possible to label multiple annotations in a single API call.
Below is an example of how to annotate existing regions in an image.
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- cURL
########################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate
# existing regions in an image. Change these strings to run your own example.
#########################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the existing regions you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"
CONCEPT_ID_3 = "bike"
REGION_ID_1 = "361d6a9253be9152968012660258a4bf"
REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1"
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[\
resources_pb2.Annotation( # label a region in this image\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
regions=[\
resources_pb2.Region(\
id=REGION_ID_1, # this should be a region id returned from list annotations call\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.\
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.\
]\
)\
)\
]\
)\
\
),\
resources_pb2.Annotation( # label another region in this image\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
regions=[\
resources_pb2.Region(\
id=REGION_ID_2 , # this should be a region id returned from list annotations call\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id=CONCEPT_ID_3, value=1.), # 1 means true, this concept is present.\
]\
)\
)\
]\
)\
\
),\
]
),
metadata=metadata
)
```javascript
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// existing regions in an image. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the existing regions you want to annotate
const INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
const CONCEPT_ID_1 = "tree";
const CONCEPT_ID_2 = "water";
const CONCEPT_ID_3 = "bike";
const REGION_ID_1 = "361d6a9253be9152968012660258a4bf";
const REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1";
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [\
{\
"input_id": INPUT_ID,\
"data": {\
"regions": [\
{\
"id": REGION_ID_1,\
"data": {\
"concepts": [\
{\
"id": CONCEPT_ID_1,\
"value": 1\
},\
{\
"id": CONCEPT_ID_2,\
"value": 0\
}\
]\
}\
}\
]\
}\
\
}, {\
"input_id": INPUT_ID,\
"data": {\
"regions": [\
{\
"id": REGION_ID_2,\
"data": {\
"concepts": [\
{\
"id": CONCEPT_ID_3,\
"value": 1\
}\
]\
}\
}\
]\
}\
\
}\
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// existing regions in an image. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [\
{ // label a region in this image\
input_id: INPUT_ID,\
data: {\
regions: [\
{\
id: REGION_ID_1, // this should be a region id returned from list annotations call\
// 1 means true, this concept is present.\
// 0 means false, this concept is not present.\
data: {\
concepts: [\
{ id: CONCEPT_ID_1, value: 1 },\
{ id: CONCEPT_ID_2, value: 0 }\
]\
},\
}\
]\
}\
\
}, { // label another region in this image\
input_id: INPUT_ID,\
data: {\
regions: [\
{\
id: REGION_ID_2, // this should be a region id returned from list annotations call\
// 1 means true, this concept is present.\
// 0 means false, this concept is not present.\
data: {\
concepts: [\
{ id: CONCEPT_ID_3, value: 1 },\
]\
},\
}\
]\
}\
\
}\
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
public class ClarifaiExample {
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the existing regions you want to annotate
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String CONCEPT_ID_1 = "tree";
static final String CONCEPT_ID_2 = "water";
static final String CONCEPT_ID_3 = "bike";
static final String REGION_ID_1 = "361d6a9253be9152968012660258a4bf";
static final String REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1";
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder() // label a region in this image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setId(REGION_ID_1) // this should be a region id returned from list annotations call
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_1)
.setValue(1f) // 1 means true, this concept is present
.build()
).addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_2)
.setValue(0f) // 0 means false, this concept is not present
.build()
)
).build()
).build()
)
.build()
).addAnnotations(
Annotation.newBuilder() // label another region in the same image
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setId(REGION_ID_2) // this should be a region id returned from list annotations call
.setData(
Data.newBuilder().addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID_3)
.setValue(1f) // 1 means true, this concept is present
.build()
)
).build()
).build()
).build()
).build()
);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the existing regions you want to annotate
$INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
$CONCEPT_ID_1 = "tree";
$CONCEPT_ID_2 = "water";
$CONCEPT_ID_3 = "bike";
$REGION_ID_1 = "361d6a9253be9152968012660258a4bf";
$REGION_ID_2 = "dcfa961b753f3b197d0bf7b242718ab1";
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Data;
use Clarifai\Api\Region;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([\
"user_app_id" => $userDataObject,\
"annotations" => [\
new Annotation([ // label a region in this image\
"input_id" => $INPUT_ID,\
"data" => new Data([\
"regions" => [\
new Region([\
"id" => $REGION_ID_1, // this should be a region id returned from list annotations call\
"data" => new Data([\
"concepts" => [\
new Concept([ "id" => $CONCEPT_ID_1, "value" => 1. ]), // 1 means true, this concept is present\
new Concept([ "id" => $CONCEPT_ID_2, "value" => 0. ]), // 0 means false, this concept is not present\
]\
])\
])\
]\
])\
]),\
new Annotation([ // label another region in this image\
"input_id" => $INPUT_ID,\
"data" => new Data([\
"regions" => [\
new Region([\
"id" => $REGION_ID_2, // this should be a region id returned from list annotations call\
"data" => new Data([\
"concepts" => [\
new Concept([ "id" => $CONCEPT_ID_3, "value" => 1. ]), // 1 means true, this concept is present\
]\
])\
])\
]\
])\
])\
]\
]),
$metadata
)->wait();
?>
# Value of 1 means true, this concept is present
# Value of 0 means false, this concept is not present
# Region ID should be the region ID returned from a list annotations call
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [\
{\
"input_id": "YOUR_INPUT_ID_HERE",\
"data": {\
"regions": [\
{\
"id": "REGION_ID_1",\
"data": {\
"concepts": [\
{\
"id": "tree",\
"value": 1\
},\
{\
"id": "water",\
"value": 0\
}\
]\
}\
}\
]\
}\
}, {\
"input_id": "YOUR_INPUT_ID_HERE",\
"data": {\
"regions": [\
{\
"id": "REGION_ID_2",\
"data": {\
"concepts": [\
{\
"id": "bike",\
"value": 1\
}\
]\
}\
}\
]\
}\
}\
]
}'
Annotate Images With Mask
Below is an example of how to add a mask to an Image using a single API call. In this example, we provide an image mask as a base64 string.
Click here to learn more about image mask annotations.
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- cURL
#########################################################################################
# In this section, we set the user authentication, app ID, and how we want to create an
# image mask. Change these strings to run your own example.
#########################################################################################
# Your user and app ID
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the new bounding boxes you want to annotate
INPUT_ID = "INPUT_ID_FROM_UI"
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
# The userDataObject is created in the overview and is required when using a PAT
user_app_id=userDataObject,
annotations=[\
resources_pb2.Annotation(\
input_id=INPUT_ID,\
data=resources_pb2.Data(\
regions=[\
resources_pb2.Region(\
region_info=resources_pb2.RegionInfo(\
mask=resources_pb2.Mask(\
image=resources_pb2.Image(\
base64=b"iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTAXQ04cStqCnkqWmdlIacNRczTbPRnFMW49ALeWoapqVNx49GTSHPhwWrpJTf1BTy3E2TpDTu4N2oKeSpaY+UjnDkdNQU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),\
)\
),\
data=resources_pb2.Data(\
concepts=[\
resources_pb2.Concept(id="CONCEPT_ID_FROM_UI", value=1), # 1 means true, this concept is present\
]\
)\
)\
]\
)\
\
)\
]
),
metadata=metadata
)
```javascript
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these based on the input you want to annotate
const INPUT_ID = 'INPUT_ID_FROM_UI';
const CONCEPT_ID = 'CONCEPT_ID_FROM_UI';
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [\
{\
"input_id": INPUT_ID,\
"data": {\
"regions": [\
{\
"region_info": {\
"mask": {\
"image": {\
"base64":"iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTAXQ04cStqCnkqWmdlIacNRczTbPRnFMW49ALeWoapqVN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MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg=="\
}\
}\
},\
"data": {\
"concepts": [\
{\
"id": CONCEPT_ID,\
"value": 1 // 1 means true, this concept is present\
}\
]\
}\
}\
]\
}\
}\
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT,
'Content-Type': 'application/json'
},
body: raw
};
</script>
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
annotations: [\
{\
input_id: INPUT_ID,\
data: {\
regions: [\
{\
region_info: {\
mask: {\
image: {\
base64:"iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTAXQ04cStqCnkqWmdlIacNRczTbPRnFMW49ALeW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9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg=="\
}\
}\
},\
data: {\
concepts: [\
{\
id: CONCEPT_ID,\
value: 1 // 1 means true, this concept is present\
}\
]\
}\
}\
]\
}\
}\
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
console.log("Post annotations succeeded");
}
);
package com.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.ByteString;
public class annotate_mask {
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to
////////////////////////////////////////////////////////////////////////////////////////// annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the portal under
// Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the input you want to annotate
static final String INPUT_ID = "INPUT_ID_FROM_UI";
static final String CONCEPT_ID = "CONCEPT_ID_FROM_UI";
static final String myString = "iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9x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W9zveJFdQU8m7xlE6H9hbfAV6jppDnWf7YlhH23xngyhx6Ic9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg==";
static final ByteString byteString = ByteString.copyFrom(myString.getBytes());
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setData(
Data.newBuilder().addRegions(
Region.newBuilder()
.setRegionInfo(
RegionInfo.newBuilder()
.setMask( // draw a mask
Mask.newBuilder()
.setImage(
Image.newBuilder()
.setBase64(
byteString)
.build())
.build())
.build())
.setData(
Data.newBuilder()
.addConcepts(
Concept.newBuilder()
.setId(CONCEPT_ID)
.setValue(1f) // 1 means
// true,
// this
// concept
// is
// present
.build()))
.build())
.build())
.build())
.build());
System.out.println("Post annotations succeeded");
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
require 'vendor/autoload.php';
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and how we want to annotate
// an image mask. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these based on the input you want to annotate
$INPUT_ID = "INPUT_ID_FROM_UI";
$CONCEPT_ID = "CONCEPT_ID_FROM_UI";
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Concept;
use Clarifai\Api\Image;
use Clarifai\Api\Data;
use Clarifai\Api\Mask;
use Clarifai\Api\Region;
use Clarifai\Api\RegionInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
// Create an instance of Clarifai\Api\Mask
$mask = new Mask([\
"image" => new Image([\
"base64" => "iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTAXQ04cStqCnkqWmdlIacNRczTbPRnFMW49ALeWoapqVNx49GTSHPhwWrpJTf1BTy3E2TpDTu4N2oKeSpaY+UjnDkdNQU8swU8hx6Y5x4BzlsPWoKeWpaIqXjHDMgNYU8HxbMkFIeUVPIczdtkNK5DtiQmkKemgZI6XR7z0hNIc+b3rNJKd9y6D2VjV7Grkty6IU8h17Yws89g6qmkKem53ExZSE1hTxves+ipRe015zUFPLU9BRSelm7LEpNIU9Njyel17fxrsz0YDZ6F1tOy6EX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d1OGu/zFVE1hAjVlsjukVE1hAjOFPIde5rrJkVdNYQA1ZajbpFRNYQIzhTwzhTx3Uya608VUTWECNWWcm6VUTWECM4U8h15mud+JV01hAjOFPDOFPHdTBrnlxVRNYQIzhTwzhTwzhTwzhTxvepnirq951RQmMFPIM1PIM1PIM1PIM1PI8wMZRrjxT2PUFCYwU8gzU8gzU8gzU8gzU8jzAxn67v3TGDWFCcwU8swU8txNibv9xVRNYQIzhTwzhTx3U8pcTH9RU8gzU8hz6CXLifcfagp5akqTlP6LmkKemlKkpX9QU8hTU3Kk9G9qCnlqSouUfsJMCbHRzzn0Qp6aUiGlD6kp5Kkp59PRb6gp5KkpJ5PS76kp5Kkpp9HRpdQU8tSUE+joc8yUY1noCg69kKemHEVHV1NTyFNTdiair1NTyFNTdqCg21JTyFNTNqSi+1BTyFNTNqGje/rvf92fZ38RTGag+3Pohby/H4XKymI6ehQ1hbwvHojCyqdE9HBqCnkLn4zKio6eR00hb93zUVxvRELPp6aQt8WjUluvSERDtv5mmOxw1lnk0At5uz08ZXUWFS1TU8jb/SGqqmkiOoKaQt6hT1NlDdHRQdQU8k57pirrCRR0KDWFvMLzVVh3VfgW85rg99BqNxH8zrKWQy/k9Z+54rpQ/1vJWmoKeTMfwQr7y8xvHs9TU8i7zgP52oW9zveJFdQU8m7xlE6H9hbfAV6jppDnWf7YlhH23xngyhx6Ic9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIc9MIe8/AQAA//+1OJOq3RUbswAAAABJRU5ErkJggg=="\
])\
]);
// Define the annotation with the mask
$annotation = new Annotation([\
"input_id" => $INPUT_ID,\
"data" => new Data([\
"regions" => [\
new Region([\
"region_info" => new RegionInfo([\
"mask" => $mask\
]),\
"data" => new Data([\
"concepts" => [\
new Concept([\
"id" => $CONCEPT_ID,\
"value" => 1.0 // 1 means true, this concept is present\
])\
]\
])\
])\
]\
])\
]);
// Let's make a RPC call to the Clarifai platform
[$response, $status] = $client->PostAnnotations(
new PostAnnotationsRequest([\
"user_app_id" => $userDataObject,\
"annotations" => [$annotation]\
]),
$metadata
)->wait();
// Check the status of the response
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
echo "Post annotations succeeded";
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [\
{\
"input_id": "INPUT_ID_FROM_UI",\
"data": {\
"regions": [\
{\
"region_info": {\
"mask": {\
"image": {\
"base64": "iVBORw0KGgoAAAANSUhEUgAAA6YAAAJLCAAAAADRRNTfAAAK8ElEQVR4nOzd227cVrpG0a0Nv/8ru9FWx4gtlcRi8TB/cozLIBdC5I9zLaoi////AXFmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnlmCnk/zv4CuJyfZ38Bb2d/AZtTU8i73oOHVU5P4G6u8EdcTSHvCo8annbddn5t6h93NYW8qY8XnnPXfD4y7M+9mkLesKcKi+nnIjMGMOOrZDHrXCG/AodeyMs/R1hKR18U3oKaQl74CcJSOrqh5CLUFPKSzw4WE9J9xHahppAXe2rwDCndWWYdagp5mecFz9DRozQG0vgqeIaNHiuwEYdeyAs8KXiGlJ7h7JmoKeT5Pb2TSOlNqSnknX3oZjEpPdO5Q1FTyFPTAXQ04cStqCnkqWmdlIacNRczTbPRnFMW49ALeWoapqVNx49GTSHPhwWrpJTf1BTy3E2TpDTu4N2oKeSpaY+UjnDkdNQU8swU8hx6Y5x4BzlsPWoKeWpaIqXj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CONCEPT_ID_FROM_UI",\
"value": 1\
}\
]\
}\
}\
]\
}\
}\
]
}'
Annotate Images With Different user_id and status
Each annotation is tied to a user or a model in your workflow. By default, when a user posts an annotation, this user is the owner of the annotation.
Sometimes, however, you might want to post an annotation as another user; for example, when assigning an image to another user. In such a case, you can create an annotation with another user_id (and status PENDING).
note
Only the app owner can post an annotation with other user's user_id; collaborators cannot.
Below is an example of how to annotate images with different user_id and status.
- Python (gRPC)
- JavaScript (REST)
- Node.js (gRPC)
- Java (gRPC)
- PHP (gRPC)
- cURL
#########################################################################
# In this section, we set the user authentication, app ID, input ID,
# and another user ID. Change these strings to run your own example.
#########################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to post your own annotations
INPUT_ID = 'e838fac8da9d40c89f2291a6496593da'
ANOTHER_USER_ID = 'ANOTHER_USER_ID_HERE'
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is created in the overview and is required when using a PAT
post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject,
annotations=[\
resources_pb2.Annotation(\
input_id=INPUT_ID,\
user_id=ANOTHER_USER_ID, # If empty, it is the user who posts this annotation\
status=status_pb2.Status(\
code=status_code_pb2.ANNOTATION_PENDING # annotation pending status. By default success.\
),\
)\
]
),
metadata=metadata
)
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and another user ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to post your own annotations
const INPUT_ID = 'c9cbb1c90cf24bc98bfd2e529e744ca9';
const ANOTHER_USER_ID = 'ANOTHER_USER_ID_HERE';
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"annotations": [\
{\
"input_id": INPUT_ID,\
"user_id": ANOTHER_USER_ID,\
"status": {\
"code": "ANNOTATION_PENDING"\
}\
}\
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and another user ID. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostAnnotations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
annotations: [\
{\
input_id: INPUT_ID,\
user_id: ANOTHER_USER_ID, // If empty, it is the user who posts this annotation\
status: {\
code: 24151 // annotation pending status. By default success.\
}\
}\
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post annotations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.Status;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, input ID,
// and another user ID. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to post your own annotations
static final String INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
static final String ANOTHER_USER_ID = "ANOTHER_USER_ID_HERE";
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
PostAnnotationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addAnnotations(
Annotation.newBuilder()
.setInputId(INPUT_ID)
.setUserId(ANOTHER_USER_ID) // If empty, it is the user who posts this annotation
.setStatus(
Status.newBuilder()
.setCodeValue(StatusCode.ANNOTATION_PENDING_VALUE) // annotation pending status. By default, it's ANNOTATION_SUCCESS_VALUE
.build()
)
.build()
).build()
);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to post your own annotations
$INPUT_ID = "c9cbb1c90cf24bc98bfd2e529e744ca9";
$ANOTHER_USER_ID = "ANOTHER_USER_ID_HERE";
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostAnnotationsRequest;
use Clarifai\Api\Annotation;
use Clarifai\Api\Status\Status;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([\
"user_id" => $USER_ID,\
"app_id" => $APP_ID\
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostAnnotations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostAnnotationsRequest([\
"user_app_id" => $userDataObject,\
"annotations" => [\
new Annotation([\
"input_id" => $INPUT_ID,\
"user_id" => $ANOTHER_USER_ID, // If empty, it is the user who posts this annotation\
"status" => new Status([\
"code" => StatusCode::ANNOTATION_PENDING // Annotation pending status. By default success\
])\
])\
]\
]),
$metadata
)->wait();
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/annotations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"annotations": [\
{\
"input_id": "YOUR_INPUT_ID_HERE",\
"user_id": "ANOTHER_USER_ID_HERE",\
"status": {\
"code": "ANNOTATION_PENDING"\
}\
}\
]
}'
- Annotate Images With Concepts
- Annotate Images With Multiple Concepts
- Annotate New Bounding Boxes in an Image
- Annotate Polygons in an Image
- Annotate Existing Regions in an Image
- Annotate Images With Mask
- Annotate Images With Different
user_idandstatus
Build your next AI app, test and tune popular LLMs models, and much more.