モデルの管理

このページでは、AutoML Tables を使用してカスタムモデルのデプロイ、デプロイ解除、一覧表示、削除、情報の取得を行う方法について説明します。

新しいモデルのトレーニングについては、モデルのトレーニングをご覧ください。

モデルのデプロイ

モデルのトレーニングが済んだら、そのモデルを使用してオンライン予測をリクエストする前にモデルをデプロイする必要があります。バッチ予測は、デプロイされていないモデルからリクエストできます。

モデルのデプロイには料金が発生します。詳細については、料金のページをご覧ください。

Console

  1. Google Cloud Console で [AutoML テーブル] ページに移動します。

    [AutoML テーブル] ページに移動

  2. 左側のナビゲーション パネルで [モデル] タブを選択し、[リージョン] を選択します。

  3. デプロイするモデルの [その他の操作] メニューで、[モデルのデプロイ] をクリックします。

    デプロイメントの [その他の操作] メニュー

REST

モデルをデプロイするには、models.deploy メソッドを使用します。

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

  • endpoint: グローバル ロケーションの場合は automl.googleapis.com、EU リージョンの場合は eu-automl.googleapis.com
  • project-id: Google Cloud プロジェクト ID
  • location:リソースのロケーション:グローバルの場合はus-central1、EUの場合はeu
  • model-id: デプロイするモデルの ID。例: TBL543

HTTP メソッドと URL:

POST https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:deploy

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

curl

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

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:deploy"

PowerShell

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

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:deploy" | Select-Object -Expand Content

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

{
  "name": "projects/292381/locations/us-central1/operations/TBL543",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "createTime": "2019-12-26T19:21:00.550021Z",
    "updateTime": "2019-12-26T19:21:00.550021Z",
    "worksOn": [
      "projects/292381/locations/us-central1/models/TBL543"
    ],
    "deployModelDetails": {},
    "state": "RUNNING"
  }
}

モデルのデプロイは長時間実行オペレーションです。オペレーションのステータスをポーリングするか、オペレーションが完了するまで待つことができます。詳細

Java

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.DeployModelRequest;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.cloud.automl.v1beta1.OperationMetadata;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

class DeployModel {

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

  // Deploy a model for prediction
  static void deployModel(String projectId, String modelId)
      throws IOException, ExecutionException, InterruptedException {
    // 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);
      DeployModelRequest request =
          DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
      OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);

      future.get();
      System.out.println("Model deployment finished");
    }
  }
}

Node.js

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

const automl = require('@google-cloud/automl');
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to deploy model.
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Deploy a model with the deploy model request.
client
  .deployModel({name: modelFullId})
  .then(responses => {
    const response = responses[0];
    console.log('Deployment Details:');
    console.log(`\tName: ${response.name}`);
    console.log('\tMetadata:');
    console.log(`\t\tType Url: ${response.metadata.typeUrl}`);
    console.log(`\tDone: ${response.done}`);
  })
  .catch(err => {
    console.error(err);
  });

Python

AutoML Tables のクライアント ライブラリには、AutoML Tables API を簡単に使用できるようにする追加の Python メソッドが含まれています。これらのメソッドは、ID ではなく名前でデータセットとモデルを参照します。データセット名とモデル名は一意である必要があります。詳細については、クライアント リファレンスをご覧ください。

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_display_name = 'MODEL_DISPLAY_NAME_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# Deploy model
response = client.deploy_model(model_display_name=model_display_name)

# synchronous check of operation status.
print(f"Model deployed. {response.result()}")

モデルのデプロイ解除

オンライン予測をリクエストするには、まずモデルをデプロイする必要があります。オンライン予測にモデルが不要になった場合は、モデルのデプロイを解除すると、デプロイ料金の発生を防ぐことができます。

デプロイ料金の詳細については、料金のページをご覧ください。

