Evaluating Models
Evaluate a model's performance
Now that you've successfully trained the model, you may want to test its performance before using it in a production environment. The Model Evaluation tool allows you to perform a cross validation on a specified model version. Once the evaluation is complete, you can view the various metrics that inform the model’s performance.
How It Works
Model Evaluation performs a K-split cross validation on data you used to train your custom model.
In the cross validation process, it will:
- Set aside a random 1/K subset of the training data and designate as a test set;
- Train a new model with the remaining training data;
- Pass the test set data through this new model to make predictions;
- Compare the predictions against the test set’s actual labels; and,
- Repeat steps 1) through 4) across K splits to average out the evaluation results.
Requirements
To run the evaluation on your custom model, it should meet the following criteria:
- It should be a custom trained model version with:
- At least 2 concepts.
- At least 10 training inputs per concept (at least 50 inputs per concept is recommended).
The evaluation may result in an error if the model version doesn’t satisfy the requirements above.
The initialization code used in the following examples is outlined in detail on the client installation page.
Running Evaluation
If evaluating an embedding-classifier
model type, you need to set use_kfold
to false
in the eval_info.params
of the evaluation request. Here is an example:
params.update({"dataset_id": DATASET_ID, "use_kfold": False})
PostModelVersionEvaluations
Below is an example of how you would use the PostModelVersionEvaluations
method to run an evaluation on a specific version of a custom model.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
############################################################################################
# In this section, we set the user authentication, app ID, and model evaluation details.
# 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 make your own evaluations
MODEL_ID = "YOUR_MODEL_ID_HERE"
MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE"
DATASET_ID = "YOUR_DATASET_ID_HERE"
##########################################################################
# 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
from google.protobuf.struct_pb2 import Struct
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
params = Struct()
params.update({"dataset_id": DATASET_ID})
metadata = (("authorization", "Key " + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_model_evaluations = stub.PostModelVersionEvaluations(
service_pb2.PostModelVersionEvaluationsRequest(
user_app_id=userDataObject,
model_id=MODEL_ID,
model_version_id=MODEL_VERSION_ID,
eval_metrics=[
resources_pb2.EvalMetrics(
eval_info=resources_pb2.EvalInfo(params=params),
)
],
),
metadata=metadata,
)
if post_model_evaluations.status.code != status_code_pb2.SUCCESS:
print(post_model_evaluations.status)
raise Exception("Failed response, status: " + post_model_evaluations.status.description)
print(post_model_evaluations)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model evaluation details.
// 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 make your own evaluations
const MODEL_ID = "YOUR_MODEL_ID_HERE";
const MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
const DATASET_ID = "YOUR_DATASET_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// 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
},
"eval_metrics": [
{
"eval_info": {
"params": {
"dataset_id": DATASET_ID
}
}
}
]
});
const requestOptions = {
method: "POST",
headers: {
"Accept": "application/json",
"Authorization": "Key " + PAT
},
body: raw
};
fetch(`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/models/${MODEL_ID}/versions/${MODEL_VERSION_ID}/evaluations`, 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 model evaluation details.
// 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 make your own evaluations
const MODEL_ID = "YOUR_MODEL_ID_HERE";
const MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
const DATASET_ID = "YOUR_DATASET_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// 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.PostModelVersionEvaluations(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
model_id: MODEL_ID,
model_version_id: MODEL_VERSION_ID,
eval_metrics: [
{
eval_info: {
params: {
dataset_id: DATASET_ID
}
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.error('Post models failed, status:', response.status);
throw new Error("Evaluate model failed, status: " + response.status.description);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model evaluation details.
// 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to make your own evaluations
static final String MODEL_ID = "YOUR_MODEL_ID_HERE";
static final String MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
static final String DATASET_ID = "YOUR_DATASET_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
Struct.Builder params = Struct.newBuilder()
.putFields("dataset_id", Value.newBuilder().setStringValue(DATASET_ID).build());
MultiEvalMetricsResponse postEvaluationsResponse = stub.postModelVersionEvaluations(
PostModelVersionEvaluationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setModelId(MODEL_ID)
.setModelVersionId(MODEL_VERSION_ID)
.addEvalMetrics(
EvalMetrics.newBuilder()
.setEvalInfo(EvalInfo.newBuilder()
.setParams(params)
)
)
.build()
);
if (postEvaluationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Evaluate model failed, status: " + postEvaluationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model evaluation details.
// 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 make your own evaluations
$MODEL_ID = "YOUR_MODEL_ID_HERE";
$MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
$DATASET_ID = "YOUR_DATASET_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostModelVersionEvaluationsRequest;
use Clarifai\Api\EvalMetrics;
use Clarifai\Api\EvalInfo;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
use Google\Protobuf\Struct;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID,
]);
// create Struct instance
$params = new Struct();
$params->model_id = $DATASET_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->PostModelVersionEvaluations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostModelVersionEvaluationsRequest([
"user_app_id" => $userDataObject,
"model_id" => $MODEL_ID,
"model_version_id" => $MODEL_VERSION_ID,
"eval_metrics" => [
new EvalMetrics([
"eval_info" => new EvalInfo([
"params" => $params
]),
])
]
]),
$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) {
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " . $response->getStatus()->getDetails());
}
echo $response->serializeToJsonString();
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/models/YOUR_MODEL_ID_HERE/versions/YOUR_MODEL_VERSION_ID_HERE/evaluations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"eval_metrics": [
{
"eval_info": {
"params": {
"dataset_id": "YOUR_DATASET_ID_HERE"
}
}
}
]
}'
PostEvaluations
Below is an example of how you would use the PostEvaluations
method to run an evaluation on a specific version of a custom model. The method allows you to choose models and datasets from different apps that you have access to.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
############################################################################################
# In this section, we set the user authentication, app ID, and model evaluation details.
# 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 make your own evaluations
MODEL_APP_ID = "YOUR_MODEL_APP_ID_HERE"
MODEL_USER_ID = "YOUR_MODEL_USER_ID_HERE"
MODEL_ID = "YOUR_MODEL_ID_HERE"
MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE"
DATASET_USER_ID = "YOUR_DATASET_USER_ID_HERE"
DATASET_APP_ID = "YOUR_DATASET_APP_ID_HERE"
DATASET_ID = "YOUR_DATASET_ID_HERE"
DATASET_VERSION_ID = "YOUR_DATASET_VERSION_ID_HERE"
##########################################################################
# 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_evaluations = stub.PostEvaluations(
service_pb2.PostEvaluationsRequest(
user_app_id=userDataObject,
eval_metrics=[
resources_pb2.EvalMetrics(
model=resources_pb2.Model(
app_id=MODEL_APP_ID,
user_id=MODEL_USER_ID,
id=MODEL_ID,
model_version=resources_pb2.ModelVersion(id=MODEL_VERSION_ID),
),
ground_truth_dataset=resources_pb2.Dataset(
user_id=DATASET_USER_ID,
app_id=DATASET_APP_ID,
id=DATASET_ID,
version=resources_pb2.DatasetVersion(id=DATASET_VERSION_ID),
),
)
],
),
metadata=metadata,
)
if post_model_evaluations.status.code != status_code_pb2.SUCCESS:
print(post_model_evaluations.status)
raise Exception(
"Failed response, status: " + post_model_evaluations.status.description
)
print(post_model_evaluations)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model evaluation details.
// 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 evaluate your own model
const MODEL_APP_ID = "YOUR_MODEL_APP_ID_HERE";
const MODEL_USER_ID = "YOUR_MODEL_USER_ID_HERE";
const MODEL_ID = "YOUR_MODEL_ID_HERE";
const MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
const DATASET_USER_ID = "YOUR_DATASET_USER_ID_HERE";
const DATASET_APP_ID = "YOUR_DATASET_APP_ID_HERE";
const DATASET_ID = "YOUR_DATASET_ID_HERE";
const DATASET_VERSION_ID = "YOUR_DATASET_VERSION_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// 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
},
"eval_metrics": [
{
"model": {
"app_id": MODEL_APP_ID,
"user_id": MODEL_USER_ID,
"id": MODEL_ID,
"model_version": {
"id": MODEL_VERSION_ID
}
},
"ground_truth_dataset": {
"user_id": DATASET_USER_ID,
"app_id": DATASET_APP_ID,
"id": DATASET_ID,
"version": {
"id": DATASET_VERSION_ID
}
}
}
]
});
const requestOptions = {
method: "POST",
headers: {
"Accept": "application/json",
"Authorization": "Key " + PAT
},
body: raw
};
fetch(`https://api.clarifai.com/v2/evaluations`, 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 model evaluation details.
// 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 evaluate your own model
const MODEL_APP_ID = "YOUR_MODEL_APP_ID_HERE";
const MODEL_USER_ID = "YOUR_MODEL_USER_ID_HERE";
const MODEL_ID = "YOUR_MODEL_ID_HERE";
const MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
const DATASET_USER_ID = "YOUR_DATASET_USER_ID_HERE";
const DATASET_APP_ID = "YOUR_DATASET_APP_ID_HERE";
const DATASET_ID = "YOUR_DATASET_ID_HERE";
const DATASET_VERSION_ID = "YOUR_DATASET_VERSION_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// 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.PostEvaluations(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
eval_metrics: [
{
model: {
app_id: MODEL_APP_ID,
user_id: MODEL_USER_ID,
id: MODEL_ID,
model_version: {
id: MODEL_VERSION_ID
}
},
ground_truth_dataset: {
user_id: DATASET_USER_ID,
app_id: DATASET_APP_ID,
id: DATASET_ID,
version: {
id: DATASET_VERSION_ID
}
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.error('Post models failed, status:', response.status);
throw new Error("Evaluate model failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model evaluation details.
// 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to evaluate your own model
static final String MODEL_APP_ID = "YOUR_MODEL_APP_ID_HERE";
static final String MODEL_USER_ID = "YOUR_MODEL_USER_ID_HERE";
static final String MODEL_ID = "YOUR_MODEL_ID_HERE";
static final String MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
static final String DATASET_USER_ID = "YOUR_DATASET_USER_ID_HERE";
static final String DATASET_APP_ID = "YOUR_DATASET_APP_ID_HERE";
static final String DATASET_ID = "YOUR_DATASET_ID_HERE";
static final String DATASET_VERSION_ID = "YOUR_DATASET_VERSION_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiEvalMetricsResponse postEvaluationsResponse = stub.postEvaluations(
PostEvaluationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addEvalMetrics(
EvalMetrics.newBuilder()
.setModel(Model.newBuilder()
.setAppId(MODEL_APP_ID)
.setUserId(MODEL_USER_ID)
.setId(MODEL_ID)
.setModelVersion(ModelVersion.newBuilder()
.setId(MODEL_VERSION_ID)
)
)
.setGroundTruthDataset(Dataset.newBuilder()
.setUserId(DATASET_USER_ID)
.setAppId(DATASET_APP_ID)
.setId(DATASET_ID)
.setVersion(DatasetVersion.newBuilder()
.setId(DATASET_VERSION_ID)
)
)
)
.build()
);
if (postEvaluationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Evaluate model failed, status: " + postEvaluationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and model evaluation details.
// 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 make your own evaluations
$MODEL_APP_ID = "YOUR_MODEL_APP_ID_HERE";
$MODEL_USER_ID = "YOUR_MODEL_USER_ID_HERE";
$MODEL_ID = "YOUR_MODEL_ID_HERE";
$MODEL_VERSION_ID = "YOUR_MODEL_VERSION_HERE";
$DATASET_USER_ID = "YOUR_DATASET_USER_ID_HERE";
$DATASET_APP_ID = "YOUR_DATASET_APP_ID_HERE";
$DATASET_ID = "YOUR_DATASET_ID_HERE";
$DATASET_VERSION_ID = "YOUR_DATASET_VERSION_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostEvaluationsRequest;
use Clarifai\Api\Model;
use Clarifai\Api\ModelVersion;
use Clarifai\Api\EvalMetrics;
use Clarifai\Api\Dataset;
use Clarifai\Api\DatasetVersion;
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->PostEvaluations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostEvaluationsRequest([
"user_app_id" => $userDataObject,
"eval_metrics" => [
new EvalMetrics([
"model" => new Model([
"app_id" => $MODEL_APP_ID,
"user_id" => $MODEL_USER_ID,
"id" => $MODEL_ID,
"model_version" => new ModelVersion([
"id" => $MODEL_VERSION_ID
])
]),
"ground_truth_dataset" => new Dataset([
"user_id" => $DATASET_USER_ID,
"app_id" => $DATASET_APP_ID,
"id" => $DATASET_ID,
"version" => new DatasetVersion([
"id" => $DATASET_VERSION_ID
])
])
])
]
]),
$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) {
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " . $response->getStatus()->getDetails());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/evaluations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"eval_metrics": [
{
"model": {
"app_id": "YOUR_MODEL_APP_ID_HERE",
"user_id": "YOUR_MODEL_USER_ID_HERE",
"id": "YOUR_MODEL_ID_HERE",
"model_version": {
"id": "YOUR_MODEL_VERSION_HERE"
}
},
"ground_truth_dataset": {
"user_id": "YOUR_DATASET_USER_ID_HERE",
"app_id": "YOUR_DATASET_APP_ID_HERE",
"id": "YOUR_DATASET_ID_HERE",
"version": {
"id": "YOUR_DATASET_VERSION_ID_HERE"
}
}
}
]
}'
Once the evaluation is complete, you can retrieve the results and analyze the performance of your custom model.
We'll talk about how to interpret a model's evaluation results in the next section.
You can also learn how to perform evaluation on the Portal here.
📄️ Interpreting Evaluations
Learn to interpret model evaluations.
📄️ Improving Your Model
Iterate upon and improve your models