Skip to main content

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.

tip

To retrieve an entire list of concepts from a given model, and get their ids and names, use the GetModelOutputInfo endpoint.

caution

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.

Below is an example of how you would select concepts and receive predictions from Clarifai's general-image-recognition model.

info

The initialization code used in the following examples is outlined in detail on the client installation page.

#########################################################################################################
# In this section, we set the user authentication, user and app ID, model details, URL of the image
# we want as an input, and concept name and ID. Change these strings to run your own example.
########################################################################################################

# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
# Specify the correct user_id/app_id pairings
# Since you're making inferences outside your app's scope
USER_ID = 'clarifai'
APP_ID = 'main'
# Change these to whatever you want to process
MODEL_ID = 'general-image-recognition'
MODEL_VERSION_ID = 'aa7f35c01e0642fda5cf400f543e7c40'
IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg'
CONCEPT_NAME = "train"
CONCEPT_ID = "ai_6kTjGfF6"

############################################################################
# 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_model_outputs_response = stub.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
model_id=MODEL_ID,
version_id=MODEL_VERSION_ID, # This is optional. Defaults to the latest model version
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL
)
)
)
],
model=resources_pb2.Model(
output_info=resources_pb2.OutputInfo(
output_config=resources_pb2.OutputConfig(
select_concepts=[
# When selecting concepts, value is ignored, so no need to specify it
resources_pb2.Concept(name=CONCEPT_NAME),
resources_pb2.Concept(id=CONCEPT_ID)
]
)
)
)
),
metadata=metadata
)
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
print(post_model_outputs_response.status)
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)

# Since we have one input, one output will exist here.
output = post_model_outputs_response.outputs[0]

print("Predicted concepts:")
for concept in output.data.concepts:
print("%s %.2f" % (concept.name, concept.value))

# Uncomment this line to print the full Response JSON
#print(output)
Text Output Example
Predicted concepts:
train 1.00
station 1.00
JSON Output Example
id: "81acc269d03e4ea7bc0299f4f8287d58"
status {
code: SUCCESS
description: "Ok"
}
created_at {
seconds: 1701798941
nanos: 10825132
}
model {
id: "general-image-recognition"
name: "Image Recognition"
created_at {
seconds: 1457543499
nanos: 608845000
}
app_id: "main"
model_version {
id: "aa7f35c01e0642fda5cf400f543e7c40"
created_at {
seconds: 1520370624
nanos: 454834000
}
status {
code: MODEL_TRAINED
description: "Model is trained and ready"
}
visibility {
gettable: PUBLIC
}
app_id: "main"
user_id: "clarifai"
metadata {
}
}
user_id: "clarifai"
model_type_id: "visual-classifier"
visibility {
gettable: PUBLIC
}
modified_at {
seconds: 1694180313
nanos: 148401000
}
workflow_recommended {
}
}
input {
id: "509694bf26544b03b1b3d30d72688aaa"
data {
image {
url: "https://samples.clarifai.com/metro-north.jpg"
}
}
}
data {
concepts {
id: "ai_HLmqFqBf"
name: "train"
value: 0.9996053576469421
app_id: "main"
}
concepts {
id: "ai_6kTjGfF6"
name: "station"
value: 0.9980133771896362
app_id: "main"
}
}

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 of [1-200].

If your use case requires more concepts, please contact Support.

Below is an example of how you would set maximum concepts and receive predictions from Clarifai's general-image-recognition model.

#######################################################################################################
# In this section, we set the user authentication, user and app ID, model details, URL of the image
# we want as an input, and max concepts. Change these strings to run your own example.
#######################################################################################################

# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
# Specify the correct user_id/app_id pairings
# Since you're making inferences outside your app's scope
USER_ID = 'clarifai'
APP_ID = 'main'
# Change these to whatever you want to process
MODEL_ID = 'general-image-recognition'
MODEL_VERSION_ID = 'aa7f35c01e0642fda5cf400f543e7c40'
IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg'
MAX_CONCEPTS = 3

