Prediction Parameters
Learn about model prediction parameters.
You can set additional parameters to gain flexibility in the predict operation.

Select Concepts

By putting this additional parameter on your predict calls, you can receive predict value(s) for only the concepts that you want to. You can specify particular concepts by either their id and/or their name. The concept names and ids are case sensitive, and so, these must be exact matches.
To retrieve an entire list of concepts from a given model use the GET /v2/models/{model_id}/output_info endpoint. Check out the Advanced Models section for how to use with any of the API clients!
If you submit a request with not an exact match of the concept id or name, you will receive an invalid model argument error. However, if one or more matches while one or more do not, the API will respond with a Mixed Success.
Python
PHP
Java
NodeJS
Python
cURL
Javascript (REST)
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_model_outputs_response = stub.PostModelOutputs(
5
service_pb2.PostModelOutputsRequest(
6
model_id="aaa03c23b3724a16a56b629203edc62c", # This is model ID of the clarifai/main General model.
7
inputs=[
8
resources_pb2.Input(
9
data=resources_pb2.Data(
10
image=resources_pb2.Image(
11
url="https://samples.clarifai.com/metro-north.jpg"
12
)
13
)
14
)
15
],
16
model=resources_pb2.Model(
17
output_info=resources_pb2.OutputInfo(
18
output_config=resources_pb2.OutputConfig(
19
select_concepts=[
20
# When selecting concepts, value is ignored, so no need to specify it.
21
resources_pb2.Concept(name="train"),
22
resources_pb2.Concept(id="ai_6kTjGfF6")
23
]
24
)
25
)
26
)
27
),
28
metadata=metadata
29
)
30
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
31
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)
32
33
# Since we have one input, one output will exist here.
34
output = post_model_outputs_response.outputs[0]
35
36
print("Predicted concepts:")
37
for concept in output.data.concepts:
38
print("%s %.2f" % (concept.name, concept.value))
Copied!
1
<?php
2
# Insert here the initialization code as outlined on this page:
3
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
4
5
///////////////////////////////////////////////////////////////////////////////
6
// Specifying the Request Data
7
///////////////////////////////////////////////////////////////////////////////
8
//
9
// In the Clarifai platform an image is defined by a special Image object.
10
// There are several ways in which an Image object can be populated including
11
// by url and image bytes (base64).
12
//
13
$image = new Image([
14
'url' => 'https://samples.clarifai.com/dog2.jpeg'
15
]);
16
17
//
18
// After an Image object is created, a Data object is constructed around it.
19
// The Data object offers a container that contains additional image independent
20
// metadata. In this particular use case, no other metadata is needed to be
21
// specified.
22
//
23
$data = new Data([
24
'image' => $image
25
]);
26
27
//
28
// The Data object is then wrapped in an Input object in order to meet the
29
// API specification. Additional fields are available to populate in the Input
30
// object, but for the purposes of this example we can send in just the
31
// Data object.
32
//
33
$input = new Input([
34
'data' => $data
35
]);
36
37
///////////////////////////////////////////////////////////////////////////////
38
// Specifying Output Configuration
39
///////////////////////////////////////////////////////////////////////////////
40
//
41
// Output configuration can be specified by the OutputConfig object. Here
42
// we specify a concept by both the name and the id for what we want to narrow
43
// down to in the results.
44
//
45
$outputConfig = new OutputConfig([
46
'select_concepts' => [
47
new Concept(['name' => 'train']),
48
new Concept(['id' => 'ai_6kTjGfF6'])
49
]
50
])
51
52
//
53
// The OutputInfo object is a wrapper around the OutputConfig object
54
//
55
$outputInfo = new OutputInfo([
56
'output_config' => $outputConfig
57
])
58
59
//
60
// The model object is a wrapper around the OutputInfo object. This is the
61
// final part needed to define an output configuration.
62
//
63
$model = new Model([
64
'output_info' => $outputInfo
65
]);
66
67
///////////////////////////////////////////////////////////////////////////////
68
// Creating the request object
69
///////////////////////////////////////////////////////////////////////////////
70
//
71
// Finally, the request object itself is created. This object carries the request
72
// along with the request status and other metadata related to the request itself.
73
// In this example we populate:
74
// - the `user_app_id` field with the UserAppIDSet constructed above
75
// - the `model_id` field with the ID of the model we are referencing
76
// - the `inputs` field with an array of input objects constructed above
77
// - the `model` field with the output configuration specified above
78
//
79
$request = new PostModelOutputsRequest([
80
'user_app_id' => $userDataObject, // This is defined above
81
'model_id' => 'aaa03c23b3724a16a56b629203edc62c', // This is the ID of the publicly available General model.
82
'inputs' => [$input],
83
'model' => $model
84
]);
85
86
///////////////////////////////////////////////////////////////////////////////
87
// Making the RPC Call
88
///////////////////////////////////////////////////////////////////////////////
89
//
90
// Once the request object is constructed, we can call the actual request to the
91
// Clarifai platform. This uses the opened gRPC client channel to communicate the
92
// request and then wait for the response.
93
//
94
[$response, $status] = $client->PostModelOutputs(
95
$request,
96
$metadata
97
)->wait();
98
99
///////////////////////////////////////////////////////////////////////////////
100
// Handling the Response
101
///////////////////////////////////////////////////////////////////////////////
102
//
103
// The response is returned and the first thing we do is check the status of it.
104
// A successful response will have a status code of 0, otherwise there is some
105
// reported error.
106
//
107
if ($status->code !== 0) throw new Exception("Error: {$status->details}");
108
109
//
110
// In addition to the RPC response status, there is a Clarifai API status that
111
// reports if the operationo was a success or failure (not just that the commuunication)
112
// was successful.
113
//
114
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
115
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " .
116
$response->getStatus()->getDetails());
117
}
118
119
//
120
// The output of a successful call can be used in many ways. In this example,
121
// we loop through all of the predicted concepts and print them out along with
122
// their numerical prediction value (confidence).
123
//
124
echo "Predicted concepts:\n";
125
foreach ($response->getOutputs()[0]->getData()->getConcepts() as $concept) {
126
echo $concept->getName() . ": " . number_format($concept->getValue(), 2) . "\n";
127
}
128
?>
Copied!
1
import com.clarifai.grpc.api.*;
2
import com.clarifai.grpc.api.status.StatusCode;
3
4
// Insert here the initialization code as outlined on this page:
5
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
6
7
MultiOutputResponse postModelOutputsResponse = stub.postModelOutputs(
8
PostModelOutputsRequest.newBuilder()
9
.setModelId("aaa03c23b3724a16a56b629203edc62c") // This is model ID of the clarifai/main General model.
10
.addInputs(
11
Input.newBuilder().setData(
12
Data.newBuilder().setImage(
13
Image.newBuilder().setUrl("https://samples.clarifai.com/metro-north.jpg")
14
)
15
)
16
)
17
.setModel(
18
Model.newBuilder().setOutputInfo(
19
OutputInfo.newBuilder().setOutputConfig(
20
OutputConfig.newBuilder()
21
// When selecting concepts, value is ignored, so no need to specify it.
22
.addSelectConcepts(Concept.newBuilder().setName("train"))
23
.addSelectConcepts(Concept.newBuilder().setId("ai_6kTjGfF6")
24
)
25
)
26
)
27
)
28
.build()
29
);
30
31
if (postModelOutputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
32
throw new RuntimeException("Post model outputs failed, status: " + postModelOutputsResponse.getStatus());
33
}
34
35
// Since we have one input, one output will exist here.
36
Output output = postModelOutputsResponse.getOutputs(0);
37
38
System.out.println("Predicted concepts:");
39
for (Concept concept : output.getData().getConceptsList()) {
40
System.out.printf("%s %.2f%n", concept.getName(), concept.getValue());
41
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
stub.PostModelOutputs(
5
{
6
model_id: "aaa03c23b3724a16a56b629203edc62c", // This is model ID of the clarifai/main General model.
7
inputs: [
8
{data: {image: {url: "https://samples.clarifai.com/metro-north.jpg"}}}
9
],
10
// When selecting concepts, value is ignored, so no need to specify it.
11
model: {output_info: {output_config: {select_concepts: [{name: "train"}, {id: "ai_6kTjGfF6"}]}}}
12
},
13
metadata,
14
(err, response) => {
15
if (err) {
16
throw new Error(err);
17
}
18
19
if (response.status.code !== 10000) {
20
throw new Error("Post model outputs failed, status: " + response.status.description);
21
}
22
23
// Since we have one input, one output will exist here.
24
const output = response.outputs[0];
25
26
console.log("Predicted concepts:");
27
for (const concept of output.data.concepts) {
28
console.log(concept.name + " " + concept.value);
29
}
30
}
31
);
Copied!
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_model_outputs_response = stub.PostModelOutputs(
5
service_pb2.PostModelOutputsRequest(
6
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
7
model_id="aaa03c23b3724a16a56b629203edc62c", # This is model ID of the clarifai/main General model.
8
inputs=[
9
resources_pb2.Input(
10
data=resources_pb2.Data(
11
image=resources_pb2.Image(
12
url="https://samples.clarifai.com/metro-north.jpg"
13
)
14
)
15
)
16
],
17
model=resources_pb2.Model(
18
output_info=resources_pb2.OutputInfo(
19
output_config=resources_pb2.OutputConfig(
20
select_concepts=[
21
# When selecting concepts, value is ignored, so no need to specify it.
22
resources_pb2.Concept(name="train"),
23
resources_pb2.Concept(id="ai_6kTjGfF6")
24
]
25
)
26
)
27
)
28
),
29
metadata=metadata
30
)
31
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
32
print("There was an error with your request!")
33
print("\tCode: {}".format(post_model_outputs_response.outputs[0].status.code))
34
print("\tDescription: {}".format(post_model_outputs_response.outputs[0].status.description))
35
print("\tDetails: {}".format(respopost_model_outputs_responsense.outputs[0].status.details))
36
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)
37
38
# Since we have one input, one output will exist here.
39
output = post_model_outputs_response.outputs[0]
40
41
print("Predicted concepts:")
42
for concept in output.data.concepts:
43
print("%s %.2f" % (concept.name, concept.value))
Copied!
1
curl -X POST \
2
-H 'authorization: Key YOUR_API_KEY' \
3
-H 'content -type: application/json' \
4
-d '{
5
"inputs": [
6
{
7
"data": {
8
"image": {
9
"url": "https://samples.clarifai.com/metro-north.jpg"
10
}
11
}
12
}
13
],
14
"model": {
15
"output_info": {
16
"output_config": {
17
"select_concepts": [
18
{"name": "train"},
19
{"id": "ai_6kTjGfF6"}
20
]
21
}
22
}
23
}
24
}'\
25
https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs
26
27
# Above is model ID of the publicly available General model.
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"inputs": [
7
{
8
"data": {
9
"image": {
10
"url": "https://samples.clarifai.com/metro-north.jpg"
11
}
12
}
13
}
14
],
15
"model": {
16
"output_info": {
17
"output_config": {
18
"select_concepts": [
19
{"name": "train"},
20
{"id": "ai_6kTjGfF6"}
21
]
22
}
23
}
24
}
25
});
26
27
const requestOptions = {
28
method: 'POST',
29
headers: {
30
'Accept': 'application/json',
31
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
32
},
33
body: raw
34
};
35
36
fetch("https://api.clarifai.com/v2/models/{YOUR_MODEL_ID}/outputs", requestOptions)
37
.then(response => response.text())
38
.then(result => console.log(result))
39
.catch(error => console.log('error', error));
Copied!
Response JSON
1
{
2
"status": {
3
"code": 10000,
4
"description": "Ok"
5
},
6
"outputs": [
7
{
8
"id": "c8abf5cbe52746efa9df8a2319d49d0a",
9
"status": {
10
"code": 10000,
11
"description": "Ok"
12
},
13
"created_at": "2017-06-27T13:31:57.493797045Z",
14
"model": {
15
"id": "aaa03c23b3724a16a56b629203edc62c",
16
"name": "general-v1.3",
17
"created_at": "2016-03-09T17:11:39.608845Z",
18
"app_id": "main",
19
"output_info": {
20
"message": "Show output_info with: GET /models/{model_id}/output_info",
21
"type": "concept",
22
"type_ext": "concept"
23
},
24
"model_version": {
25
"id": "aa9ca48295b37401f8af92ad1af0d91d",
26
"created_at": "2016-07-13T01:19:12.147644Z",
27
"status": {
28
"code": 21100,
29
"description": "Model trained successfully"
30
}
31
}
32
},
33
"input": {
34
"id": "c613b3254da34382b2fca65365da7c49",
35
"data": {
36
"image": {
37
"url": "https://samples.clarifai.com/metro-north.jpg"
38
}
39
}
40
},
41
"data": {
42
"concepts": [
43
{
44
"id": "ai_HLmqFqBf",
45
"name": "train",
46
"value": 0.9989112,
47
"app_id": "main"
48
},
49
{
50
"id": "ai_6kTjGfF6",
51
"name": "station",
52
"value": 0.992573,
53
"app_id": "main"
54
}
55
]
56
}
57
}
58
]
59
}
Copied!

