AutoML 動画動作認識モデルを評価して反復処理を行う

このページでは、モデルを反復処理できるように AutoML 動画動作認識モデルを評価する方法について説明します。

Vertex AI では、モデルのパフォーマンスを判定するためのモデル評価指標(適合率や再現率の指標など)が提供されます。Vertex AI では、評価指標の計算にテストセットが使用されます。

モデル評価指標の使い方

モデル評価指標は、テストセットに対するモデルのパフォーマンスを定量的に測定します。これらの評価指標をどのように解釈し、使用するかは、ビジネスニーズや、どのような問題をモデルのトレーニングで解決するかによって異なります。たとえば、偽陽性の許容範囲が偽陰性の許容範囲よりも低い場合もあれば、その逆の場合もあります。このような質問に対する答えは、どの指標を重視するかによって変わります。

モデルのパフォーマンスを向上させるための反復修正の詳細については、モデルの反復修正をご覧ください。

Vertex AI から返される評価指標

Vertex AI からは、適合率、再現率、信頼度しきい値など、さまざまな評価指標が返されます。返される評価指標は、モデルの目標によって異なります。たとえば、画像分類モデルと画像オブジェクト検出モデルでは、異なる評価指標が返されます。

Cloud Storage からダウンロードできるスキーマ ファイルによって、Vertex AI から各目標に対して提供される評価指標が決まります。次のスキーマ ファイルでは、動画動作認識の評価指標を記述します。

スキーマ ファイルは、Cloud Storage 上の gs://google-cloud-aiplatform/schema/modelevaluation/ からダウンロードできます。

  • AuPRC: 適合率 / 再現率(PR)曲線の下の領域の面積。平均適合率とも呼ばれます。この値は範囲が 0~1 で、値が高いほど高品質のモデルであることを示します。
  • 適合率ウィンドウ期間: 真陽性としてカウントされるためには、予測のタイムスタンプがこのウィンドウに入っている必要があります。特定の長さを持つ正解(グラウンド トゥルース)アクションのタイムスタンプが適合率ウィンドウ期間の中心になります。この値は、動画の先頭から測定された秒数で表され、末尾に「s」が追加されます。小数値を指定できます(マイクロ秒単位まで)。
  • 算術平均適合率: 平均適合率とも呼ばれます。この値は範囲が 0~1 で、値が高いほど高品質のモデルであることを示します。
  • 信頼度しきい値: 返される予測を仕分ける信頼度のスコア。モデルはこの値以上の予測を返します。信頼度しきい値が高いほど、適合率は向上しますが、再現率は低くなります。Vertex AI は、さまざまなしきい値に対する信頼指標を返し、しきい値が適合率再現率にどのように影響するかを示します。
  • 再現率: このクラスの予測のうち、モデルが正しく予測した割合。真陽性率とも呼ばれます。
  • 適合率: モデルによって生成された分類予測のうち正しい分類であった割合。
  • F1 スコア: 適合率と再現率の調和平均。適合率と再現率のバランスを求めていて、クラス分布が不均一な場合、F1 は有用な指標となります。

評価指標の取得

モデルに関する評価指標の集合セットを取得できますが、目的によっては、特定のクラスやラベルに関する評価指標を取得することもできます。特定のクラスやラベルに関する評価指標は、評価スライスとも呼ばれます。以下のコンテンツでは、Google Cloud コンソールまたは API を使用して評価指標の集合セットと評価スライスを取得する方法を説明します。

Google Cloud コンソール

  1. Google Cloud コンソールの [Vertex AI] セクションで、[モデル] ページに移動します。

    [モデル] ページに移動

  2. [リージョン] プルダウンで、モデルが配置されているリージョンを選択します。

  3. モデルの一覧からモデルをクリックすると、モデルの [評価] タブが開きます。

    [評価] タブでは、モデルの評価指標の集合セット(平均適合率再現率など)を確認できます。

    モデルの目標に評価スライスが含まれる場合は、コンソールにラベルの一覧が表示されます。次の例に示すように、ラベルをクリックすると、そのラベルの評価指標を表示できます。

    コンソールでラベルを選択する

API

評価指標を取得するための API リクエストはデータ型や目標ごとに同じですが、その出力は異なります。以下のサンプルでは、同じリクエストが使用されていますが、レスポンスが異なっています。

集約型のモデル評価指標の取得

集約型のモデル評価指標は、モデル全体に関する情報を提供します。特定のスライスに関する情報を表示するには、モデル評価スライスを一覧表示します。