############################################################################
# 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_model_outputs_response = stub.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
model_id=MODEL_ID,
version_id=MODEL_VERSION_ID, # This is optional. Defaults to the latest model version
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL
)
)
)
],
model=resources_pb2.Model(
output_info=resources_pb2.OutputInfo(
output_config=resources_pb2.OutputConfig(
max_concepts=MAX_CONCEPTS
)
)
)
),
metadata=metadata
)
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
print(post_model_outputs_response.status)
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)

# Since we have one input, one output will exist here.
output = post_model_outputs_response.outputs[0]

print("Predicted concepts:")
for concept in output.data.concepts:
print("%s %.2f" % (concept.name, concept.value))

# Uncomment this line to print the full Response JSON
#print(output)
Text Output Example
Predicted concepts:
train 1.00
railway 1.00
subway system 1.00
JSON Output Example
id: "51ba22c23b0e4724bfbe7600370e4072"
status {
code: SUCCESS
description: "Ok"
}
created_at {
seconds: 1701799066
nanos: 783913374
}
model {
id: "general-image-recognition"
name: "Image Recognition"
created_at {
seconds: 1457543499
nanos: 608845000
}
app_id: "main"
model_version {
id: "aa7f35c01e0642fda5cf400f543e7c40"
created_at {
seconds: 1520370624
nanos: 454834000
}
status {
code: MODEL_TRAINED
description: "Model is trained and ready"
}
visibility {
gettable: PUBLIC
}
app_id: "main"
user_id: "clarifai"
metadata {
}
}
user_id: "clarifai"
model_type_id: "visual-classifier"
visibility {
gettable: PUBLIC
}
modified_at {
seconds: 1694180313
nanos: 148401000
}
workflow_recommended {
}
}
input {
id: "7fd5d408a38a4a15964d9ff7b191ea0a"
data {
image {
url: "https://samples.clarifai.com/metro-north.jpg"
}
}
}
data {
concepts {
id: "ai_HLmqFqBf"
name: "train"
value: 0.9996053576469421
app_id: "main"
}
concepts {
id: "ai_fvlBqXZR"
name: "railway"
value: 0.9992986917495728
app_id: "main"
}
concepts {
id: "ai_SHNDcmJ3"
name: "subway system"
value: 0.9982585310935974
app_id: "main"
}
}

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 .95 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.

Below is an example of how you would set a minimum probability threshold and receive predictions from Clarifai's general-image-recognition model.

#########################################################################################################
# In this section, we set the user authentication, user and app ID, model details, URL of the image
# we want as an input, and minimum value. Change these strings to run your own example.
#########################################################################################################

# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
# Specify the correct user_id/app_id pairings
# Since you're making inferences outside your app's scope
USER_ID = 'clarifai'
APP_ID = 'main'
# Change these to whatever you want to process
MODEL_ID = 'general-image-recognition'
MODEL_VERSION_ID = 'aa7f35c01e0642fda5cf400f543e7c40'
IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg'
MINIMUM_VALUE = 0.95

############################################################################
# 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_model_outputs_response = stub.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
model_id=MODEL_ID,
version_id=MODEL_VERSION_ID, # This is optional. Defaults to the latest model version
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL
)
)
)
],
model=resources_pb2.Model(
output_info=resources_pb2.OutputInfo(
output_config=resources_pb2.OutputConfig(
min_value=MINIMUM_VALUE
)
)
)
),
metadata=metadata
)
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
print(post_model_outputs_response.status)
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)

# Since we have one input, one output will exist here.
output = post_model_outputs_response.outputs[0]

print("Predicted concepts:")
for concept in output.data.concepts:
print("%s %.2f" % (concept.name, concept.value))