Maximum Concepts

Setting the max concepts parameter will customize how many concepts and their corresponding probability scores the predict endpoint will return. If not specified, the predict endpoint will return the top 20 concepts. You can currently set the max concepts parameter to any number in the range: [1-200]. If your use case requires more concepts, please contact Support.
Python
PHP
Java
NodeJS
Python
cURL
Javascript (REST)
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_model_outputs_response = stub.PostModelOutputs(
5
service_pb2.PostModelOutputsRequest(
6
model_id="aaa03c23b3724a16a56b629203edc62c", # This is model ID of the clarifai/main General model.
7
inputs=[
8
resources_pb2.Input(
9
data=resources_pb2.Data(
10
image=resources_pb2.Image(
11
url="https://samples.clarifai.com/metro-north.jpg"
12
)
13
)
14
)
15
],
16
model=resources_pb2.Model(
17
output_info=resources_pb2.OutputInfo(
18
output_config=resources_pb2.OutputConfig(
19
max_concepts=3
20
)
21
)
22
)
23
),
24
metadata=metadata
25
)
26
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
27
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)
28
29
# Since we have one input, one output will exist here.
30
output = post_model_outputs_response.outputs[0]
31
32
print("Predicted concepts:")
33
for concept in output.data.concepts:
34
print("%s %.2f" % (concept.name, concept.value))
Copied!
1
<?php
2
# Insert here the initialization code as outlined on this page:
3
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
4
5
///////////////////////////////////////////////////////////////////////////////
6
// Specifying the Request Data
7
///////////////////////////////////////////////////////////////////////////////
8
//
9
// In the Clarifai platform an image is defined by a special Image object.
10
// There are several ways in which an Image object can be populated including
11
// by url and image bytes (base64).
12
//
13
$image = new Image([
14
'url' => 'https://samples.clarifai.com/dog2.jpeg'
15
]);
16
17
//
18
// After an Image object is created, a Data object is constructed around it.
19
// The Data object offers a container that contains additional image independent
20
// metadata. In this particular use case, no other metadata is needed to be
21
// specified.
22
//
23
$data = new Data([
24
'image' => $image
25
]);
26
27
//
28
// The Data object is then wrapped in an Input object in order to meet the
29
// API specification. Additional fields are available to populate in the Input
30
// object, but for the purposes of this example we can send in just the
31
// Data object.
32
//
33
$input = new Input([
34
'data' => $data
35
]);
36
37
///////////////////////////////////////////////////////////////////////////////
38
// Specifying Output Configuration
39
///////////////////////////////////////////////////////////////////////////////
40
//
41
// Output configuration can be specified by the OutputConfig object. Here
42
// we specify the max number of concepts to return at 3.
43
//
44
$outputConfig = new OutputConfig([
45
'max_concepts' => 3
46
])
47
48
//
49
// The OutputInfo object is a wrapper around the OutputConfig object
50
//
51
$outputInfo = new OutputInfo([
52
'output_config' => $outputConfig
53
])
54
55
//
56
// The model object is a wrapper around the OutputInfo object. This is the
57
// final part needed to define an output configuration.
58
//
59
$model = new Model([
60
'output_info' => $outputInfo
61
]);
62
63
///////////////////////////////////////////////////////////////////////////////
64
// Creating the request object
65
///////////////////////////////////////////////////////////////////////////////
66
//
67
// Finally, the request object itself is created. This object carries the request
68
// along with the request status and other metadata related to the request itself.
69
// In this example we populate:
70
// - the `user_app_id` field with the UserAppIDSet constructed above
71
// - the `model_id` field with the ID of the model we are referencing
72
// - the `inputs` field with an array of input objects constructed above
73
// - the `model` field with the output configuration specified above
74
//
75
$request = new PostModelOutputsRequest([
76
'user_app_id' => $userDataObject, // This is defined above
77
'model_id' => 'aaa03c23b3724a16a56b629203edc62c', // This is the ID of the publicly available General model.
78
'inputs' => [$input],
79
'model' => $model
80
]);
81
82
///////////////////////////////////////////////////////////////////////////////
83
// Making the RPC Call
84
///////////////////////////////////////////////////////////////////////////////
85
//
86
// Once the request object is constructed, we can call the actual request to the
87
// Clarifai platform. This uses the opened gRPC client channel to communicate the
88
// request and then wait for the response.
89
//
90
[$response, $status] = $client->PostModelOutputs(
91
$request,
92
$metadata
93
)->wait();
94
95
///////////////////////////////////////////////////////////////////////////////
96
// Handling the Response
97
///////////////////////////////////////////////////////////////////////////////
98
//
99
// The response is returned and the first thing we do is check the status of it.
100
// A successful response will have a status code of 0, otherwise there is some
101
// reported error.
102
//
103
if ($status->code !== 0) throw new Exception("Error: {$status->details}");
104
105
//
106
// In addition to the RPC response status, there is a Clarifai API status that
107
// reports if the operationo was a success or failure (not just that the commuunication)
108
// was successful.
109
//
110
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
111
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " .
112
$response->getStatus()->getDetails());
113
}
114
115
//
116
// The output of a successful call can be used in many ways. In this example,
117
// we loop through all of the predicted concepts and print them out along with
118
// their numerical prediction value (confidence).
119
//
120
echo "Predicted concepts:\n";
121
foreach ($response->getOutputs()[0]->getData()->getConcepts() as $concept) {
122
echo $concept->getName() . ": " . number_format($concept->getValue(), 2) . "\n";
123
}
124
?>
Copied!
1
import com.clarifai.grpc.api.*;
2
import com.clarifai.grpc.api.status.*;
3
4
// Insert here the initialization code as outlined on this page:
5
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
6
7
MultiOutputResponse postModelOutputsResponse = stub.postModelOutputs(
8
PostModelOutputsRequest.newBuilder()
9
.setModelId("aaa03c23b3724a16a56b629203edc62c") // This is model ID of the clarifai/main General model.
10
.addInputs(
11
Input.newBuilder().setData(
12
Data.newBuilder().setImage(
13
Image.newBuilder().setUrl("https://samples.clarifai.com/metro-north.jpg")
14
)
15
)
16
)
17
.setModel(
18
Model.newBuilder().setOutputInfo(
19
OutputInfo.newBuilder().setOutputConfig(
20
OutputConfig.newBuilder().setMaxConcepts(3)
21
)
22
)
23
)
24
.build()
25
);
26
27
if (postModelOutputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
28
throw new RuntimeException("Post model outputs failed, status: " + postModelOutputsResponse.getStatus());
29
}
30
31
// Since we have one input, one output will exist here.
32
Output output = postModelOutputsResponse.getOutputs(0);
33
34
System.out.println("Predicted concepts:");
35
for (Concept concept : output.getData().getConceptsList()) {
36
System.out.printf("%s %.2f%n", concept.getName(), concept.getValue());
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
stub.PostModelOutputs(
5
{
6
model_id: "aaa03c23b3724a16a56b629203edc62c", // This is model ID of the clarifai/main General model
7
inputs: [
8
{data: {image: {url: "https://samples.clarifai.com/metro-north.jpg"}}}
9
],
10
model: {output_info: {output_config: {max_concepts: 3}}}
11
},
12
metadata,
13
(err, response) => {
14
if (err) {
15
throw new Error(err);
16
}
17
18
if (response.status.code !== 10000) {
19
throw new Error("Post model outputs failed, status: " + response.status.description);
20
}
21
22
// Since we have one input, one output will exist here.
23
const output = response.outputs[0];
24
25
console.log("Predicted concepts:");
26
for (const concept of output.data.concepts) {
27
console.log(concept.name + " " + concept.value);
28
}
29
}
30
);
Copied!
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_model_outputs_response = stub.PostModelOutputs(
5
service_pb2.PostModelOutputsRequest(
6
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
7
model_id="aaa03c23b3724a16a56b629203edc62c", # This is model ID of the clarifai/main General model.
8
inputs=[
9
resources_pb2.Input(
10
data=resources_pb2.Data(
11
image=resources_pb2.Image(
12
url="https://samples.clarifai.com/metro-north.jpg"
13
)
14
)
15
)
16
],
17
model=resources_pb2.Model(
18
output_info=resources_pb2.OutputInfo(
19
output_config=resources_pb2.OutputConfig(
20
max_concepts=3
21
)
22
)
23
)
24
),
25
metadata=metadata
26
)
27
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
28
print("There was an error with your request!")
29
print("\tCode: {}".format(post_model_outputs_response.outputs[0].status.code))
30
print("\tDescription: {}".format(post_model_outputs_response.outputs[0].status.description))
31
print("\tDetails: {}".format(respopost_model_outputs_responsense.outputs[0].status.details))
32
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)
33
34
# Since we have one input, one output will exist here.
35
output = post_model_outputs_response.outputs[0]
36
37
print("Predicted concepts:")
38
for concept in output.data.concepts:
39
print("%s %.2f" % (concept.name, concept.value))
Copied!
1
curl -X POST \
2
-H "Authorization: Key YOUR_API_KEY" \
3
-H "Content-Type: application/json" \
4
-d '
5
{
6
"inputs": [
7
{
8
"data": {
9
"image": {
10
"url": "https://samples.clarifai.com/metro-north.jpg"
11
}
12
}
13
}
14
],
15
"model":{
16
"output_info":{
17
"output_config":{
18
"max_concepts": 3
19
}
20
}
21
}
22
}'\
23
https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"inputs": [
7
{
8
"data": {
9
"image": {
10
"url": "https://samples.clarifai.com/metro-north.jpg"
11
}
12
}
13
}
14
],
15
"model":{
16
"output_info":{
17
"output_config":{
18
"max_concepts": 3
19
}
20
}
21
}
22
});
23
24
const requestOptions = {
25
method: 'POST',
26
headers: {
27
'Accept': 'application/json',
28
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
29
},
30
body: raw
31
};
32
33
fetch("https://api.clarifai.com/v2/models/{YOUR_MODEL_ID}/outputs", requestOptions)
34
.then(response => response.text())
35
.then(result => console.log(result))
36
.catch(error => console.log('error', error));
Copied!
Response JSON
1
{
2
"status": {
3
"code": 10000,
4
"description": "Ok"
5
},
6
"outputs": [
7
{
8
"id": "c8c400234b0d47df9084857df0d69efb",
9
"status": {
10
"code": 10000,
11
"description": "Ok"
12
},
13
"created_at": "2017-06-15T16:09:48.984389535Z",
14
"model": {
15
"id": "aaa03c23b3724a16a56b629203edc62c",
16
"name": "general-v1.3",
17
"created_at": "2016-02-26T23:38:40.086101Z",
18
"app_id": "main",
19
"output_info": {
20
"message": "Show output_info with: GET /models/{model_id}/output_info",
21
"type": "concept",
22
"type_ext": "concept"
23
},
24
"model_version": {
25
"id": "aa9ca48295b37401f8af92ad1af0d91d",
26
"created_at": "2016-07-13T00:58:55.915745Z",
27
"status": {
28
"code": 21100,
29
"description": "Model trained successfully"
30
}
31
}
32
},
33
"input": {
34
"id": "fd99d9e345f3495a8bd2802151d09efa",
35
"data": {
36
"image": {
37
"url": "https://samples.clarifai.com/metro-north.jpg"
38
}
39
}
40
},
41
"data": {
42
"concepts": [
43
{
44
"id": "ai_HLmqFqBf",
45
"name": "train",
46
"value": 0.9989112,
47
"app_id": "main"
48
},
49
{
50
"id": "ai_fvlBqXZR",
51
"name": "railway",
52
"value": 0.9975532,
53
"app_id": "main"
54
},
55
{
56
"id": "ai_Xxjc3MhT",
57
"name": "transportation system",
58
"value": 0.9959158,
59
"app_id": "main"
60
}
61
]
62
}
63
}
64
]
65
}
Copied!