Console

  1. Google Cloud Console で [AutoML テーブル] ページに移動します。

    [AutoML テーブル] ページに移動

  2. 左側のナビゲーション パネルで [モデル] タブを選択し、[リージョン] を選択します。

  3. デプロイ解除するモデルの [その他の操作] メニューで、[デプロイメントを削除] をクリックします。

    [デプロイメントを削除] が表示された [その他の操作] メニュー

REST

モデルをデプロイ解除するには、models.undeploy メソッドを使用します。

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

  • endpoint: グローバル ロケーションの場合は automl.googleapis.com、EU リージョンの場合は eu-automl.googleapis.com
  • project-id: Google Cloud プロジェクト ID
  • location:リソースのロケーション:グローバルの場合はus-central1、EUの場合はeu
  • model-id: デプロイ解除するモデルの ID。例: TBL543

HTTP メソッドと URL:

POST https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:undeploy

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

curl

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

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:undeploy"

PowerShell

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

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:undeploy" | Select-Object -Expand Content

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

{
  "name": "projects/292381/locations/us-central1/operations/TBL543",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "createTime": "2019-12-26T19:19:21.579163Z",
    "updateTime": "2019-12-26T19:19:21.579163Z",
    "worksOn": [
      "projects/292381/locations/us-central1/models/TBL543"
    ],
    "undeployModelDetails": {},
    "state": "RUNNING"
  }
}

Java

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.cloud.automl.v1beta1.OperationMetadata;
import com.google.cloud.automl.v1beta1.UndeployModelRequest;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

class UndeployModel {

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

  // Undeploy a model from prediction
  static void undeployModel(String projectId, String modelId)
      throws IOException, ExecutionException, InterruptedException {
    // 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);
      UndeployModelRequest request =
          UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
      OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(request);

      future.get();
      System.out.println("Model undeployment finished");
    }
  }
}

Node.js

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

const automl = require('@google-cloud/automl');
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to undelpoy model.
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Undeploy a model with the undeploy model request.
client
  .undeployModel({name: modelFullId})
  .then(responses => {
    const response = responses[0];
    console.log('Undeployment Details:');
    console.log(`\tName: ${response.name}`);
    console.log('\tMetadata:');
    console.log(`\t\tType Url: ${response.metadata.typeUrl}`);
    console.log(`\tDone: ${response.done}`);
  })
  .catch(err => {
    console.error(err);
  });

Python

AutoML Tables のクライアント ライブラリには、AutoML Tables API を簡単に使用できるようにする追加の Python メソッドが含まれています。これらのメソッドは、ID ではなく名前でデータセットとモデルを参照します。データセット名とモデル名は一意である必要があります。詳細については、クライアント リファレンスをご覧ください。

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_display_name = 'MODEL_DISPLAY_NAME_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# Undeploy model
response = client.undeploy_model(model_display_name=model_display_name)

# synchronous check of operation status.
print(f"Model undeployed. {response.result()}")

モデルに関する情報の取得

トレーニングが完了したら、新しく作成したモデルに関する情報を取得できます。

Console

  1. Google Cloud Console で [AutoML テーブル] ページに移動します。

    [AutoML テーブル] ページに移動

  2. 左側のナビゲーション パネルで [モデル] タブを選択して、情報を表示するモデルを選択します。

  3. [トレーニング] タブを選択します。

    モデルの主な指標(精度や再現率など)を確認できます。

    トレーニング済みモデルの主な指標

    モデルの品質の評価については、モデルの評価をご覧ください。

REST

モデルに関する情報を取得するには、models.get メソッドを使用します。

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

  • endpoint: グローバル ロケーションの場合は automl.googleapis.com、EU リージョンの場合は eu-automl.googleapis.com
  • project-id: Google Cloud プロジェクト ID
  • location:リソースのロケーション:グローバルの場合はus-central1、EUの場合はeu
  • model-id: 情報を取得する対象のモデルの ID。例: TBL543

HTTP メソッドと URL:

GET https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id

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

curl

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

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://endpoint/v1beta1/projects/project-id/locations/location/models/model-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://endpoint/v1beta1/projects/project-id/locations/location/models/model-id" | Select-Object -Expand Content

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

Java

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細