# Uncomment this line to print the full Response JSON
#print(output)
Text Output Example
Predicted concepts:
train 1.00
railway 1.00
subway system 1.00
station 1.00
locomotive 1.00
transportation system 1.00
travel 0.99
commuter 0.98
platform 0.98
light 0.97
train station 0.97
blur 0.97
city 0.96
road 0.96
urban 0.96
traffic 0.96
JSON Output Example
id: "5b7931cce8d84be6be71edaf8d5691ae"
status {
code: SUCCESS
description: "Ok"
}
created_at {
seconds: 1701799220
nanos: 689214282
}
model {
id: "general-image-recognition"
name: "Image Recognition"
created_at {
seconds: 1457543499
nanos: 608845000
}
app_id: "main"
model_version {
id: "aa7f35c01e0642fda5cf400f543e7c40"
created_at {
seconds: 1520370624
nanos: 454834000
}
status {
code: MODEL_TRAINED
description: "Model is trained and ready"
}
visibility {
gettable: PUBLIC
}
app_id: "main"
user_id: "clarifai"
metadata {
}
}
user_id: "clarifai"
model_type_id: "visual-classifier"
visibility {
gettable: PUBLIC
}
modified_at {
seconds: 1694180313
nanos: 148401000
}
workflow_recommended {
}
}
input {
id: "cdc6a6628de7435597f09c4ed920c753"
data {
image {
url: "https://samples.clarifai.com/metro-north.jpg"
}
}
}
data {
concepts {
id: "ai_HLmqFqBf"
name: "train"
value: 0.9996053576469421
app_id: "main"
}
concepts {
id: "ai_fvlBqXZR"
name: "railway"
value: 0.9992986917495728
app_id: "main"
}
concepts {
id: "ai_SHNDcmJ3"
name: "subway system"
value: 0.9982585310935974
app_id: "main"
}
concepts {
id: "ai_6kTjGfF6"
name: "station"
value: 0.9980133771896362
app_id: "main"
}
concepts {
id: "ai_RRXLczch"
name: "locomotive"
value: 0.9972604513168335
app_id: "main"
}
concepts {
id: "ai_Xxjc3MhT"
name: "transportation system"
value: 0.9969792366027832
app_id: "main"
}
concepts {
id: "ai_VRmbGVWh"
name: "travel"
value: 0.9889689683914185
app_id: "main"
}
concepts {
id: "ai_jlb9q33b"
name: "commuter"
value: 0.9809139370918274
app_id: "main"
}
concepts {
id: "ai_2gkfMDsM"
name: "platform"
value: 0.9806650876998901
app_id: "main"
}
concepts {
id: "ai_n9vjC1jB"
name: "light"
value: 0.9741945266723633
app_id: "main"
}
concepts {
id: "ai_sQQj52KZ"
name: "train station"
value: 0.9688410758972168
app_id: "main"
}
concepts {
id: "ai_l4WckcJN"
name: "blur"
value: 0.9673133492469788
app_id: "main"
}
concepts {
id: "ai_WBQfVV0p"
name: "city"
value: 0.9615091681480408
app_id: "main"
}
concepts {
id: "ai_TZ3C79C6"
name: "road"
value: 0.9613693356513977
app_id: "main"
}
concepts {
id: "ai_CpFBRWzD"
name: "urban"
value: 0.960391640663147
app_id: "main"
}
concepts {
id: "ai_tr0MBp64"
name: "traffic"
value: 0.9599775075912476
app_id: "main"
}
}

By Model Version ID

Every time you train a custom model, it creates a new model version. By specifying version_id in your predict call, you can continue to predict on a previous version, for consistent prediction results. Clarifai also updates its pre-built models on a regular basis.

If you are looking for consistent results from your predict calls, use version_id. If the model version_id is not specified, predict will default to the most current model.

Below is an example of how you would set a model version ID and receive predictions from Clarifai's general-image-recognition model.

#######################################################################################################
# In this section, we set the user authentication, user and app ID, model ID, model version ID, and
# URL of the image we want as an input. Change these strings to run your own example.
#######################################################################################################

# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
# Specify the correct user_id/app_id pairings
# Since you're making inferences outside your app's scope
USER_ID = 'clarifai'
APP_ID = 'main'
# Change these to whatever you want to process
MODEL_ID = 'general-image-recognition'
MODEL_VERSION_ID = 'aa7f35c01e0642fda5cf400f543e7c40'
IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg'

############################################################################
# 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_model_outputs_response = stub.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
model_id=MODEL_ID,
version_id=MODEL_VERSION_ID,
inputs=[

resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL
)
)
)
]
),
metadata=metadata
)
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
print(post_model_outputs_response.status)
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)

# Since we have one input, one output will exist here
output = post_model_outputs_response.outputs[0]

