AutoML Edge モデルをエクスポートする

このページでは、Vertex AI を使用して画像および動画の AutoML Edge モデルを Cloud Storage にエクスポートする方法について説明します。

表形式のモデルのエクスポートについては、AutoML 表形式のモデルのエクスポートをご覧ください。

はじめに

AutoML Edge モデルをトレーニングした後、そのモデルの用途に応じて異なる形式でモデルをエクスポートできます。エクスポートされたモデルファイルは Cloud Storage バケットに保存され、選択した環境で予測に使用できます。

予測の提供に Vertex AI の Edge モデルを使用することはできません。予測を取得するには、Edge モデルを外部デバイスにデプロイする必要があります。

モデルをエクスポートする

次のサンプルコードを使用して、AutoML Edge モデルを識別し、出力ファイルの保存場所を指定してモデル エクスポート リクエストを送信します。

画像

目標に応じて以下のタブを選択してください。

分類

トレーニング済みの AutoML Edge 画像分類モデルは、次の形式でエクスポートできます。

  • TF Lite - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
  • Edge TPU TF Lite - Edge TPU デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
  • コンテナ - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
  • Core ML - iOS デバイスや macOS デバイスでモデルを実行するため、.mlmodel ファイルをエクスポートします。
  • Tensorflow.js - ブラウザと Node.js でモデルを実行するため、モデルを TensorFlow.js パッケージとしてエクスポートします。

お使いの言語または環境に応じて、以下のタブを選択してください。

コンソール

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

    [モデル] ページに移動

  2. エクスポートする AutoML Edge モデルのバージョン番号をクリックして、詳細ページを開きます。
  3. [エクスポート] をクリックします。
  4. [モデルをエクスポート] サイド ウィンドウで、Edge モデルのエクスポート出力を保存する Cloud Storage 内の場所を指定します。
  5. [エクスポート] をクリックします。
  6. [完了] をクリックして、[モデルをエクスポート] サイド ウィンドウを閉じます。

REST

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

  • LOCATION: 実際のプロジェクトのロケーション。
  • PROJECT: 実際のプロジェクト ID
  • MODEL_ID: エクスポートするトレーニング済みの AutoML Edge モデルの ID 番号。
  • EXPORT_FORMAT: エクスポートする Edge モデルのタイプ。この目標の場合は、次のオプションがあります。
    • tflite(TF Lite) - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
    • edgetpu-tflite(Edge TPU TF Lite) - Edge TPU デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
    • tf-saved-model(コンテナ) - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
    • core-ml(Core ML) - iOS デバイスや macOS デバイスでモデルを実行するため、.mlmodel ファイルをエクスポートします。
    • tf-js(Tensorflow.js) - ブラウザと Node.js でモデルを実行するため、モデルを TensorFlow.js パッケージとしてエクスポートします。
  • OUTPUT_BUCKET: Edge モデルファイルを保存する Cloud Storage バケット ディレクトリのパス。
  • HTTP メソッドと URL:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export

    リクエストの本文(JSON):

    {
      "outputConfig": {
        "exportFormatId": "EXPORT_FORMAT",
        "artifactDestination": {
          "outputUriPrefix": "gs://OUTPUT_BUCKET/"
        }
      }
    }
    

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

    curl

    リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export"

    PowerShell

    リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export" | Select-Object -Expand Content

    レスポンスには、仕様と OPERATION_ID に関する情報が含まれています。

    エクスポート オペレーションのステータスを取得して、終了時間を確認できます。

Java

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

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


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.ExportModelOperationMetadata;
import com.google.cloud.aiplatform.v1.ExportModelRequest;
import com.google.cloud.aiplatform.v1.ExportModelResponse;
import com.google.cloud.aiplatform.v1.GcsDestination;
import com.google.cloud.aiplatform.v1.ModelName;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ExportModelSample {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String gcsDestinationOutputUriPrefix = "gs://YOUR_GCS_SOURCE_BUCKET/path_to_your_destination/";
    String exportFormat = "YOUR_EXPORT_FORMAT";
    exportModelSample(project, modelId, gcsDestinationOutputUriPrefix, exportFormat);
  }

  static void exportModelSample(
      String project, String modelId, String gcsDestinationOutputUriPrefix, String exportFormat)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    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";
      GcsDestination.Builder gcsDestination = GcsDestination.newBuilder();
      gcsDestination.setOutputUriPrefix(gcsDestinationOutputUriPrefix);

      ModelName modelName = ModelName.of(project, location, modelId);
      ExportModelRequest.OutputConfig outputConfig =
          ExportModelRequest.OutputConfig.newBuilder()
              .setExportFormatId(exportFormat)
              .setArtifactDestination(gcsDestination)
              .build();

      OperationFuture<ExportModelResponse, ExportModelOperationMetadata> exportModelResponseFuture =
          modelServiceClient.exportModelAsync(modelName, outputConfig);
      System.out.format(
          "Operation name: %s\n", exportModelResponseFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      ExportModelResponse exportModelResponse =
          exportModelResponseFuture.get(300, TimeUnit.SECONDS);

      System.out.format("Export Model Response: %s\n", exportModelResponse);
    }
  }
}

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)
 */

