モデルの評価

モデルをトレーニングした後、AutoML Vision Object Detection は TEST セットの画像を使用して、新しいモデルの品質と精度を評価します。

AutoML Vision Object Detection では、モデルが全体的にどの程度的確に機能しているかを示す評価指標(評価プロセスの出力)と、カテゴリラベルごとに、モデルがラベルに対してどの程度的確に機能しているかを示す評価指標の集合体を示します。

評価の概要

評価プロセスの入力

  • IoU しきい値: Intersection over Union。オブジェクト検出で使用される値の 1 つ。オブジェクトの境界ボックスの予想サイズと実際のサイズとの重なりを測定します。予測された境界ボックスの値が実際の境界ボックスの値に近いほど、交差部分と IoU 値が大きいことになります。

  • スコアしきい値: この値よりも低いスコアで予測が返されないことを前提として、出力指標(以下を参照)が計算されます。

評価プロセスの出力

  • AuPRC: 適合率 / 再現率曲線の下の部分の面積で、「平均適合率」とも呼ばれます。通常は、0.5 から 1.0 の間です。値が高いほど、モデルの精度が高いことを示します。

  • 信頼しきい値曲線: さまざまな信頼しきい値が適合率、再現率、真陽性率、偽陽性率にどのように影響するかを示します。適合率と再現率の関係をご覧ください。

  • F1 スコア: 適合率と再現率の調和平均。適合率と再現率のバランスを見る場合に有用な指標です。トレーニング データのクラス分布が均等でない場合にも F1 が役に立ちます。

このデータを使用して、モデルの準備状況を評価します。混同が多い、AUC スコアが低い、または適合率スコアと再現率スコアが低い場合は、モデルに追加のトレーニング データが必要であるか、ラベルに一貫性がないことを示している可能性があります。AUC スコアが非常に高く、適合率と再現率が完璧な場合は、データが単純すぎて適切に一般化できないことを示している可能性があります。AUC の値が高い場合、モデルは理想化されたデータでトレーニングされているため、今後の推定では十分に機能しない可能性があります。

モデル評価の管理

モデル評価のリスト表示

モデルをトレーニングしたら、そのモデルの評価指標を一覧表示できます。

ウェブ UI

  1. AutoML Vision Object Detection UI を開き、左側のナビゲーション バーで電球のアイコンがある [モデル] タブをクリックすると、使用可能なモデルが表示されます。

    別のプロジェクトのモデルを表示するには、タイトルバーの右上にあるプルダウン リストからプロジェクトを選択します。

  2. 評価するモデルの行をクリックします。

  3. 必要に応じて、タイトルバーのすぐ下にある [評価] タブをクリックします。

    モデルのトレーニングが完了すると、AutoML Vision Object Detection の評価指標が表示されます。

    モデル評価ページ

  4. 特定のラベルの指標を表示するには、ページの下部にあるラベルのリストからラベル名を選択します。

    モデル評価ページ固有のラベル

REST

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

  • project-id: GCP プロジェクト ID
  • model-id: モデルを作成したときにレスポンスで返されたモデルの ID。この ID は、モデルの名前の最後の要素です。例:
    • モデル名: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • モデル ID: IOD4412217016962778756

HTTP メソッドと URL:

GET https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID/modelEvaluations

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

curl

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

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID/modelEvaluations"

PowerShell

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

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

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID/modelEvaluations" | Select-Object -Expand Content