print("Predicted concepts:")
for concept in output.data.concepts:
print("%s %.2f" % (concept.name, concept.value))

# Uncomment this line to print the full Response JSON
#print(output)
Text Output Example
Predicted concepts:
train 1.00
railway 1.00
subway system 1.00
station 1.00
locomotive 1.00
transportation system 1.00
travel 0.99
commuter 0.98
platform 0.98
light 0.97
train station 0.97
blur 0.97
city 0.96
road 0.96
urban 0.96
traffic 0.96
street 0.95
public 0.93
tramway 0.93
business 0.93
JSON Output Example
id: "7601649459f6458e80eb6e44f6d3dfe0" 
status {
code: SUCCESS
description: "Ok"
}
created_at {
seconds: 1701799352
nanos: 145163726
}
model {
id: "general-image-recognition"
name: "Image Recognition"
created_at {
seconds: 1457543499
nanos: 608845000
}
app_id: "main"
model_version {
id: "aa7f35c01e0642fda5cf400f543e7c40"
created_at {
seconds: 1520370624
nanos: 454834000
}
status {
code: MODEL_TRAINED
description: "Model is trained and ready"
}
visibility {
gettable: PUBLIC
}
app_id: "main"
user_id: "clarifai"
metadata {
}
}
user_id: "clarifai"
model_type_id: "visual-classifier"
visibility {
gettable: PUBLIC
}
modified_at {
seconds: 1694180313
nanos: 148401000
}
workflow_recommended {
}
}
input {
id: "256fa5839e9d425db43553ce9ff38d03"
data {
image {
url: "https://samples.clarifai.com/metro-north.jpg"
}
}
}
data {
concepts {
id: "ai_HLmqFqBf"
name: "train"
value: 0.9996053576469421
app_id: "main"
}
concepts {
id: "ai_fvlBqXZR"
name: "railway"
value: 0.9992986917495728
app_id: "main"
}
concepts {
id: "ai_SHNDcmJ3"
name: "subway system"
value: 0.9982585310935974
app_id: "main"
}
concepts {
id: "ai_6kTjGfF6"
name: "station"
value: 0.9980133771896362
app_id: "main"
}
concepts {
id: "ai_RRXLczch"
name: "locomotive"
value: 0.9972604513168335
app_id: "main"
}
concepts {
id: "ai_Xxjc3MhT"
name: "transportation system"
value: 0.9969792366027832
app_id: "main"
}
concepts {
id: "ai_VRmbGVWh"
name: "travel"
value: 0.9889689683914185
app_id: "main"
}
concepts {
id: "ai_jlb9q33b"
name: "commuter"
value: 0.9809139370918274
app_id: "main"
}
concepts {
id: "ai_2gkfMDsM"
name: "platform"
value: 0.9806650876998901
app_id: "main"
}
concepts {
id: "ai_n9vjC1jB"
name: "light"
value: 0.9741945266723633
app_id: "main"
}
concepts {
id: "ai_sQQj52KZ"
name: "train station"
value: 0.9688410758972168
app_id: "main"
}
concepts {
id: "ai_l4WckcJN"
name: "blur"
value: 0.9673133492469788
app_id: "main"
}
concepts {
id: "ai_WBQfVV0p"
name: "city"
value: 0.9615091681480408
app_id: "main"
}
concepts {
id: "ai_TZ3C79C6"
name: "road"
value: 0.9613693356513977
app_id: "main"
}
concepts {
id: "ai_CpFBRWzD"
name: "urban"
value: 0.960391640663147
app_id: "main"
}
concepts {
id: "ai_tr0MBp64"
name: "traffic"
value: 0.9599775075912476
app_id: "main"
}
concepts {
id: "ai_GjVpxXrs"
name: "street"
value: 0.9475197196006775
app_id: "main"
}
concepts {
id: "ai_mcSHVRfS"
name: "public"
value: 0.934360921382904
app_id: "main"
}
concepts {
id: "ai_J6d1kV8t"
name: "tramway"
value: 0.9320586323738098
app_id: "main"
}
concepts {
id: "ai_6lhccv44"
name: "business"
value: 0.9294787645339966
app_id: "main"
}
}