// const modelId = 'YOUR_MODEL_ID';
// const gcsDestinationOutputUriPrefix ='YOUR_GCS_DEST_OUTPUT_URI_PREFIX';
//    eg. "gs://<your-gcs-bucket>/destination_path"
// const exportFormat = 'YOUR_EXPORT_FORMAT';
// 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 exportModel() {
  // Configure the name resources
  const name = `projects/${project}/locations/${location}/models/${modelId}`;
  // Configure the outputConfig resources
  const outputConfig = {
    exportFormatId: exportFormat,
    gcsDestination: {
      outputUriPrefix: gcsDestinationOutputUriPrefix,
    },
  };
  const request = {
    name,
    outputConfig,
  };

  // Export Model request
  const [response] = await modelServiceClient.exportModel(request);
  console.log(`Long running operation : ${response.name}`);

  // Wait for operation to complete
  await response.promise();
  const result = response.result;

  console.log(`Export model response : ${JSON.stringify(result)}`);
}
exportModel();

Python

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

from google.cloud import aiplatform

def export_model_sample(
    project: str,
    model_id: str,
    gcs_destination_output_uri_prefix: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 300,
):
    # 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)
    output_config = {
        "artifact_destination": {
            "output_uri_prefix": gcs_destination_output_uri_prefix
        },
        # For information about export formats: https://cloud.google.com/ai-platform-unified/docs/export/export-edge-model#aiplatform_export_model_sample-drest
        "export_format_id": "tf-saved-model",
    }
    name = client.model_path(project=project, location=location, model=model_id)
    response = client.export_model(name=name, output_config=output_config)
    print("Long running operation:", response.operation.name)
    print("output_info:", response.metadata.output_info)
    export_model_response = response.result(timeout=timeout)
    print("export_model_response:", export_model_response)

分類

トレーニング済みの AutoML Edge 画像分類モデルは、次の形式でエクスポートできます。

  • TF Lite - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
  • Edge TPU TF Lite - Edge TPU デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
  • コンテナ - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
  • Core ML - iOS デバイスや macOS デバイスでモデルを実行するため、.mlmodel ファイルをエクスポートします。
  • Tensorflow.js - ブラウザと Node.js でモデルを実行するため、モデルを TensorFlow.js パッケージとしてエクスポートします。

お使いの言語または環境に応じて、以下のタブを選択してください。

コンソール

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

    [モデル] ページに移動

  2. エクスポートする AutoML Edge モデルのバージョン番号をクリックして、詳細ページを開きます。
  3. [エクスポート] をクリックします。
  4. [モデルをエクスポート] サイド ウィンドウで、Edge モデルのエクスポート出力を保存する Cloud Storage 内の場所を指定します。
  5. [エクスポート] をクリックします。
  6. [完了] をクリックして、[モデルをエクスポート] サイド ウィンドウを閉じます。

REST

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

  • LOCATION: 実際のプロジェクトのロケーション。
  • PROJECT: 実際のプロジェクト ID
  • MODEL_ID: エクスポートするトレーニング済みの AutoML Edge モデルの ID 番号。
  • EXPORT_FORMAT: エクスポートする Edge モデルのタイプ。この目標の場合は、次のオプションがあります。
    • tflite(TF Lite) - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
    • edgetpu-tflite(Edge TPU TF Lite) - Edge TPU デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
    • tf-saved-model(コンテナ) - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
    • core-ml(Core ML) - iOS デバイスや macOS デバイスでモデルを実行するため、.mlmodel ファイルをエクスポートします。
    • tf-js(Tensorflow.js) - ブラウザと Node.js でモデルを実行するため、モデルを TensorFlow.js パッケージとしてエクスポートします。
  • OUTPUT_BUCKET: Edge モデルファイルを保存する Cloud Storage バケット ディレクトリのパス。
  • HTTP メソッドと URL:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export

    リクエストの本文(JSON):

    {
      "outputConfig": {
        "exportFormatId": "EXPORT_FORMAT",
        "artifactDestination": {
          "outputUriPrefix": "gs://OUTPUT_BUCKET/"
        }
      }
    }
    

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

    curl

    リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export"

    PowerShell

    リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export" | Select-Object -Expand Content

    レスポンスには、仕様と OPERATION_ID に関する情報が含まれています。

    エクスポート オペレーションのステータスを取得して、終了時間を確認できます。