集約型のモデル評価指標を表示するには、projects.locations.models.evaluations.get メソッドを使用します。

Vertex AI は、動画の動作認識指標の配列を返します。各要素には、precisionWindowLengthconfidenceThreshold のさまざまな値における評価指標が表示されます。さまざまなウィンドウ長や信頼度のしきい値における評価指標を表示させることにより、その他の指標(適合率や再現率など)がそれらの値によってどのように変化するか確認できます。

お使いの言語または環境に対応するタブを選択してください。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: モデルが保存されているリージョン。
  • PROJECT: 実際のプロジェクト ID
  • MODEL_ID: モデルリソースの ID。
  • PROJECT_NUMBER: プロジェクトに自動生成されたプロジェクト番号
  • EVALUATION_ID: モデル評価の ID(レスポンスに表示される)。

HTTP メソッドと URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations"

PowerShell

次のコマンドを実行します。

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations" | Select-Object -Expand Content

次のような JSON レスポンスが返されます。

Java

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Java の設定手順を完了してください。詳細については、Vertex AI Java API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

import com.google.cloud.aiplatform.v1.ModelEvaluation;
import com.google.cloud.aiplatform.v1.ModelEvaluationName;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;

public class GetModelEvaluationVideoActionRecognitionSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // To obtain evaluationId run the code block below after setting modelServiceSettings.
    //
    // try (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings))
    // {
    //   String location = "us-central1";
    //   ModelName modelFullId = ModelName.of(project, location, modelId);
    //   ListModelEvaluationsRequest modelEvaluationsrequest =
    //   ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
    //   for (ModelEvaluation modelEvaluation :
    //     modelServiceClient.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
    //       System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName());
    //   }
    // }
    String project = "PROJECT";
    String modelId = "MODEL_ID";
    String evaluationId = "EVALUATION_ID";
    getModelEvaluationVideoActionRecognitionSample(project, modelId, evaluationId);
  }

  static void getModelEvaluationVideoActionRecognitionSample(
      String project, String modelId, String evaluationId) throws IOException {
    ModelServiceSettings settings =
        ModelServiceSettings.newBuilder()
            .setEndpoint("us-central1-aiplatform.googleapis.com:443")
            .build();
    String location = "us-central1";

    // 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 (ModelServiceClient client = ModelServiceClient.create(settings)) {
      ModelEvaluationName name = ModelEvaluationName.of(project, location, modelId, evaluationId);
      ModelEvaluation response = client.getModelEvaluation(name);
      System.out.format("response: %s\n", response);
    }
  }
}

Python

Python をインストールまたは更新する方法については、Vertex AI SDK for Python をインストールするをご覧ください。詳細については、Python API リファレンス ドキュメントをご覧ください。

from google.cloud import aiplatform