次のサンプルのような JSON レスポンスが返されます。わかりやすいように、オブジェクト検出に固有の主要フィールドを太字で示し、boundingBoxMetricsEntries エントリはオブジェクトによって情報量を変えて示しています。



    {
  "modelEvaluation": [
    {
      "name": "projects/project-id/locations/us-central1/models/model-id/modelEvaluations/model-eval-id",
      "annotationSpecId": "6342510834593300480",
      "createTime": "2019-07-26T22:28:56.890727Z",
      "evaluatedExampleCount": 18,
      "imageObjectDetectionEvaluationMetrics": {
        "evaluatedBoundingBoxCount": 96,
        "boundingBoxMetricsEntries": [
          {
            "iouThreshold": 0.15,
            "meanAveragePrecision": 0.6317751,
            "confidenceMetricsEntries": [
              {
                "confidenceThreshold": 0.101631254,
                "recall": 0.84375,
                "precision": 0.2555205,
                "f1Score": 0.3922518
              },
              {
                "confidenceThreshold": 0.10180253,
                "recall": 0.8333333,
                "precision": 0.25316456,
                "f1Score": 0.3883495
              },
              ...
              {
                "confidenceThreshold": 0.8791167,
                "recall": 0.020833334,
                "precision": 1,
                "f1Score": 0.040816326
              },
              {
                "confidenceThreshold": 0.8804436,
                "recall": 0.010416667,
                "precision": 1,
                "f1Score": 0.020618558
              }
            ]
          },
          {
            "iouThreshold": 0.8,
            "meanAveragePrecision": 0.15461995,
            "confidenceMetricsEntries": [
              {
                "confidenceThreshold": 0.101631254,
                "recall": 0.22916667,
                "precision": 0.06940063,
                "f1Score": 0.10653753
              },
              ...
              {
                "confidenceThreshold": 0.8804436,
                "recall": 0.010416667,
                "precision": 1,
                "f1Score": 0.020618558
              }
            ]
          },
          {
            "iouThreshold": 0.4,
            "meanAveragePrecision": 0.56170964,
            "confidenceMetricsEntries": [
              {
                "confidenceThreshold": 0.101631254,
                "recall": 0.7604167,
                "precision": 0.23028392,
                "f1Score": 0.3535109
              },
              ...
              {
                "confidenceThreshold": 0.8804436,
                "recall": 0.010416667,
                "precision": 1,
                "f1Score": 0.020618558
              }
            ]
          },
          ...
        ],
        "boundingBoxMeanAveragePrecision": 0.4306387
      },
      "displayName": "Tomato"
    },
    {
      "name": "projects/project-id/locations/us-central1/models/model-id/modelEvaluations/model-eval-id",
      "annotationSpecId": "1730824816165912576",
      "createTime": "2019-07-26T22:28:56.890727Z",
      "evaluatedExampleCount": 9,
      "imageObjectDetectionEvaluationMetrics": {
        "evaluatedBoundingBoxCount": 51,
        "boundingBoxMetricsEntries": [
          {
            ...
          }
        ],
        "boundingBoxMeanAveragePrecision": 0.29565892
      },
      "displayName": "Cheese"
    },
    {
      "name": "projects/project-id/locations/us-central1/models/model-id/modelEvaluations/model-eval-id",
      "annotationSpecId": "7495432339200147456",
      "createTime": "2019-07-26T22:28:56.890727Z",
      "evaluatedExampleCount": 4,
      "imageObjectDetectionEvaluationMetrics": {
        "evaluatedBoundingBoxCount": 22,
        "boundingBoxMetricsEntries": [
          {
            "iouThreshold": 0.2,
            "meanAveragePrecision": 0.104004614,
            "confidenceMetricsEntries": [
              {
                "confidenceThreshold": 0.1008248,
                "recall": 0.36363637,
                "precision": 0.08888889,
                "f1Score": 0.14285715
              },
              ...
              {
                "confidenceThreshold": 0.47585258,
                "recall": 0.045454547,
                "precision": 1,
                "f1Score": 0.08695653
              }
            ]
          },
          ...
        ],
        "boundingBoxMeanAveragePrecision": 0.057070773
      },
      "displayName": "Seafood"
    }
  ]
}

Go

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。

import (
	"context"
	"fmt"
	"io"

	automl "cloud.google.com/go/automl/apiv1"
	"cloud.google.com/go/automl/apiv1/automlpb"
	"google.golang.org/api/iterator"
)