Java

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

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


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.ExportModelOperationMetadata;
import com.google.cloud.aiplatform.v1.ExportModelRequest;
import com.google.cloud.aiplatform.v1.ExportModelResponse;
import com.google.cloud.aiplatform.v1.GcsDestination;
import com.google.cloud.aiplatform.v1.ModelName;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ExportModelSample {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String gcsDestinationOutputUriPrefix = "gs://YOUR_GCS_SOURCE_BUCKET/path_to_your_destination/";
    String exportFormat = "YOUR_EXPORT_FORMAT";
    exportModelSample(project, modelId, gcsDestinationOutputUriPrefix, exportFormat);
  }

  static void exportModelSample(
      String project, String modelId, String gcsDestinationOutputUriPrefix, String exportFormat)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    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";
      GcsDestination.Builder gcsDestination = GcsDestination.newBuilder();
      gcsDestination.setOutputUriPrefix(gcsDestinationOutputUriPrefix);

      ModelName modelName = ModelName.of(project, location, modelId);
      ExportModelRequest.OutputConfig outputConfig =
          ExportModelRequest.OutputConfig.newBuilder()
              .setExportFormatId(exportFormat)
              .setArtifactDestination(gcsDestination)
              .build();

      OperationFuture<ExportModelResponse, ExportModelOperationMetadata> exportModelResponseFuture =
          modelServiceClient.exportModelAsync(modelName, outputConfig);
      System.out.format(
          "Operation name: %s\n", exportModelResponseFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      ExportModelResponse exportModelResponse =
          exportModelResponseFuture.get(300, TimeUnit.SECONDS);

      System.out.format("Export Model Response: %s\n", exportModelResponse);
    }
  }
}

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)
 */

// const modelId = 'YOUR_MODEL_ID';
// const gcsDestinationOutputUriPrefix ='YOUR_GCS_DEST_OUTPUT_URI_PREFIX';
//    eg. "gs://<your-gcs-bucket>/destination_path"
// const exportFormat = 'YOUR_EXPORT_FORMAT';
// 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 exportModel() {
  // Configure the name resources
  const name = `projects/${project}/locations/${location}/models/${modelId}`;
  // Configure the outputConfig resources
  const outputConfig = {
    exportFormatId: exportFormat,
    gcsDestination: {
      outputUriPrefix: gcsDestinationOutputUriPrefix,
    },
  };
  const request = {
    name,
    outputConfig,
  };

  // Export Model request
  const [response] = await modelServiceClient.exportModel(request);
  console.log(`Long running operation : ${response.name}`);

  // Wait for operation to complete
  await response.promise();
  const result = response.result;

  console.log(`Export model response : ${JSON.stringify(result)}`);
}
exportModel();

Python

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

from google.cloud import aiplatform

def export_model_sample(
    project: str,
    model_id: str,
    gcs_destination_output_uri_prefix: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 300,
):
    # 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)
    output_config = {
        "artifact_destination": {
            "output_uri_prefix": gcs_destination_output_uri_prefix
        },
        # For information about export formats: https://cloud.google.com/ai-platform-unified/docs/export/export-edge-model#aiplatform_export_model_sample-drest
        "export_format_id": "tf-saved-model",
    }
    name = client.model_path(project=project, location=location, model=model_id)
    response = client.export_model(name=name, output_config=output_config)
    print("Long running operation:", response.operation.name)
    print("output_info:", response.metadata.output_info)
    export_model_response = response.result(timeout=timeout)
    print("export_model_response:", export_model_response)

オブジェクト検出

トレーニング済みの AutoML Edge 画像オブジェクト検出モデルは、次の形式でエクスポートできます。

  • TF Lite - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
  • コンテナ - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
  • Tensorflow.js - ブラウザと Node.js でモデルを実行するため、モデルを TensorFlow.js パッケージとしてエクスポートします。

お使いの言語または環境に応じて、以下のタブを選択してください。