def get_model_evaluation_video_action_recognition_sample(
    project: str,
    model_id: str,
    evaluation_id: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    """
    To obtain evaluation_id run the following commands where LOCATION
    is the region where the model is stored, PROJECT is the project ID,
    and MODEL_ID is the ID of your model.

    model_client = aiplatform.gapic.ModelServiceClient(
        client_options={
            'api_endpoint':'LOCATION-aiplatform.googleapis.com'
            }
        )
    evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID')
    print("evaluations:", evaluations)
    """
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.ModelServiceClient(client_options=client_options)
    name = client.model_evaluation_path(
        project=project, location=location, model=model_id, evaluation=evaluation_id
    )
    response = client.get_model_evaluation(name=name)
    print("response:", response)

すべての評価スライスの一覧表示

projects.locations.models.evaluations.slices.list メソッドは、モデルのすべての評価スライスを一覧表示します。モデルの評価 ID が必要です。この ID は、評価指標の集合セットを表示する際に取得できます。

モデル評価スライスを使用すると、特定のラベルでのモデルのパフォーマンスを判断できます。value フィールドは、指標の対象となるラベルを示します。

Vertex AI は、動画の動作認識指標の配列を返します。各要素には、precisionWindowLengthconfidenceThreshold のさまざまな値における評価指標が表示されます。さまざまなウィンドウ長や信頼度のしきい値における評価指標を表示させることにより、その他の指標(適合率や再現率など)がそれらの値によってどのように変化するか確認できます。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: モデルが配置されているリージョン。例: us-central1
  • PROJECT: 実際のプロジェクト ID
  • MODEL_ID: モデルの ID。
  • EVALUATION_ID: リストする評価スライスを含むモデル評価の ID。

HTTP メソッドと URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations/EVALUATION_ID/slices

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations/EVALUATION_ID/slices"

PowerShell

次のコマンドを実行します。

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations/EVALUATION_ID/slices" | Select-Object -Expand Content

次のような JSON レスポンスが返されます。

Java

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Java の設定手順を完了してください。詳細については、Vertex AI Java API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。


import com.google.cloud.aiplatform.v1.ModelEvaluationName;
import com.google.cloud.aiplatform.v1.ModelEvaluationSlice;
import com.google.cloud.aiplatform.v1.ModelEvaluationSlice.Slice;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;

public class ListModelEvaluationSliceSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // To obtain evaluationId run the code block below after setting modelServiceSettings.
    //
    // try (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings))
    // {
    //   String location = "us-central1";
    //   ModelName modelFullId = ModelName.of(project, location, modelId);
    //   ListModelEvaluationsRequest modelEvaluationsrequest =
    //   ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
    //   for (ModelEvaluation modelEvaluation :
    //     modelServiceClient.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
    //       System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName());
    //   }
    // }
    String project = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String evaluationId = "YOUR_EVALUATION_ID";
    listModelEvaluationSliceSample(project, modelId, evaluationId);
  }

  static void listModelEvaluationSliceSample(String project, String modelId, String evaluationId)
      throws IOException {
    ModelServiceSettings modelServiceSettings =
        ModelServiceSettings.newBuilder()
            .setEndpoint("us-central1-aiplatform.googleapis.com:443")
            .build();

    // 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 (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings)) {
      String location = "us-central1";
      ModelEvaluationName modelEvaluationName =
          ModelEvaluationName.of(project, location, modelId, evaluationId);

      for (ModelEvaluationSlice modelEvaluationSlice :
          modelServiceClient.listModelEvaluationSlices(modelEvaluationName).iterateAll()) {
        System.out.format("Model Evaluation Slice Name: %s\n", modelEvaluationSlice.getName());
        System.out.format("Metrics Schema Uri: %s\n", modelEvaluationSlice.getMetricsSchemaUri());
        System.out.format("Metrics: %s\n", modelEvaluationSlice.getMetrics());
        System.out.format("Create Time: %s\n", modelEvaluationSlice.getCreateTime());

        Slice slice = modelEvaluationSlice.getSlice();
        System.out.format("Slice Dimensions: %s\n", slice.getDimension());
        System.out.format("Slice Value: %s\n\n", slice.getValue());
      }
    }
  }
}

Node.js

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Node.js の設定手順を完了してください。詳細については、Vertex AI Node.js API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

/**
 * TODO(developer): Uncomment these variables before running the sample
 * (not necessary if passing values as arguments). To obtain evaluationId,
 * instantiate the client and run the following the commands.
 */
// const parentName = `projects/${project}/locations/${location}/models/${modelId}`;
// const evalRequest = {
//   parent: parentName
// };
// const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest);
// console.log(evalResponse);

// const modelId = 'YOUR_MODEL_ID';
// const evaluationId = 'YOUR_EVALUATION_ID';
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';

// Imports the Google Cloud Model Service Client library
const {ModelServiceClient} = require('@google-cloud/aiplatform');

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

// Instantiates a client
const modelServiceClient = new ModelServiceClient(clientOptions);