import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.Model;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.cloud.automl.v1beta1.TablesModelColumnInfo;
import io.grpc.StatusRuntimeException;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class TablesGetModel {

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

  // Demonstrates using the AutoML client to get model details.
  public static void getModel(String projectId, String computeRegion, String modelId)
      throws IOException, StatusRuntimeException {
    // 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, computeRegion, modelId);

      // Get complete detail of the model.
      Model model = client.getModel(modelFullId);

      // Display the model information.
      System.out.format("Model name: %s%n", model.getName());
      System.out.format(
          "Model Id: %s\n", model.getName().split("/")[model.getName().split("/").length - 1]);
      System.out.format("Model display name: %s%n", model.getDisplayName());
      System.out.format("Dataset Id: %s%n", model.getDatasetId());
      System.out.println("Tables Model Metadata: ");
      System.out.format(
          "\tTraining budget: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());
      System.out.format(
          "\tTraining cost: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());

      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
      String createTime =
          dateFormat.format(new java.util.Date(model.getCreateTime().getSeconds() * 1000));
      System.out.format("Model create time: %s%n", createTime);

      System.out.format("Model deployment state: %s%n", model.getDeploymentState());

      // Get features of top importance
      for (TablesModelColumnInfo info :
          model.getTablesModelMetadata().getTablesModelColumnInfoList()) {
        System.out.format(
            "Column: %s - Importance: %.2f%n",
            info.getColumnDisplayName(), info.getFeatureImportance());
      }
    }
  }
}

Node.js

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

const automl = require('@google-cloud/automl');
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to get model details.
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Get complete detail of the model.
client
  .getModel({name: modelFullId})
  .then(responses => {
    const model = responses[0];

    // Display the model information.
    console.log(`Model name: ${model.name}`);
    console.log(`Model Id: ${model.name.split('/').pop(-1)}`);
    console.log(`Model display name: ${model.displayName}`);
    console.log(`Dataset Id: ${model.datasetId}`);
    console.log('Tables model metadata: ');
    console.log(
      `\tTraining budget: ${model.tablesModelMetadata.trainBudgetMilliNodeHours}`
    );
    console.log(
      `\tTraining cost: ${model.tablesModelMetadata.trainCostMilliNodeHours}`
    );
    console.log(`Model deployment state: ${model.deploymentState}`);
  })
  .catch(err => {
    console.error(err);
  });

Python

AutoML Tables のクライアント ライブラリには、AutoML Tables API を簡単に使用できるようにする追加の Python メソッドが含まれています。これらのメソッドは、ID ではなく名前でデータセットとモデルを参照します。データセット名とモデル名は一意である必要があります。詳細については、クライアント リファレンスをご覧ください。

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_display_name = 'MODEL_DISPLAY_NAME_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# Get complete detail of the model.
model = client.get_model(model_display_name=model_display_name)

# Retrieve deployment state.
if model.deployment_state == automl.Model.DeploymentState.DEPLOYED:
    deployment_state = "deployed"
else:
    deployment_state = "undeployed"

# get features of top importance
feat_list = [
    (column.feature_importance, column.column_display_name)
    for column in model.tables_model_metadata.tables_model_column_info
]
feat_list.sort(reverse=True)
if len(feat_list) < 10:
    feat_to_show = len(feat_list)
else:
    feat_to_show = 10

# Display the model information.
print(f"Model name: {model.name}")
print("Model id: {}".format(model.name.split("/")[-1]))
print(f"Model display name: {model.display_name}")
print("Features of top importance:")
for feat in feat_list[:feat_to_show]:
    print(feat)
print(f"Model create time: {model.create_time}")
print(f"Model deployment state: {deployment_state}")

モデルの一覧表示

1 つのプロジェクトに、同じデータセットまたは異なるデータセットからトレーニングされた多数のモデルが含まれる場合があります。

Console

Google Cloud コンソール を使用して使用可能なモデルのリストを表示するには、左側のナビゲーション バーで [モデル] タブをクリックし、[リージョン] を選択します。

REST

API を使用して使用可能なモデルのリストを表示するには、models.list メソッドを使用します。

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

  • endpoint: グローバル ロケーションの場合は automl.googleapis.com、EU リージョンの場合は eu-automl.googleapis.com
  • project-id: Google Cloud プロジェクト ID
  • location:リソースのロケーション:グローバルの場合はus-central1、EUの場合はeu

HTTP メソッドと URL:

GET https://endpoint/v1beta1/projects/project-id/locations/location/models

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

curl

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

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://endpoint/v1beta1/projects/project-id/locations/location/models"

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://endpoint/v1beta1/projects/project-id/locations/location/models" | Select-Object -Expand Content
このメソッドでは、選択したロケーションとプロジェクトのすべてのモデルのモデル オブジェクト全体が返されます。

Java

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.ListModelsRequest;
import com.google.cloud.automl.v1beta1.LocationName;
import com.google.cloud.automl.v1beta1.Model;
import java.io.IOException;

class ListModels {

  static void listModels() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    listModels(projectId);
  }

  // List the models available in the specified location
  static void listModels(String projectId) 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()) {
      // A resource that represents Google Cloud Platform location.
      LocationName projectLocation = LocationName.of(projectId, "us-central1");

      // Create list models request.
      ListModelsRequest listModelsRequest =
          ListModelsRequest.newBuilder()
              .setParent(projectLocation.toString())
              .setFilter("")
              .build();

      // List all the models available in the region by applying filter.
      System.out.println("List of models:");
      for (Model model : client.listModels(listModelsRequest).iterateAll()) {
        // Display the model information.
        System.out.format("Model name: %s%n", model.getName());
        // To get the model id, you have to parse it out of the `name` field. As models Ids are
        // required for other methods.
        // Name Format: `projects/{project_id}/locations/{location_id}/models/{model_id}`
        String[] names = model.getName().split("/");
        String retrievedModelId = names[names.length - 1];
        System.out.format("Model id: %s%n", retrievedModelId);
        System.out.format("Model display name: %s%n", model.getDisplayName());
        System.out.println("Model create time:");
        System.out.format("\tseconds: %s%n", model.getCreateTime().getSeconds());
        System.out.format("\tnanos: %s%n", model.getCreateTime().getNanos());
        System.out.format("Model deployment state: %s%n", model.getDeploymentState());
      }
    }
  }
}