コンソール

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

    [モデル] ページに移動

  2. エクスポートする AutoML Edge モデルのバージョン番号をクリックして、詳細ページを開きます。
  3. [デプロイとテスト] タブを選択して、使用可能なエクスポート形式を表示します。
  4. [Use your edge-optimized model] セクションから目的のエクスポート モデルの形式を選択します。
  5. [モデルをエクスポート] サイド ウィンドウで、Edge モデルのエクスポート出力を保存する Cloud Storage 内の場所を指定します。
  6. [エクスポート] をクリックします。
  7. [完了] をクリックして、[モデルをエクスポート] サイド ウィンドウを閉じます。

REST

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

  • LOCATION: 実際のプロジェクトのロケーション。
  • PROJECT: 実際のプロジェクト ID
  • MODEL_ID: エクスポートするトレーニング済みの AutoML Edge モデルの ID 番号。
  • EXPORT_FORMAT: エクスポートする Edge モデルのタイプ。この目標の場合は、次のオプションがあります。
    • tflite(TF Lite) - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
    • tf-saved-model(コンテナ) - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
    • tf-js(Tensorflow.js) - ブラウザと Node.js でモデルを実行するため、モデルを TensorFlow.js パッケージとしてエクスポートします。
  • OUTPUT_BUCKET: Edge モデルファイルを保存する Cloud Storage バケット ディレクトリのパス。
  • HTTP メソッドと URL:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export

    リクエストの本文(JSON):

    {
      "outputConfig": {
        "exportFormatId": "EXPORT_FORMAT",
        "artifactDestination": {
          "outputUriPrefix": "gs://OUTPUT_BUCKET/"
        }
      }
    }
    

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

    curl

    リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export"

    PowerShell

    リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/models/MODEL_ID:export" | Select-Object -Expand Content

    レスポンスには、仕様と OPERATION_ID に関する情報が含まれています。

    エクスポート オペレーションのステータスを取得して、終了時間を確認できます。

Java

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

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


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.ExportModelOperationMetadata;
import com.google.cloud.aiplatform.v1.ExportModelRequest;
import com.google.cloud.aiplatform.v1.ExportModelResponse;
import com.google.cloud.aiplatform.v1.GcsDestination;
import com.google.cloud.aiplatform.v1.ModelName;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ExportModelSample {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String gcsDestinationOutputUriPrefix = "gs://YOUR_GCS_SOURCE_BUCKET/path_to_your_destination/";
    String exportFormat = "YOUR_EXPORT_FORMAT";
    exportModelSample(project, modelId, gcsDestinationOutputUriPrefix, exportFormat);
  }

  static void exportModelSample(
      String project, String modelId, String gcsDestinationOutputUriPrefix, String exportFormat)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    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";
      GcsDestination.Builder gcsDestination = GcsDestination.newBuilder();
      gcsDestination.setOutputUriPrefix(gcsDestinationOutputUriPrefix);

      ModelName modelName = ModelName.of(project, location, modelId);
      ExportModelRequest.OutputConfig outputConfig =
          ExportModelRequest.OutputConfig.newBuilder()
              .setExportFormatId(exportFormat)
              .setArtifactDestination(gcsDestination)
              .build();

      OperationFuture<ExportModelResponse, ExportModelOperationMetadata> exportModelResponseFuture =
          modelServiceClient.exportModelAsync(modelName, outputConfig);
      System.out.format(
          "Operation name: %s\n", exportModelResponseFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      ExportModelResponse exportModelResponse =
          exportModelResponseFuture.get(300, TimeUnit.SECONDS);

      System.out.format("Export Model Response: %s\n", exportModelResponse);
    }
  }
}

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)
 */

// const modelId = 'YOUR_MODEL_ID';
// const gcsDestinationOutputUriPrefix ='YOUR_GCS_DEST_OUTPUT_URI_PREFIX';
//    eg. "gs://<your-gcs-bucket>/destination_path"
// const exportFormat = 'YOUR_EXPORT_FORMAT';
// 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 exportModel() {
  // Configure the name resources
  const name = `projects/${project}/locations/${location}/models/${modelId}`;
  // Configure the outputConfig resources
  const outputConfig = {
    exportFormatId: exportFormat,
    gcsDestination: {
      outputUriPrefix: gcsDestinationOutputUriPrefix,
    },
  };
  const request = {
    name,
    outputConfig,
  };

  // Export Model request
  const [response] = await modelServiceClient.exportModel(request);
  console.log(`Long running operation : ${response.name}`);

  // Wait for operation to complete
  await response.promise();
  const result = response.result;

  console.log(`Export model response : ${JSON.stringify(result)}`);
}
exportModel();