// listModelEvaluation lists existing model evaluations.
func listModelEvaluations(w io.Writer, projectID string, location string, modelID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// modelID := "TRL123456789..."

	ctx := context.Background()
	client, err := automl.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &automlpb.ListModelEvaluationsRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID),
	}

	it := client.ListModelEvaluations(ctx, req)

	// Iterate over all results
	for {
		evaluation, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("ListModelEvaluations.Next: %w", err)
		}

		fmt.Fprintf(w, "Model evaluation name: %v\n", evaluation.GetName())
		fmt.Fprintf(w, "Model annotation spec id: %v\n", evaluation.GetAnnotationSpecId())
		fmt.Fprintf(w, "Create Time:\n")
		fmt.Fprintf(w, "\tseconds: %v\n", evaluation.GetCreateTime().GetSeconds())
		fmt.Fprintf(w, "\tnanos: %v\n", evaluation.GetCreateTime().GetNanos())
		fmt.Fprintf(w, "Evaluation example count: %v\n", evaluation.GetEvaluatedExampleCount())
		fmt.Fprintf(w, "Object detection model evaluation metrics: %v\n", evaluation.GetImageObjectDetectionEvaluationMetrics())
	}

	return nil
}

Java

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。


import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.ListModelEvaluationsRequest;
import com.google.cloud.automl.v1.ModelEvaluation;
import com.google.cloud.automl.v1.ModelName;
import java.io.IOException;

class ListModelEvaluations {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    listModelEvaluations(projectId, modelId);
  }

  // List model evaluations
  static void listModelEvaluations(String projectId, String modelId) 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.
      ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
      ListModelEvaluationsRequest modelEvaluationsrequest =
          ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();

      // List all the model evaluations in the model by applying filter.
      System.out.println("List of model evaluations:");
      for (ModelEvaluation modelEvaluation :
          client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {

        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(
            "Object Detection Model Evaluation Metrics: %s\n",
            modelEvaluation.getImageObjectDetectionEvaluationMetrics());
      }
    }
  }
}

Node.js

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。

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

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

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

async function listModelEvaluations() {
  // Construct request
  const request = {
    parent: client.modelPath(projectId, location, modelId),
    filter: '',
  };

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

  console.log('List of model evaluations:');
  for (const evaluation of response) {
    console.log(`Model evaluation name: ${evaluation.name}`);
    console.log(`Model annotation spec id: ${evaluation.annotationSpecId}`);
    console.log(`Model display name: ${evaluation.displayName}`);
    console.log('Model create time');
    console.log(`\tseconds ${evaluation.createTime.seconds}`);
    console.log(`\tnanos ${evaluation.createTime.nanos / 1e9}`);
    console.log(
      `Evaluation example count: ${evaluation.evaluatedExampleCount}`
    );
    console.log(
      `Object detection model evaluation metrics: ${evaluation.imageObjectDetectionEvaluationMetrics}`
    );
  }
}

listModelEvaluations();

Python

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。

from google.cloud import automl

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

client = automl.AutoMlClient()
# Get the full path of the model.
model_full_id = client.model_path(project_id, "us-central1", model_id)

print("List of model evaluations:")
for evaluation in client.list_model_evaluations(parent=model_full_id, filter=""):
    print(f"Model evaluation name: {evaluation.name}")
    print(f"Model annotation spec id: {evaluation.annotation_spec_id}")
    print(f"Create Time: {evaluation.create_time}")
    print(f"Evaluation example count: {evaluation.evaluated_example_count}")
    print(
        "Object detection model evaluation metrics: {}\n\n".format(
            evaluation.image_object_detection_evaluation_metrics
        )
    )

その他の言語

C#: クライアント ライブラリ ページの C# の設定手順を行ってから、.NET 用の AutoML Vision Object Detection リファレンス ドキュメントをご覧ください。

PHP: クライアント ライブラリ ページの PHP の設定手順を行ってから、PHP 用の AutoML Vision Object Detection リファレンス ドキュメントをご覧ください。

Ruby: クライアント ライブラリ ページの Ruby の設定手順を行ってから、Ruby 用の AutoML Vision Object Detection リファレンス ドキュメントをご覧ください。