async function listModelEvaluationSlices() {
  // Configure the parent resources
  const parent = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`;
  const request = {
    parent,
  };

  // Get and print out a list of all the evaluation slices for this resource
  const [response] =
    await modelServiceClient.listModelEvaluationSlices(request);
  console.log('List model evaluation response', response);
  console.log(response);
}
listModelEvaluationSlices();

Python

Python をインストールまたは更新する方法については、Vertex AI SDK for Python をインストールするをご覧ください。詳細については、Python API リファレンス ドキュメントをご覧ください。

from google.cloud import aiplatform

def list_model_evaluation_slices_sample(
    project: str,
    model_id: str,
    evaluation_id: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    """
    To obtain evaluation_id run the following commands where LOCATION
    is the region where the model is stored, PROJECT is the project ID,
    and MODEL_ID is the ID of your model.

    model_client = aiplatform.gapic.ModelServiceClient(
        client_options={
            'api_endpoint':'LOCATION-aiplatform.googleapis.com'
            }
        )
    evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID')
    print("evaluations:", evaluations)
    """
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.ModelServiceClient(client_options=client_options)
    parent = client.model_evaluation_path(
        project=project, location=location, model=model_id, evaluation=evaluation_id
    )
    response = client.list_model_evaluation_slices(parent=parent)
    for model_evaluation_slice in response:
        print("model_evaluation_slice:", model_evaluation_slice)

単一のスライスに関する指標の取得

単一のスライスに関する評価指標を表示するには、projects.locations.models.evaluations.slices.get メソッドを使用します。スライス ID が必要になります。これは、すべてのスライスを一覧表示するときに提供される ID です。次のサンプルは、すべてのデータ型と目標に適用されます。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: モデルが配置されているリージョン。たとえば、us-central1 などです。
  • PROJECT: 実際のプロジェクト ID
  • MODEL_ID: モデルの ID。
  • EVALUATION_ID: 取得する評価スライスを含むモデル評価の ID。
  • SLICE_ID: 取得する評価スライスの ID。
  • PROJECT_NUMBER: プロジェクトに自動生成されたプロジェクト番号
  • EVALUATION_METRIC_SCHEMA_FILE_NAME: 戻り値となる評価指標を定義するスキーマ ファイルの名前(classification_metrics_1.0.0 など)。

HTTP メソッドと URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations/EVALUATION_ID/slices/SLICE_ID

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations/EVALUATION_ID/slices/SLICE_ID"

PowerShell

次のコマンドを実行します。

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID/evaluations/EVALUATION_ID/slices/SLICE_ID" | Select-Object -Expand Content

次のような JSON レスポンスが返されます。

Java

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Java の設定手順を完了してください。詳細については、Vertex AI Java API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。


import com.google.cloud.aiplatform.v1.ModelEvaluationSlice;
import com.google.cloud.aiplatform.v1.ModelEvaluationSlice.Slice;
import com.google.cloud.aiplatform.v1.ModelEvaluationSliceName;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;

public class GetModelEvaluationSliceSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // To obtain evaluationId run the code block below after setting modelServiceSettings.
    //
    // try (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings))
    // {
    //   String location = "us-central1";
    //   ModelName modelFullId = ModelName.of(project, location, modelId);
    //   ListModelEvaluationsRequest modelEvaluationsrequest =
    //   ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
    //   for (ModelEvaluation modelEvaluation :
    //     modelServiceClient.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
    //       System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName());
    //   }
    // }
    String project = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String evaluationId = "YOUR_EVALUATION_ID";
    String sliceId = "YOUR_SLICE_ID";
    getModelEvaluationSliceSample(project, modelId, evaluationId, sliceId);
  }

  static void getModelEvaluationSliceSample(
      String project, String modelId, String evaluationId, String sliceId) throws IOException {
    ModelServiceSettings modelServiceSettings =
        ModelServiceSettings.newBuilder()
            .setEndpoint("us-central1-aiplatform.googleapis.com:443")
            .build();

    // 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 (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings)) {
      String location = "us-central1";
      ModelEvaluationSliceName modelEvaluationSliceName =
          ModelEvaluationSliceName.of(project, location, modelId, evaluationId, sliceId);

      ModelEvaluationSlice modelEvaluationSlice =
          modelServiceClient.getModelEvaluationSlice(modelEvaluationSliceName);

      System.out.println("Get Model Evaluation Slice Response");
      System.out.format("Model Evaluation Slice Name: %s\n", modelEvaluationSlice.getName());
      System.out.format("Metrics Schema Uri: %s\n", modelEvaluationSlice.getMetricsSchemaUri());
      System.out.format("Metrics: %s\n", modelEvaluationSlice.getMetrics());
      System.out.format("Create Time: %s\n", modelEvaluationSlice.getCreateTime());

      Slice slice = modelEvaluationSlice.getSlice();
      System.out.format("Slice Dimensions: %s\n", slice.getDimension());
      System.out.format("Slice Value: %s\n", slice.getValue());
    }
  }
}

Node.js

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Node.js の設定手順を完了してください。詳細については、Vertex AI Node.js API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

/**
 * TODO(developer): Uncomment these variables before running the sample
 * (not necessary if passing values as arguments). To obtain evaluationId,
 * instantiate the client and run the following the commands.
 */
// const parentName = `projects/${project}/locations/${location}/models/${modelId}`;
// const evalRequest = {
//   parent: parentName
// };
// const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest);
// console.log(evalResponse);

// const modelId = 'YOUR_MODEL_ID';
// const evaluationId = 'YOUR_EVALUATION_ID';
// const sliceId = 'YOUR_SLICE_ID';
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';

// Imports the Google Cloud Model Service client library
const {ModelServiceClient} = require('@google-cloud/aiplatform');
// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};
// Specifies the location of the api endpoint
const modelServiceClient = new ModelServiceClient(clientOptions);

async function getModelEvaluationSlice() {
  // Configure the parent resource
  const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}/slices/${sliceId}`;
  const request = {
    name,
  };

  // Get and print out a list of all the endpoints for this resource
  const [response] =
    await modelServiceClient.getModelEvaluationSlice(request);

  console.log('Get model evaluation slice');
  console.log(`\tName : ${response.name}`);
  console.log(`\tMetrics_Schema_Uri : ${response.metricsSchemaUri}`);
  console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`);
  console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`);

  console.log('Slice');
  const slice = response.slice;
  console.log(`\tDimension :${slice.dimension}`);
  console.log(`\tValue :${slice.value}`);
}
getModelEvaluationSlice();