Python

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

from google.cloud import aiplatform

def export_model_sample(
    project: str,
    model_id: str,
    gcs_destination_output_uri_prefix: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 300,
):
    # 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)
    output_config = {
        "artifact_destination": {
            "output_uri_prefix": gcs_destination_output_uri_prefix
        },
        # For information about export formats: https://cloud.google.com/ai-platform-unified/docs/export/export-edge-model#aiplatform_export_model_sample-drest
        "export_format_id": "tf-saved-model",
    }
    name = client.model_path(project=project, location=location, model=model_id)
    response = client.export_model(name=name, output_config=output_config)
    print("Long running operation:", response.operation.name)
    print("output_info:", response.metadata.output_info)
    export_model_response = response.result(timeout=timeout)
    print("export_model_response:", export_model_response)

動画

目標に応じて以下のタブを選択してください。

動作認識

トレーニング済みの AutoML Edge 動画動作認識モデルは、保存されたモデル形式でエクスポートできます。

お使いの言語または環境に応じて、以下のタブを選択してください。

コンソール

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

    [モデル] ページに移動

  2. エクスポートする AutoML Edge モデルのバージョン番号をクリックして、詳細ページを開きます。
  3. [エクスポート] をクリックします。
  4. [モデルをエクスポート] サイド ウィンドウで、Edge モデルのエクスポート出力を保存する Cloud Storage 内の場所を指定します。
  5. [エクスポート] をクリックします。
  6. [完了] をクリックして、[モデルをエクスポート] サイド ウィンドウを閉じます。

REST

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

  • LOCATION: モデルが保存されているリージョン。例: us-central1
  • MODEL_ID: エクスポートするトレーニング済みの AutoML Edge モデルの ID 番号。
  • EXPORT_FORMAT: エクスポートする Edge モデルのタイプ。動画動作認識の場合、次のモデル オプションがあります。
    • tf-saved-model(コンテナ) - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
  • OUTPUT_BUCKET: Edge モデルファイルを保存する Cloud Storage バケット ディレクトリのパス。
  • PROJECT_NUMBER: プロジェクトに自動生成されたプロジェクト番号

HTTP メソッドと URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export

リクエストの本文(JSON):

{
  "outputConfig": {
    "exportFormatId": "EXPORT_FORMAT",
    "artifactDestination": {
    "outputUriPrefix": "gs://OUTPUT_BUCKET/"
    }
  }
}

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

curl

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export"

PowerShell

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export" | Select-Object -Expand Content

レスポンスには、仕様と OPERATION_ID に関する情報が含まれています。

エクスポート オペレーションのステータスを取得して、終了時間を確認できます。

Java

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

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

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.ExportModelOperationMetadata;
import com.google.cloud.aiplatform.v1.ExportModelRequest;
import com.google.cloud.aiplatform.v1.ExportModelResponse;
import com.google.cloud.aiplatform.v1.GcsDestination;
import com.google.cloud.aiplatform.v1.ModelName;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class ExportModelVideoActionRecognitionSample {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "PROJECT";
    String modelId = "MODEL_ID";
    String gcsDestinationOutputUriPrefix = "GCS_DESTINATION_OUTPUT_URI_PREFIX";
    String exportFormat = "EXPORT_FORMAT";
    exportModelVideoActionRecognitionSample(
        project, modelId, gcsDestinationOutputUriPrefix, exportFormat);
  }

  static void exportModelVideoActionRecognitionSample(
      String project, String modelId, String gcsDestinationOutputUriPrefix, String exportFormat)
      throws IOException, ExecutionException, InterruptedException {
    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)) {
      GcsDestination gcsDestination =
          GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
      ExportModelRequest.OutputConfig outputConfig =
          ExportModelRequest.OutputConfig.newBuilder()
              .setArtifactDestination(gcsDestination)
              .setExportFormatId(exportFormat)
              .build();
      ModelName name = ModelName.of(project, location, modelId);
      OperationFuture<ExportModelResponse, ExportModelOperationMetadata> response =
          client.exportModelAsync(name, outputConfig);

      // You can use OperationFuture.getInitialFuture to get a future representing the initial
      // response to the request, which contains information while the operation is in progress.
      System.out.format("Operation name: %s\n", response.getInitialFuture().get().getName());

      // OperationFuture.get() will block until the operation is finished.
      ExportModelResponse exportModelResponse = response.get();
      System.out.format("exportModelResponse: %s\n", exportModelResponse);
    }
  }
}

Python

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

from google.cloud import aiplatform