モデル評価の取得

評価 ID を使用して、特定のラベル(displayName)に対するモデル評価を取得することもできます。

ウェブ UI

AutoML Vision Object Detection UI で同様のオペレーションを行うには、[モデル] ページに移動して、モデルを選択します。モデルを選択したら、[評価] タブに移動してラベルを選択し、ラベルごとの評価を確認します。

モデル評価ページ固有のラベル

REST

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

  • project-id: GCP プロジェクト ID
  • model-id: モデルを作成したときにレスポンスで返されたモデルの ID。この ID は、モデルの名前の最後の要素です。例:
    • モデル名: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • モデル ID: IOD4412217016962778756
  • model-evaluation-id: モデル評価の ID 値。モデル評価 ID は、list モデル評価オペレーションから取得できます。

HTTP メソッドと URL:

GET https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID/modelEvaluations/MODEL_EVALUATION_ID

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

curl

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

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID/modelEvaluations/MODEL_EVALUATION_ID"

PowerShell

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

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

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID/modelEvaluations/MODEL_EVALUATION_ID" | Select-Object -Expand Content

次のサンプルのような JSON レスポンスが返されます。わかりやすいように、オブジェクト検出に固有の主要フィールドを太字で示し、boundingBoxMetricsEntries エントリは短縮版を示しています。



    {
  "name": "projects/project-id/locations/us-central1/models/model-id/modelEvaluations/model-evaluation-id",
  "annotationSpecId": "6342510834593300480",
  "createTime": "2019-07-26T22:28:56.890727Z",
  "evaluatedExampleCount": 18,
  "imageObjectDetectionEvaluationMetrics": {
    "evaluatedBoundingBoxCount": 96,
    "boundingBoxMetricsEntries": [
      {
        "iouThreshold": 0.15,
        "meanAveragePrecision": 0.6317751,
        "confidenceMetricsEntries": [
          {
            "confidenceThreshold": 0.101631254,
            "recall": 0.84375,
            "precision": 0.2555205,
            "f1Score": 0.3922518
          },
          ...
          {
            "confidenceThreshold": 0.8804436,
            "recall": 0.010416667,
            "precision": 1,
            "f1Score": 0.020618558
          }
        ]
      },
      {
        "iouThreshold": 0.8,
        "meanAveragePrecision": 0.15461995,
        "confidenceMetricsEntries": [
          {
            "confidenceThreshold": 0.101631254,
            "recall": 0.22916667,
            "precision": 0.06940063,
            "f1Score": 0.10653753
          },
          ...
          {
            "confidenceThreshold": 0.8804436,
            "recall": 0.010416667,
            "precision": 1,
            "f1Score": 0.020618558
          }
        ]
      },
      {
        "iouThreshold": 0.4,
        "meanAveragePrecision": 0.56170964,
        "confidenceMetricsEntries": [
          {
            "confidenceThreshold": 0.101631254,
            "recall": 0.7604167,
            "precision": 0.23028392,
            "f1Score": 0.3535109
          },
          ...
          {
            "confidenceThreshold": 0.8804436,
            "recall": 0.010416667,
            "precision": 1,
            "f1Score": 0.020618558
          }
        ]
      },
      ...
    ],
    "boundingBoxMeanAveragePrecision": 0.4306387
  },
  "displayName": "Tomato"
}

Go

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。

import (
	"context"
	"fmt"
	"io"

	automl "cloud.google.com/go/automl/apiv1"
	"cloud.google.com/go/automl/apiv1/automlpb"
)