Python

Python をインストールまたは更新する方法については、Vertex AI SDK for Python をインストールするをご覧ください。詳細については、Python API リファレンス ドキュメントをご覧ください。

from google.cloud import aiplatform

def get_model_evaluation_slice_sample(
    project: str,
    model_id: str,
    evaluation_id: str,
    slice_id: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    """
    To obtain evaluation_id run the following commands where LOCATION
    is the region where the model is stored, PROJECT is the project ID,
    and MODEL_ID is the ID of your model.

    model_client = aiplatform.gapic.ModelServiceClient(
        client_options={
            'api_endpoint':'LOCATION-aiplatform.googleapis.com'
            }
        )
    evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID')
    print("evaluations:", evaluations)
    """
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.ModelServiceClient(client_options=client_options)
    name = client.model_evaluation_slice_path(
        project=project,
        location=location,
        model=model_id,
        evaluation=evaluation_id,
        slice=slice_id,
    )
    response = client.get_model_evaluation_slice(name=name)
    print("response:", response)

モデルの反復処理

モデル評価指標は、モデルが期待する条件を満たしていない場合に、モデルをデバッグするための起点となります。たとえば、適合率スコアと再現率スコアが低い場合は、モデルに追加のトレーニング データが必要であるか、ラベルに一貫性がないことを示している可能性があります。適合率と再現率が完璧である場合は、テストデータの予測が容易すぎるか、または一般化が十分でない可能性があります。

トレーニング データを反復修正することにより、新しいモデルを作成できます。新しいモデルを作成した後に、既存のモデルと新しいモデルの評価指標を比較できます。

次に示す提案は、分類モデルや検出モデルなど、項目にラベル付けするモデルを改善するのに役立ちます。

  • トレーニング データのサンプルを追加するか、サンプルの範囲を広げます。詳しいガイダンスについては、データの準備をご覧ください。
  • サンプル数が少ないクラスやラベルを削除します。サンプルの数が少ないと、クラスやラベルに関するモデルの予測が、不確実で一貫性のないものになります。
  • コンピュータはクラス名やラベル名の意味を理解できません。また、「door」と「door_with_knob」のような名前のニュアンスも理解できません。コンピュータがそのようなニュアンスを認識できるようなデータを提供する必要があります。
  • 真陽性と真陰性のサンプルを追加してデータを強化します。特に判定境界に近いサンプルを追加することで、モデルが混同するのを緩和します。
  • 独自のデータ分割(トレーニング、検証、テスト)を指定します。Vertex AI は各セットにアイテムをランダムに割り当てます。そのため、トレーニング セットや検証セットに重複に近いアイテムが割り当てられる可能性があり、過剰適合によってテストセットでのパフォーマンスが低下する可能性があります。独自のデータ分割の設定については、AutoML モデルのデータ分割についてをご覧ください。
  • モデルの評価指標に混同行列が含まれている場合、モデルが 2 つのラベルを混同(特定のラベルを真のラベルより強く予測)していないか確認できます。サンプルに正しいラベルが付けられているかどうか、データを確認してください。
  • トレーニング時間が短い(最大ノード時間数が少ない)場合は、トレーニング時間を長くする(最大ノード時間数を増やす)ことにより、より高品質のモデルが得られる場合があります。