def export_model_video_action_recognition_sample(
    project: str,
    model_id: str,
    gcs_destination_output_uri_prefix: str,
    export_format: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 300,
):
    # 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)
    gcs_destination = {"output_uri_prefix": gcs_destination_output_uri_prefix}
    output_config = {
        "artifact_destination": gcs_destination,
        "export_format_id": export_format,
    }
    name = client.model_path(project=project, location=location, model=model_id)
    response = client.export_model(name=name, output_config=output_config)
    print("Long running operation:", response.operation.name)
    print("output_info:", response.metadata.output_info)
    export_model_response = response.result(timeout=timeout)
    print("export_model_response:", export_model_response)

分類

トレーニング済み AutoML Edge 動画分類モデルは、保存されたモデル形式でのみエクスポートできます。

お使いの言語または環境に応じて、以下のタブを選択してください。

コンソール

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

    [モデル] ページに移動

  2. エクスポートする AutoML Edge モデルのバージョン番号をクリックして、詳細ページを開きます。
  3. [エクスポート] をクリックします。
  4. [モデルをエクスポート] サイド ウィンドウで、Edge モデルのエクスポート出力を保存する Cloud Storage 内の場所を指定します。
  5. [エクスポート] をクリックします。
  6. [完了] をクリックして、[モデルをエクスポート] サイド ウィンドウを閉じます。

REST

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

  • LOCATION: モデルが保存されているリージョン。例: us-central1
  • MODEL_ID: エクスポートするトレーニング済みの AutoML Edge モデルの ID 番号。
  • EXPORT_FORMAT: エクスポートする Edge モデルのタイプ。動画分類の場合、次のモデル オプションがあります。
    • tf-saved-model(コンテナ) - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
  • OUTPUT_BUCKET: Edge モデルファイルを保存する Cloud Storage バケット ディレクトリのパス。
  • PROJECT_NUMBER: プロジェクトに自動生成されたプロジェクト番号

HTTP メソッドと URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export

リクエストの本文(JSON):

{
  "outputConfig": {
    "exportFormatId": "EXPORT_FORMAT",
    "artifactDestination": {
    "outputUriPrefix": "gs://OUTPUT_BUCKET/"
    }
  }
}

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

curl

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export"

PowerShell

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export" | Select-Object -Expand Content

レスポンスには、仕様と OPERATION_ID に関する情報が含まれています。

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.ExportModelOperationMetadata",
    "genericMetadata": {
      "createTime": "2020-10-12T20:53:40.130785Z",
      "updateTime": "2020-10-12T20:53:40.130785Z"
    },
    "outputInfo": {
      "artifactOutputUri": "gs://OUTPUT_BUCKET/model-MODEL_ID/EXPORT_FORMAT/YYYY-MM-DDThh:mm:ss.sssZ"
    }
  }
}

エクスポート オペレーションのステータスを取得して、終了時間を確認できます。

オブジェクト トラッキング

トレーニング済みの AutoML Edge 動画オブジェクト トラッキング モデルは、次の形式でエクスポートできます。

  • TF Lite - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TensorFlow Lite パッケージとしてエクスポートします。
  • コンテナ - Docker コンテナで実行するため、モデルを TensorFlow 保存モデルとしてエクスポートします。

お使いの言語または環境に応じて、以下のタブを選択してください。

コンソール

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

    [モデル] ページに移動

  2. エクスポートする AutoML Edge モデルのバージョン番号をクリックして、詳細ページを開きます。
  3. [エクスポート] をクリックします。
  4. [モデルをエクスポート] サイド ウィンドウで、Edge モデルのエクスポート出力を保存する Cloud Storage 内の場所を指定します。
  5. [エクスポート] をクリックします。
  6. [完了] をクリックして、[モデルをエクスポート] サイド ウィンドウを閉じます。

REST

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

  • LOCATION: モデルが保存されているリージョン。例: us-central1
  • MODEL_ID: エクスポートするトレーニング済みの AutoML Edge モデルの ID 番号。
  • EXPORT_FORMAT: エクスポートする Edge モデルのタイプ。動画オブジェクト トラッキング モデルの場合、次のオプションがあります。
    • tflite(TF Lite) - エッジまたはモバイル デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
    • edgetpu-tflite(Edge TPU TF Lite) - Edge TPU デバイスでモデルを実行するために、モデルを TF Lite パッケージとしてエクスポートします。
    • tf-saved-model(コンテナ) - Docker コンテナで実行するため、モデルを TF 保存モデルとしてエクスポートします。
  • OUTPUT_BUCKET: Edge モデルファイルを保存する Cloud Storage バケット ディレクトリのパス。
  • PROJECT_NUMBER: プロジェクトに自動生成されたプロジェクト番号