Node.js

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

const automl = require('@google-cloud/automl');
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to list all models.
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const filter_ = '[FILTER_EXPRESSIONS]' e.g., "tablesModelMetadata:*";

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// List all the models available in the region by applying filter.
client
  .listModels({parent: projectLocation, filter: filter})
  .then(responses => {
    const model = responses[0];

    // Display the model information.
    console.log('List of models:');
    for (let i = 0; i < model.length; i++) {
      console.log(`\nModel name: ${model[i].name}`);
      console.log(`Model Id: ${model[i].name.split('/').pop(-1)}`);
      console.log(`Model display name: ${model[i].displayName}`);
      console.log(`Dataset Id: ${model[i].datasetId}`);
      console.log('Tables model metadata:');
      console.log(
        `\tTraining budget: ${model[i].tablesModelMetadata.trainBudgetMilliNodeHours}`
      );
      console.log(
        `\tTraining cost: ${model[i].tablesModelMetadata.trainCostMilliNodeHours}`
      );
      console.log(`Model deployment state: ${model[i].deploymentState}`);
    }
  })
  .catch(err => {
    console.error(err);
  });

Python

AutoML Tables のクライアント ライブラリには、AutoML Tables API を簡単に使用できるようにする追加の Python メソッドが含まれています。これらのメソッドは、ID ではなく名前でデータセットとモデルを参照します。データセット名とモデル名は一意である必要があります。詳細については、クライアント リファレンスをご覧ください。

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# filter = 'DATASET_DISPLAY_NAME_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# List all the models available in the region by applying filter.
response = client.list_models(filter=filter)