Minimum Prediction Value

This parameter lets you set a minimum probability threshold for the outputs you want to view for the Predict operation. For example if you want to see all concepts with a probability score of .90 or higher, this parameter will allow you to accomplish that. Also note that if you don't specify the number of max concepts, you will only see the top 20. If your result can contain more values you will have to increase the number of maximum concepts as well.
Python
PHP
Java
NodeJS
Python
cURL
Javascript (REST)
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_model_outputs_response = stub.PostModelOutputs(
5
service_pb2.PostModelOutputsRequest(
6
model_id="aaa03c23b3724a16a56b629203edc62c", # This is model ID of the clarifai/main General model.
7
inputs=[
8
resources_pb2.Input(
9
data=resources_pb2.Data(
10
image=resources_pb2.Image(
11
url="https://samples.clarifai.com/metro-north.jpg"
12
)
13
)
14
)
15
],
16
model=resources_pb2.Model(
17
output_info=resources_pb2.OutputInfo(
18
output_config=resources_pb2.OutputConfig(
19
min_value=0.95
20
)
21
)
22
)
23
),
24
metadata=metadata
25
)
26
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
27
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)
28
29
# Since we have one input, one output will exist here.
30
output = post_model_outputs_response.outputs[0]
31
32
print("Predicted concepts:")
33
for concept in output.data.concepts:
34
print("%s %.2f" % (concept.name, concept.value))
Copied!
1
<?php
2
# Insert here the initialization code as outlined on this page:
3
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
4
5
///////////////////////////////////////////////////////////////////////////////
6
// Specifying the Request Data
7
///////////////////////////////////////////////////////////////////////////////
8
//
9
// In the Clarifai platform an image is defined by a special Image object.
10
// There are several ways in which an Image object can be populated including
11
// by url and image bytes (base64).
12
//
13
$image = new Image([
14
'url' => 'https://samples.clarifai.com/dog2.jpeg'
15
]);
16
17
//
18
// After an Image object is created, a Data object is constructed around it.
19
// The Data object offers a container that contains additional image independent
20
// metadata. In this particular use case, no other metadata is needed to be
21
// specified.
22
//
23
$data = new Data([
24
'image' => $image
25
]);
26
27
//
28
// The Data object is then wrapped in an Input object in order to meet the
29
// API specification. Additional fields are available to populate in the Input
30
// object, but for the purposes of this example we can send in just the
31
// Data object.
32
//
33
$input = new Input([
34
'data' => $data
35
]);
36
37
///////////////////////////////////////////////////////////////////////////////
38
// Specifying Output Configuration
39
///////////////////////////////////////////////////////////////////////////////
40
//
41
// Output configuration can be specified by the OutputConfig object. Here
42
// we specify the minimum threshold value to 0.95.
43
//
44
$outputConfig = new OutputConfig([
45
'min_value' => 0.95
46
])
47
48
//
49
// The OutputInfo object is a wrapper around the OutputConfig object
50
//
51
$outputInfo = new OutputInfo([
52
'output_config' => $outputConfig
53
])
54
55
//
56
// The model object is a wrapper around the OutputInfo object. This is the
57
// final part needed to define an output configuration.
58
//
59
$model = new Model([
60
'output_info' => $outputInfo
61
]);
62
63
///////////////////////////////////////////////////////////////////////////////
64
// Creating the request object
65
///////////////////////////////////////////////////////////////////////////////
66
//
67
// Finally, the request object itself is created. This object carries the request
68
// along with the request status and other metadata related to the request itself.
69
// In this example we populate:
70
// - the `user_app_id` field with the UserAppIDSet constructed above
71
// - the `model_id` field with the ID of the model we are referencing
72
// - the `inputs` field with an array of input objects constructed above
73
// - the `model` field with the output configuration specified above
74
//
75
$request = new PostModelOutputsRequest([
76
'user_app_id' => $userDataObject, // This is defined above
77
'model_id' => 'aaa03c23b3724a16a56b629203edc62c', // This is the ID of the publicly available General model.
78
'inputs' => [$input],
79
'model' => $model
80
]);
81
82
///////////////////////////////////////////////////////////////////////////////
83
// Making the RPC Call
84
///////////////////////////////////////////////////////////////////////////////
85
//
86
// Once the request object is constructed, we can call the actual request to the
87
// Clarifai platform. This uses the opened gRPC client channel to communicate the
88
// request and then wait for the response.
89
//
90
[$response, $status]