HTTP メソッドと URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export

リクエストの本文(JSON):

{
  "outputConfig": {
    "exportFormatId": "EXPORT_FORMAT",
    "artifactDestination": {
    "outputUriPrefix": "gs://OUTPUT_BUCKET/"
    }
  }
}

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

curl

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export"

PowerShell

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID:export" | Select-Object -Expand Content

レスポンスには、仕様と OPERATION_ID に関する情報が含まれています。

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/models/MODEL_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.ExportModelOperationMetadata",
    "genericMetadata": {
      "createTime": "2020-10-12T20:53:40.130785Z",
      "updateTime": "2020-10-12T20:53:40.130785Z"
    },
    "outputInfo": {
      "artifactOutputUri": "gs://OUTPUT_BUCKET/model-MODEL_ID/EXPORT_FORMAT/YYYY-MM-DDThh:mm:ss.sssZ"
    }
  }
}

エクスポート オペレーションのステータスを取得して、終了時間を確認できます。

オペレーションのステータスの取得

画像

エクスポート オペレーションのステータスを取得するには、次のコードを使用します。このコードは、すべての目標で同じです。

REST

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

  • LOCATION: 実際のプロジェクトのロケーション。
  • PROJECT: 実際のプロジェクト ID
  • OPERATION_ID: ターゲット オペレーションの ID。この ID は通常、元のリクエストに対するレスポンスに含まれます。

HTTP メソッドと URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/operations/OPERATION_ID

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

curl

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

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/operations/OPERATION_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/operations/OPERATION_ID" | Select-Object -Expand Content
完了したインポート オペレーションの場合、出力は次のようになります。
{
  "name": "projects/PROJECT/locations/LOCATION/models/MODEL_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.ExportModelOperationMetadata",
    "genericMetadata": {
      "createTime": "2020-10-12T20:53:40.130785Z",
      "updateTime": "2020-10-12T20:53:40.793983Z"
    },
    "outputInfo": {
      "artifactOutputUri": "gs://OUTPUT_BUCKET/model-MODEL_ID/EXPORT_FORMAT/YYYY-MM-DDThh:mm:ss.sssZ"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.ExportModelResponse"
  }
}

動画

REST

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

  • PROJECT_NUMBER: プロジェクトに自動生成されたプロジェクト番号
  • LOCATION: モデルが保存されているリージョン。例: us-central1
  • OPERATION_ID: オペレーションの ID。

HTTP メソッドと URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/operations/OPERATION_ID

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

curl

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

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/operations/OPERATION_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/operations/OPERATION_ID" | Select-Object -Expand Content

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

出力ファイル

画像

ご使用のモデル形式に対応するタブを選択してください。

TF Lite

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/tflite/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. model.tflite: TensorFlow Lite ですぐに使用できるモデル バージョンを含むファイル。

Edge TPU

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/edgetpu-tflite/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. edgetpu_model.tflite: TensorFlow Lite のモデル バージョンを含むファイル。Edge TPU との互換性のため Edge TPU コンパイラを通過します。

コンテナ

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/tf-saved-model/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. saved_model.pb: グラフの定義とモデルの重みを含むプロトコル バッファ ファイル。

Core ML

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/core-ml/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. dict.txt: ラベルファイル。ラベルファイル dict.txt 内の各行には、モデルから返された予測のラベルが入ります。ラベルはリクエストされた順番で記述されます。

    dict.txt の例

    roses
    daisy
    tulips
    dandelion
    sunflowers
    
  2. model.mlmodel: Core ML モデルを指定するファイル。