print("List of models:")
for model in response:
    # Retrieve deployment state.
    if model.deployment_state == automl.Model.DeploymentState.DEPLOYED:
        deployment_state = "deployed"
    else:
        deployment_state = "undeployed"

    # Display the model information.
    print(f"Model name: {model.name}")
    print("Model id: {}".format(model.name.split("/")[-1]))
    print(f"Model display name: {model.display_name}")
    metadata = model.tables_model_metadata
    print(
        "Target column display name: {}".format(
            metadata.target_column_spec.display_name
        )
    )
    print(
        "Training budget in node milli hours: {}".format(
            metadata.train_budget_milli_node_hours
        )
    )
    print(
        "Training cost in node milli hours: {}".format(
            metadata.train_cost_milli_node_hours
        )
    )
    print(f"Model create time: {model.create_time}")
    print(f"Model deployment state: {deployment_state}")
    print("\n")

モデルの削除

モデルを削除すると、プロジェクトから完全に削除されます。

Console

  1. AutoML Tables UI で左側のナビゲーション メニューの [モデル] タブをクリックし、[リージョン] をクリックして、そのリージョンで使用できるモデルのリストを表示します。

  2. 削除する行の右端にあるその他メニューをクリックし、[モデルを削除] を選択します。

  3. 確認ダイアログ ボックスで [削除] をクリックします。

REST

モデルを削除するには、models.delete メソッドを使用します。

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

  • endpoint: グローバル ロケーションの場合は automl.googleapis.com、EU リージョンの場合は eu-automl.googleapis.com
  • project-id: Google Cloud プロジェクト ID
  • location:リソースのロケーション:グローバルの場合はus-central1、EUの場合はeu
  • model-id: 削除するモデルの ID。例: TBL543

HTTP メソッドと URL:

DELETE https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id

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

curl

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

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id"

PowerShell

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

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

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id" | Select-Object -Expand Content

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

{
  "name": "projects/29452381/locations/us-central1/operations/TBL543",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "createTime": "2019-12-26T17:19:50.684850Z",
    "updateTime": "2019-12-26T17:19:50.684850Z",
    "deleteDetails": {},
    "worksOn": [
      "projects/29452381/locations/us-central1/models/TBL543"
    ],
    "state": "DONE"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.protobuf.Empty"
  }
}

モデルの削除は長時間実行オペレーションです。オペレーションのステータスをポーリングするか、オペレーションが完了するまで待つことができます。詳細

Java

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

class DeleteModel {

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

  // Delete a model
  static void deleteModel(String projectId, String modelId)
      throws IOException, ExecutionException, InterruptedException {
    // 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);

      // Delete a model.
      Empty response = client.deleteModelAsync(modelFullId).get();

      System.out.println("Model deletion started...");
      System.out.println(String.format("Model deleted. %s", response));
    }
  }
}

Node.js

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

const automl = require('@google-cloud/automl');
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to delete a model.
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Delete a model.
client
  .deleteModel({name: modelFullId})
  .then(responses => {
    const operation = responses[0];
    return operation.promise();
  })
  .then(responses => {
    // The final result of the operation.
    const operationDetails = responses[2];

    // Get the Model delete details.
    console.log('Model delete details:');
    console.log('\tOperation details:');
    console.log(`\t\tName: ${operationDetails.name}`);
    console.log(`\tDone: ${operationDetails.done}`);
  })
  .catch(err => {
    console.error(err);
  });

Python

AutoML Tables のクライアント ライブラリには、AutoML Tables API を簡単に使用できるようにする追加の Python メソッドが含まれています。これらのメソッドは、ID ではなく名前でデータセットとモデルを参照します。データセット名とモデル名は一意である必要があります。詳細については、クライアント リファレンスをご覧ください。

リソースが EU リージョンにある場合は、エンドポイントを明示的に設定する必要があります。詳細

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_display_name = 'MODEL_DISPLAY_NAME_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# Undeploy model
response = client.delete_model(model_display_name=model_display_name)

# synchronous check of operation status.
print(f"Model deleted. {response.result()}")

次のステップ