评估模型

训练完模型后,AutoML Video Intelligence 对象跟踪会使用测试集中的内容来评估新模型的质量和准确率。

AutoML Video Intelligence 对象跟踪提供了一组总体评估指标以及针对每个类别标签的评估指标;前者指示模型的整体表现,后者指示模型在该标签上的表现。

  • IoUIntersection over Union,一种在对象跟踪中使用的指标,作用是测量视频帧中对象实例的预测边界框与实际边界框的重叠度。预测的边界框值与实际的边界框值越接近,交集和 IoU 值越大。

  • AuPRC精确率/召回率曲线下的面积,亦称为“平均精确率”。通常介于 0.5 和 1.0 之间。数值越高,表示模型越准确。

  • 置信度阈值曲线显示不同的置信度阈值对精确率、召回率、真正例率和假正例率有何影响。请了解精确率和召回率的关系。

您可利用这些数据来评估您的模型的就绪情况。如果 AUC 得分低,或者精确率和召回率得分低,这可能表明您的模型需要额外的训练数据或者模型标签不一致。如果 AUC 得分非常高,并且精确率和召回率也很完美,这可能表明数据过于简单,模型可能无法有效泛化。

获取模型评估值

网页界面

  1. AutoML Video 对象跟踪界面中打开模型页面。

  2. 点击待评估模型所在的行。

  3. 点击评估标签。

    如果模型已完成训练,则 AutoML Video 对象跟踪会显示其评估指标。

    含有模型信息的“评估”标签
  4. 如需查看特定标签的指标,请从页面下部的标签列表中选择标签名称。

REST

在使用任何请求数据之前,请先进行以下替换:

  • model-id:将替换为模型的标识符
  • project-number:您项目的编号
  • location-id:在其中添加注解的 Cloud 区域。支持的云区域为:us-east1us-west1europe-west1asia-east1。如果未指定区域,系统将根据视频文件位置确定区域。

HTTP 方法和网址:

GET https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models/model-id:modelEvaluations

如需发送请求,请选择以下方式之一:

curl

执行以下命令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models/model-id:modelEvaluations"

PowerShell

执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models/model-id:modelEvaluations" | Select-Object -Expand Content
响应包含整个模型的 ModelEvaluation 资源,例如 8703337066443674578

Java

要向 AutoML Video 对象跟踪进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.ModelEvaluation;
import com.google.cloud.automl.v1beta1.ModelEvaluationName;
import java.io.IOException;

class GetModelEvaluation {

  static void getModelEvaluation() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String modelEvaluationId = "YOUR_MODEL_EVALUATION_ID";
    getModelEvaluation(projectId, modelId, modelEvaluationId);
  }

  // Get a model evaluation
  static void getModelEvaluation(String projectId, String modelId, String modelEvaluationId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // Get the full path of the model evaluation.
      ModelEvaluationName modelEvaluationFullId =
          ModelEvaluationName.of(projectId, "us-central1", modelId, modelEvaluationId);

      // Get complete detail of the model evaluation.
      ModelEvaluation modelEvaluation = client.getModelEvaluation(modelEvaluationFullId);

      System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName());
      System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId());
      System.out.println("Create Time:");
      System.out.format("\tseconds: %s%n", modelEvaluation.getCreateTime().getSeconds());
      System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9);
      System.out.format(
          "Evalution Example Count: %d%n", modelEvaluation.getEvaluatedExampleCount());

      System.out.format(
          "Video Object Tracking Evaluation Metrics: %s%n",
          modelEvaluation.getVideoObjectTrackingEvaluationMetrics());
    }
  }
}

Node.js

要向 AutoML Video 对象跟踪进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1';
// const modelId = 'YOUR_MODEL_ID';
// const modelEvaluationId = 'YOUR_MODEL_EVALUATION_ID';

// Imports the Google Cloud AutoML library
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

// Instantiates a client
const client = new AutoMlClient();

async function getModelEvaluation() {
  // Construct request
  const request = {
    name: client.modelEvaluationPath(
      projectId,
      location,
      modelId,
      modelEvaluationId
    ),
  };

  const [response] = await client.getModelEvaluation(request);

  console.log(`Model evaluation name: ${response.name}`);
  console.log(`Model annotation spec id: ${response.annotationSpecId}`);
  console.log(`Model display name: ${response.displayName}`);
  console.log('Model create time');
  console.log(`\tseconds ${response.createTime.seconds}`);
  console.log(`\tnanos ${response.createTime.nanos / 1e9}`);
  console.log(`Evaluation example count: ${response.evaluatedExampleCount}`);
  console.log(
    `Video object tracking model evaluation metrics: ${response.videoObjectTrackingEvaluationMetrics}`
  );

}

getModelEvaluation();

Python

要向 AutoML Video 对象跟踪进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

from google.cloud import automl_v1beta1 as automl

# TODO(developer): Uncomment and set the following variables
# project_id = "YOUR_PROJECT_ID"
# model_id = "YOUR_MODEL_ID"
# model_evaluation_id = "YOUR_MODEL_EVALUATION_ID"

client = automl.AutoMlClient()
# Get the full path of the model evaluation.
model_path = client.model_path(project_id, "us-central1", model_id)
model_evaluation_full_id = f"{model_path}/modelEvaluations/{model_evaluation_id}"

# Get complete detail of the model evaluation.
response = client.get_model_evaluation(name=model_evaluation_full_id)

print(f"Model evaluation name: {response.name}")
print(f"Model annotation spec id: {response.annotation_spec_id}")
print(f"Create Time: {response.create_time}")
print(f"Evaluation example count: {response.evaluated_example_count}")

print(
    "Video object tracking model evaluation metrics: {}".format(
        response.video_object_tracking_evaluation_metrics
    )
)

迭代模型

如果您对质量水平不满意,则可以重新执行前述步骤以提高质量:

  • 您可能需要添加不同类型的视频(例如更宽的角度、更高或更低的分辨率、不同的视角)。
  • 如果您没有足够多的训练视频,请考虑完全移除相应标签。
  • 请记住,机器无法读取您的标签名称;对于机器而言,这只是一串随机的字母。如果您有一个名为“door”的标签和另一个名为“door_with_knob”的标签,那么除了您提供给它的视频以外,机器无法厘清二者的细微差别。
  • 用更多的真正例和真负例示例来扩充您的数据。 那些接近决策边界的示例尤为重要。

一旦进行了更改,请训练并评估新模型,直到达到足够高的质量水平为止。