Tensorflow.js

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/tf-js/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. dict.txt: ラベルファイル。ラベルファイル dict.txt 内の各行には、モデルから返された予測のラベルが入ります。ラベルはリクエストされた順番で記述されます。

    dict.txt の例

    roses
    daisy
    tulips
    dandelion
    sunflowers
    
  2. group1-shard1of3.bin: バイナリ ファイル。
  3. group1-shard2of3.bin: バイナリ ファイル。
  4. group1-shard3of3.bin: バイナリ ファイル。
  5. model.json: モデルの JSON ファイル表現。

    サンプル model.json(わかりやすくするため短縮しています)

    {
      "format": "graph-model",
      "generatedBy": "2.4.0",
      "convertedBy": "TensorFlow.js Converter v1.7.0",
      "userDefinedMetadata": {
        "signature": {
          "inputs": {
            "image:0": {
              "name": "image:0",
              "dtype": "DT_FLOAT",
              "tensorShape": {
                "dim": [
                  {
                    "size": "1"
                  },
                  {
                    "size": "224"
                  },
                  {
                    "size": "224"
                  },
                  {
                    "size": "3"
                  }
                ]
              }
            }
          },
          "outputs": {
            "scores:0": {
              "name": "scores:0",
              "dtype": "DT_FLOAT",
              "tensorShape": {
                "dim": [
                  {
                    "size": "1"
                  },
                  {
                    "size": "5"
                  }
                ]
              }
            }
          }
        }
      },
      "modelTopology": {
        "node": [
          {
            "name": "image",
            "op": "Placeholder",
            "attr": {
              "dtype": {
                "type": "DT_FLOAT"
              },
              "shape": {
                "shape": {
                  "dim": [
                    {
                      "size": "1"
                    },
                    {
                      "size": "224"
                    },
                    {
                      "size": "224"
                    },
                    {
                      "size": "3"
                    }
                  ]
                }
              }
            }
          },
          {
            "name": "mnas_v4_a_1/feature_network/feature_extractor/Mean/reduction_indices",
            "op": "Const",
            "attr": {
              "value": {
                "tensor": {
                  "dtype": "DT_INT32",
                  "tensorShape": {
                    "dim": [
                      {
                        "size": "2"
                      }
                    ]
                  }
                }
              },
              "dtype": {
                "type": "DT_INT32"
              }
            }
          },
          ...
          {
            "name": "scores",
            "op": "Identity",
            "input": [
              "Softmax"
            ],
            "attr": {
              "T": {
                "type": "DT_FLOAT"
              }
            }
          }
        ],
        "library": {},
        "versions": {}
      },
      "weightsManifest": [
        {
          "paths": [
            "group1-shard1of3.bin",
            "group1-shard2of3.bin",
            "group1-shard3of3.bin"
          ],
          "weights": [
            {
              "name": "mnas_v4_a_1/feature_network/feature_extractor/Mean/reduction_indices",
              "shape": [
                2
              ],
              "dtype": "int32"
            },
            {
              "name": "mnas_v4_a/output/fc/tf_layer/kernel",
              "shape": [
                1280,
                5
              ],
              "dtype": "float32"
            },
            ...
            {
              "name": "mnas_v4_a_1/feature_network/lead_cell_17/op_0/conv2d_0/Conv2D_weights",
              "shape": [
                1,
                1,
                320,
                1280
              ],
              "dtype": "float32"
            },
            {
              "name": "mnas_v4_a_1/feature_network/cell_14/op_0/expand_0/Conv2D_bn_offset",
              "shape": [
                1152
              ],
              "dtype": "float32"
            }
          ]
        }
      ]
    }

動画

ご使用のモデル形式に対応するタブを選択してください。

TF Lite

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/tflite/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. model.tflite: TensorFlow Lite ですぐに使用できるモデル バージョンを含むファイル。
  2. frozen_inference_graph.pb: グラフの定義とモデルの重みを含むシリアル化されたプロトコル バッファ ファイル。
  3. label_map.pbtxt: 使用されたラベルを整数値にマッピングするラベル マップ ファイル。

Edge TPU

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/edgetpu-tflite/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. edgetpu_model.tflite: TensorFlow Lite のモデル バージョンを含むファイル。Edge TPU との互換性のため Edge TPU コンパイラを通過します。
  2. label_map.pbtxt: 使用されたラベルを整数値にマッピングするラベル マップ ファイル。

コンテナ

リクエストで指定した OUTPUT_BUCKET によって、出力ファイルの保存場所が決まります。出力ファイルが保存されるディレクトリの形式:

  • gs://OUTPUT_BUCKET/model-MODEL_ID/tf-saved-model/YYYY-MM-DDThh:mm:ss.sssZ/

ファイル:

  1. frozen_inference_graph.pb: グラフの定義とモデルの重みを含むシリアル化されたプロトコル バッファ ファイル。
  2. label_map.pbtxt: 使用されたラベルを整数値にマッピングするラベル マップ ファイル。
  3. saved_model/saved_model.pb: このファイルには、実際の TensorFlow プログラムまたはモデル、名前付きのシグネチャのセットが格納されます。これは、テンソルの入力を受け入れ、テンソルの出力を生成する関数を表します。
  4. saved_model/variables/: 変数ディレクトリには、標準のトレーニング チェックポイントが含まれます。