// getModelEvaluation gets a model evaluation.
func getModelEvaluation(w io.Writer, projectID string, location string, modelID string, modelEvaluationID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// modelID := "TRL123456789..."
	// modelEvaluationID := "123456789..."

	ctx := context.Background()
	client, err := automl.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &automlpb.GetModelEvaluationRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/models/%s/modelEvaluations/%s", projectID, location, modelID, modelEvaluationID),
	}

	evaluation, err := client.GetModelEvaluation(ctx, req)
	if err != nil {
		return fmt.Errorf("GetModelEvaluation: %w", err)
	}

	fmt.Fprintf(w, "Model evaluation name: %v\n", evaluation.GetName())
	fmt.Fprintf(w, "Model annotation spec id: %v\n", evaluation.GetAnnotationSpecId())
	fmt.Fprintf(w, "Create Time:\n")
	fmt.Fprintf(w, "\tseconds: %v\n", evaluation.GetCreateTime().GetSeconds())
	fmt.Fprintf(w, "\tnanos: %v\n", evaluation.GetCreateTime().GetNanos())
	fmt.Fprintf(w, "Evaluation example count: %v\n", evaluation.GetEvaluatedExampleCount())
	fmt.Fprintf(w, "Object detection model evaluation metrics: %v\n", evaluation.GetImageObjectDetectionEvaluationMetrics())

	return nil
}

Java

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。


import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.ModelEvaluation;
import com.google.cloud.automl.v1.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(
          "Object Detection Model Evaluation Metrics: %s\n",
          modelEvaluation.getImageObjectDetectionEvaluationMetrics());
    }
  }
}

Node.js

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。

/**
 * 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').v1;

// 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(
    `Object detection model evaluation metrics: ${response.imageObjectDetectionEvaluationMetrics}`
  );
}

getModelEvaluation();

Python

このサンプルを試す前に、クライアント ライブラリ ページを参照して、この言語の設定手順を完了してください。

from google.cloud import 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(
    "Object detection model evaluation metrics: {}".format(
        response.image_object_detection_evaluation_metrics
    )
)

その他の言語

C#: クライアント ライブラリ ページの C# の設定手順を行ってから、.NET 用の AutoML Vision Object Detection リファレンス ドキュメントをご覧ください。

PHP: クライアント ライブラリ ページの PHP の設定手順を行ってから、PHP 用の AutoML Vision Object Detection リファレンス ドキュメントをご覧ください。

Ruby: クライアント ライブラリ ページの Ruby の設定手順を行ってから、Ruby 用の AutoML Vision Object Detection リファレンス ドキュメントをご覧ください。

真陽性、偽陰性、偽陽性(UI のみ)

ユーザー インターフェースで、モデル パフォーマンスの特定のサンプルを確認できます。たとえば、TRAINING セットと VALIDATION のセットから真陽性(TP)、偽陰性(FN)、偽陽性(FP)のインスタンスを確認できます。

ウェブ UI

UI で TP、FN、FP ビューにアクセスするには、[評価] タブをクリックして特定のラベルを選択します。

これらの予測の傾向を表示すると、トレーニング セットを変更し、モデルのパフォーマンスを向上させることができます。

真陽性の画像は、モデルが正しくアノテーションを付けたトレーニング済みモデルに提供される検証ボックスです。

真陽性の表示

偽陰性の画像もトレーニング済みモデルに提供されますが、モデルはオブジェクトのインスタンスに正確なアノテーションを付けていません。

偽陰性の表示

偽陽性の画像は、オブジェクトのインスタンスにアノテーションを付けているトレーニング済みモデルに提供されますが、指定した領域にはアノテーションが付いていません。

偽陽性の表示

このモデルでは、めったにない面白いケースを選択していますが、これらを参考に定義とラベルを調整すれば、モデルによるラベルの解釈の理解度を向上させることができるでしょう。たとえば、より厳密な定義を与えて、ピーマンの詰めものを「サラダ」と認識するべきかどうかモデルに理解させることができます。ラベル、トレーニング、評価のループを繰り返すことで、データに存在する別のあいまいさが表面化することがあります。

また、ユーザー インターフェースのこのビューでスコアしきい値を調整すると、表示されている TP、FN、FP の各画像にしきい値の変化が反映されます。

しきい値を更新した後の真陽性

評価指標の解釈

オブジェクト検出モデルは、入力画像に多くの境界ボックスを出力します。各ボックスには、1)ラベルと 2)スコアまたは信頼度が付いています。評価指標は、モデルに関する次の重要なパフォーマンスを調べる際に役立ちます。

  • ボックスの数が適切かどうか。
  • 境界ケースに対してモデルが低いスコアを出す傾向にあるかどうか。
  • 予測ボックスと正解ボックスの違いはどのくらいか。

マルチラベル分類と同様に、これらの指標では一般的な低スコア以外のクラスの混同はわかりません。

画像ごとにモデルの出力を調べる場合は、ボックスのペア(正解ボックスと予測されたボックス)を調べて、一致の程度を確認する必要があります。次の点を考慮する必要があります。

  • 両方のボックスに同じラベルが付いているか。
  • ボックスがどのくらい重なっているか。
  • モデルがボックスを予測した信頼度はどのくらいか。

2 番目の要件に対応するため、IoUintersection-over-union)という新しい測定値を導入しました。

IoU と IoU しきい値

ボックス全体とボックスの交差部分の表示

IoU は 2 つのボックスの一致度を示します。IoU の値は 0(重なりなし)から 1(完全に一致)です。この値は、2 つのボックスの共通領域をいずれかのボックスに含まれている領域の合計で割って計算します。AutoML サービスでは、IoU しきい値をいくつか見てモデルのパフォーマンスを調べることができます。

IoU しきい値を変更する理由

駐車場で自動車の台数を数える場合について考えてみましょう。ボックスの座標が正確であるかを気にする必要はありません。ここでは、ボックスの合計数が正しいかどうかが問題です。このケースでは IoU しきい値を低く設定します。

低いしきい値を設定した場合に車を囲む境界ボックス
画像クレジット: Nacho、"Smart"CC BY 2.0、境界ボックスとテキストを追加)。

次に、布の汚れの大きさを測定してみましょう。ここでは、正確な座標が必要になるため、IoU しきい値を高く設定します。

高いしきい値を設定した場合に汚れを囲む境界ボックス
画像クレジット: Housing Works Thrift Shops、"Modern Sofa"CC BY-SA 2.0、境界ボックスとテキストを追加)

ユースケースに適切なしきい値について考えが変わった場合でも、すでにさまざまな IoU しきい値の評価指標を利用できるのでモデルのトレーニングをやり直す必要はありません

スコアとスコアのしきい値

分類モデルと同様に、オブジェクト検出モデルの出力(ボックス)にもスコアが付いています。画像分類と同様に、スコアにもトレーニング後に指定できるしきい値があります。このしきい値により、「適切な」一致とみなすレベルを設定できます。スコアしきい値を変更すると、特定のモデルのニーズに合わせて、偽陽性率と真陽性率を調整できます。通常、再現率を非常に高くしたい場合は、モデルの出力処理で低めのスコアしきい値を使用します。

モデルの反復

品質水準に不満がある場合は、前のステップに戻って品質を向上させることができます。

  • 境界ボックスの品質が低いラベルには、画像を追加することを検討してください。
  • さまざまなタイプの画像を追加しなければならない場合があります(たとえば、構図の拡大、解像度の増減、異なる視点など)。
  • 十分なトレーニング画像がない場合は、境界ボックスのラベルも削除してください。
  • このトレーニング アルゴリズムではラベル名を使用しません。「door」というラベルと「door_with_knob」という別のラベルがある場合、このアルゴリズムでは、そのラベルが付いた画像以外にニュアンスを把握する方法はありません。
  • 真陽性と真陰性のサンプルを追加してデータを強化してください。特に重要なサンプルは、意思決定の境界に近いものです(混同を招く可能性があるが、正しくラベル付けされているもの)。
  • 独自の TRAIN、TEST、VALIDATE の分割を指定してください。ツールは画像をランダムに割り当てますが、割り当てが重複に近い場合は TRAIN と VALIDATE の過学習につながり、TEST セットのパフォーマンスが低下する可能性があります。

変更が完了したら、十分に高い品質水準に達するまで、モデルをトレーニングして評価します。