Mengekspor model AutoML Edge

Halaman ini menjelaskan cara menggunakan Vertex AI untuk mengekspor model AutoML Edge gambar dan video Anda ke Cloud Storage.

Untuk mengetahui informasi tentang cara mengekspor model tabel, lihat Mengekspor model tabel AutoML.

Pengantar

Setelah melatih model AutoML Edge, dalam beberapa kasus, Anda dapat mengekspor model dalam berbagai format, bergantung pada cara Anda ingin menggunakannya. File model yang diekspor disimpan di bucket Cloud Storage, dan dapat digunakan untuk prediksi di lingkungan yang Anda pilih.

Anda tidak dapat menggunakan model Edge di Vertex AI untuk menyajikan prediksi; Anda harus men-deploy model Edge ke perangkat eksternal untuk mendapatkan prediksi.

Mengekspor model

Gunakan contoh kode berikut untuk mengidentifikasi model AutoML Edge, menentukan lokasi penyimpanan file output, lalu mengirim permintaan model ekspor.

Gambar

Pilih tab di bawah ini untuk tujuan Anda:

Klasifikasi

Model klasifikasi gambar AutoML Edge yang dilatih dapat diekspor dalam format berikut:

  • TF Lite - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat edge atau seluler.
  • Edge TPU TF Lite - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model Anda di perangkat Edge TPU.
  • Container - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
  • Core ML - Ekspor file .mlmodel untuk menjalankan model Anda di perangkat iOS dan macOS.
  • Tensorflow.js - Ekspor model Anda sebagai paket TensorFlow.js untuk menjalankan model Anda di browser dan di Node.js.

Pilih tab di bawah untuk bahasa atau lingkungan Anda:

Konsol

  1. Di konsol Google Cloud, di bagian Vertex AI, buka halaman Model.

    Buka halaman Model

  2. Klik nomor versi model AutoML Edge yang ingin Anda ekspor untuk membuka halaman detailnya.
  3. Klik Ekspor.
  4. Di jendela samping Ekspor model, tentukan lokasi di Cloud Storage untuk menyimpan output ekspor model Edge.
  5. Klik Ekspor.
  6. Klik Selesai untuk menutup jendela samping Ekspor model.

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: Lokasi project Anda.
  • PROJECT: Project ID Anda.
  • MODEL_ID: Nomor ID model AutoML Edge terlatih yang Anda ekspor.
  • EXPORT_FORMAT: Jenis model Edge yang Anda ekspor. Untuk tujuan ini, opsinya adalah:
    • tflite (TF Lite) - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat edge atau seluler.
    • edgetpu-tflite (Edge TPU TF Lite) - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat Edge TPU.
    • tf-saved-model (Container) - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
    • core-ml (Core ML) - Ekspor file .mlmodel untuk menjalankan model Anda di perangkat iOS dan macOS.
    • tf-js (Tensorflow.js) - Ekspor model Anda sebagai paket TensorFlow.js untuk menjalankan model Anda di browser dan di Node.js.
  • OUTPUT_BUCKET: Jalur ke direktori bucket Cloud Storage tempat Anda ingin menyimpan file model Edge.
  • Metode HTTP dan URL:

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

    Isi JSON permintaan:

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

    Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

    curl

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

    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

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

    $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

    Respons ini berisi informasi tentang spesifikasi serta OPERATION_ID.

    Anda bisa mendapatkan status operasi ekspor untuk melihat kapan operasi tersebut selesai.

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Java Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


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

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di Panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Node.js Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

Untuk mempelajari cara menginstal atau mengupdate Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi 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)

Klasifikasi

Model klasifikasi gambar AutoML Edge yang dilatih dapat diekspor dalam format berikut:

  • TF Lite - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat edge atau seluler.
  • Edge TPU TF Lite - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model Anda di perangkat Edge TPU.
  • Container - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
  • Core ML - Ekspor file .mlmodel untuk menjalankan model Anda di perangkat iOS dan macOS.
  • Tensorflow.js - Ekspor model Anda sebagai paket TensorFlow.js untuk menjalankan model Anda di browser dan di Node.js.

Pilih tab di bawah untuk bahasa atau lingkungan Anda:

Konsol

  1. Di konsol Google Cloud, di bagian Vertex AI, buka halaman Model.

    Buka halaman Model

  2. Klik nomor versi model AutoML Edge yang ingin Anda ekspor untuk membuka halaman detailnya.
  3. Klik Ekspor.
  4. Di jendela samping Ekspor model, tentukan lokasi di Cloud Storage untuk menyimpan output ekspor model Edge.
  5. Klik Ekspor.
  6. Klik Selesai untuk menutup jendela samping Ekspor model.

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: Lokasi project Anda.
  • PROJECT: Project ID Anda.
  • MODEL_ID: Nomor ID model AutoML Edge terlatih yang Anda ekspor.
  • EXPORT_FORMAT: Jenis model Edge yang Anda ekspor. Untuk tujuan ini, opsinya adalah:
    • tflite (TF Lite) - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat edge atau seluler.
    • edgetpu-tflite (Edge TPU TF Lite) - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat Edge TPU.
    • tf-saved-model (Container) - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
    • core-ml (Core ML) - Ekspor file .mlmodel untuk menjalankan model Anda di perangkat iOS dan macOS.
    • tf-js (Tensorflow.js) - Ekspor model Anda sebagai paket TensorFlow.js untuk menjalankan model Anda di browser dan di Node.js.
  • OUTPUT_BUCKET: Jalur ke direktori bucket Cloud Storage tempat Anda ingin menyimpan file model Edge.
  • Metode HTTP dan URL:

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

    Isi JSON permintaan:

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

    Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

    curl

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

    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

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

    $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

    Respons ini berisi informasi tentang spesifikasi serta OPERATION_ID.

    Anda bisa mendapatkan status operasi ekspor untuk melihat kapan operasi tersebut selesai.

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Java Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


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

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di Panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Node.js Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

Untuk mempelajari cara menginstal atau mengupdate Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi 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)

Deteksi objek

Model deteksi objek gambar AutoML Edge yang dilatih dapat diekspor dalam format berikut:

  • TF Lite - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat edge atau seluler.
  • Container - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
  • Tensorflow.js - Ekspor model Anda sebagai paket TensorFlow.js untuk menjalankan model Anda di browser dan di Node.js.

Pilih tab di bawah untuk bahasa atau lingkungan Anda:

Konsol

  1. Di konsol Google Cloud, di bagian Vertex AI, buka halaman Model.

    Buka halaman Model

  2. Klik nomor versi model AutoML Edge yang ingin Anda ekspor untuk membuka halaman detailnya.
  3. Pilih tab Deploy & Uji untuk melihat format ekspor yang tersedia.
  4. Pilih format model ekspor yang diinginkan dari bagian Gunakan model edge yang dioptimalkan.
  5. Di jendela samping Ekspor model, tentukan lokasi di Cloud Storage untuk menyimpan output ekspor model Edge.
  6. Klik Ekspor.
  7. Klik Selesai untuk menutup jendela samping Ekspor model.

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: Lokasi project Anda.
  • PROJECT: Project ID Anda.
  • MODEL_ID: Nomor ID model AutoML Edge terlatih yang Anda ekspor.
  • EXPORT_FORMAT: Jenis model Edge yang Anda ekspor. Untuk tujuan ini, opsinya adalah:
    • tflite (TF Lite) - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat edge atau seluler.
    • tf-saved-model (Container) - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
    • tf-js (Tensorflow.js) - Ekspor model Anda sebagai paket TensorFlow.js untuk menjalankan model Anda di browser dan di Node.js.
  • OUTPUT_BUCKET: Jalur ke direktori bucket Cloud Storage tempat Anda ingin menyimpan file model Edge.
  • Metode HTTP dan URL:

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

    Isi JSON permintaan:

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

    Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

    curl

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

    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

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

    $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

    Respons ini berisi informasi tentang spesifikasi serta OPERATION_ID.

    Anda bisa mendapatkan status operasi ekspor untuk melihat kapan operasi tersebut selesai.

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Java Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


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

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di Panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Node.js Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

Untuk mempelajari cara menginstal atau mengupdate Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi 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)

Video

Pilih tab di bawah ini untuk tujuan Anda:

Pengenalan tindakan

Model pengenalan tindakan video AutoML Edge yang dilatih dapat diekspor dalam format model tersimpan.

Pilih tab di bawah ini untuk bahasa atau lingkungan Anda:

Konsol

  1. Di konsol Google Cloud, di bagian Vertex AI, buka halaman Model.

    Buka halaman Model

  2. Klik nomor versi model AutoML Edge yang ingin Anda ekspor untuk membuka halaman detailnya.
  3. Klik Ekspor.
  4. Di jendela samping Ekspor model, tentukan lokasi di Cloud Storage untuk menyimpan output ekspor model Edge.
  5. Klik Ekspor.
  6. Klik Selesai untuk menutup jendela samping Ekspor model.

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: Region tempat Model disimpan. Contoh, us-central1.
  • MODEL_ID: Nomor ID model AutoML Edge terlatih yang Anda ekspor.
  • EXPORT_FORMAT: Jenis model Edge yang Anda ekspor. Untuk pengenalan tindakan video, opsi modelnya adalah:
    • tf-saved-model (Container) - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
  • OUTPUT_BUCKET: Jalur ke direktori bucket Cloud Storage tempat Anda ingin menyimpan file model Edge.
  • PROJECT_NUMBER: Nomor project yang dibuat secara otomatis untuk project Anda.

Metode HTTP dan URL:

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

Isi JSON permintaan:

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

Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

curl

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

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

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

$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

Respons ini berisi informasi tentang spesifikasi serta OPERATION_ID.

Anda bisa mendapatkan status operasi ekspor untuk melihat kapan operasi tersebut selesai.

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Java Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

Untuk mempelajari cara menginstal atau mengupdate Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi 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)

Klasifikasi

Model klasifikasi video AutoML Edge yang dilatih hanya dapat diekspor dalam format model tersimpan.

Pilih tab di bawah ini untuk bahasa atau lingkungan Anda:

Konsol

  1. Di konsol Google Cloud, di bagian Vertex AI, buka halaman Model.

    Buka halaman Model

  2. Klik nomor versi model AutoML Edge yang ingin Anda ekspor untuk membuka halaman detailnya.
  3. Klik Ekspor.
  4. Di jendela samping Ekspor model, tentukan lokasi di Cloud Storage untuk menyimpan output ekspor model Edge.
  5. Klik Ekspor.
  6. Klik Selesai untuk menutup jendela samping Ekspor model.

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: Region tempat Model disimpan. Contoh, us-central1
  • MODEL_ID: Nomor ID model AutoML Edge terlatih yang Anda ekspor.
  • EXPORT_FORMAT: Jenis model Edge yang Anda ekspor. Untuk klasifikasi video, opsi modelnya adalah:
    • tf-saved-model (Container) - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
  • OUTPUT_BUCKET: Jalur ke direktori bucket Cloud Storage tempat Anda ingin menyimpan file model Edge.
  • PROJECT_NUMBER: Nomor project yang dibuat secara otomatis untuk project Anda.

Metode HTTP dan URL:

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

Isi JSON permintaan:

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

Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

curl

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

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

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

$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

Respons ini berisi informasi tentang spesifikasi serta 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"
    }
  }
}

Anda bisa mendapatkan status operasi ekspor untuk melihat kapan operasi tersebut selesai.

Pelacakan objek

Model pelacakan objek video AutoML Edge yang dilatih dapat diekspor dalam format berikut:

  • TF Lite - Ekspor model Anda sebagai paket TensorFlow Lite untuk menjalankan model Anda di perangkat edge atau seluler.
  • Container - Ekspor model Anda sebagai TensorFlow Tersimpan Model untuk dijalankan di container Docker.

Pilih tab di bawah ini untuk bahasa atau lingkungan Anda:

Konsol

  1. Di konsol Google Cloud, di bagian Vertex AI, buka halaman Model.

    Buka halaman Model

  2. Klik nomor versi model AutoML Edge yang ingin Anda ekspor untuk membuka halaman detailnya.
  3. Klik Ekspor.
  4. Di jendela samping Ekspor model, tentukan lokasi di Cloud Storage untuk menyimpan output ekspor model Edge.
  5. Klik Ekspor.
  6. Klik Selesai untuk menutup jendela samping Ekspor model.

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: Region tempat Model disimpan. Contoh, us-central1
  • MODEL_ID: Nomor ID model AutoML Edge terlatih yang Anda ekspor.
  • EXPORT_FORMAT: Jenis model Edge yang Anda ekspor. Untuk model pelacakan objek video, opsinya adalah:
    • tflite (TF Lite) - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat edge atau seluler.
    • edgetpu-tflite (Edge TPU TF Lite) - Ekspor model Anda sebagai paket TF Lite untuk menjalankan model di perangkat Edge TPU.
    • tf-saved-model (Container) - Ekspor model Anda sebagai TF Saved Model untuk dijalankan di container Docker.
  • OUTPUT_BUCKET: Jalur ke direktori bucket Cloud Storage tempat Anda ingin menyimpan file model Edge.
  • PROJECT_NUMBER: Nomor project yang dibuat secara otomatis untuk project Anda.

Metode HTTP dan URL:

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

Isi JSON permintaan:

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

Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

curl

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

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

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

$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

Respons ini berisi informasi tentang spesifikasi serta 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"
    }
  }
}

Anda bisa mendapatkan status operasi ekspor untuk melihat kapan operasi tersebut selesai.

Mendapatkan status operasi

Gambar

Gunakan kode berikut untuk mendapatkan status operasi ekspor. Kode ini sama untuk semua tujuan:

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: Lokasi project Anda.
  • PROJECT: Project ID Anda.
  • OPERATION_ID:ID operasi target. ID ini biasanya terdapat dalam respons terhadap permintaan asli.

Metode HTTP dan URL:

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

Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

curl

Jalankan perintah berikut:

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

Jalankan perintah berikut:

$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
Anda akan melihat output yang mirip dengan berikut ini untuk operasi yang telah selesai:
{
  "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"
  }
}

Video

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • PROJECT_NUMBER: Nomor project yang dibuat secara otomatis untuk project Anda.
  • LOCATION: Region tempat Model disimpan. Contoh, us-central1.
  • OPERATION_ID: ID operasi Anda.

Metode HTTP dan URL:

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

Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

curl

Jalankan perintah berikut:

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

Jalankan perintah berikut:

$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

Anda akan menerima respons JSON yang mirip dengan yang berikut ini:

File output

Gambar

Pilih tab di bawah ini untuk format model Anda:

TF Lite

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. model.tflite: File yang berisi versi model yang siap digunakan dengan TensorFlow Lite.

Edge TPU

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. edgetpu_model.tflite: File yang berisi versi model untuk TensorFlow Lite, yang diteruskan melalui compiler Edge TPU agar kompatibel dengan Edge TPU.

Container

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. saved_model.pb: File buffering protokol yang berisi definisi grafik dan bobot model.

ML Inti

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. dict.txt: File label. Setiap baris dalam file label dict.txt mewakili label prediksi yang ditampilkan oleh model, dengan urutan yang sama seperti saat diminta.

    Contoh dict.txt

    roses
    daisy
    tulips
    dandelion
    sunflowers
    
  2. model.mlmodel: File yang menentukan model Core ML.

Tensorflow.js

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. dict.txt: File label. Setiap baris dalam file label dict.txt mewakili label prediksi yang ditampilkan oleh model, dengan urutan yang sama seperti saat diminta.

    Contoh dict.txt

    roses
    daisy
    tulips
    dandelion
    sunflowers
    
  2. group1-shard1of3.bin: File biner.
  3. group1-shard2of3.bin: File biner.
  4. group1-shard3of3.bin: File biner.
  5. model.json: Representasi file JSON dari suatu model.

    Sampel model.json (disingkat agar lebih jelas)

    {
      "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"
            }
          ]
        }
      ]
    }

Video

Pilih tab di bawah ini untuk format model Anda:

TF Lite

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. model.tflite: File yang berisi versi model yang siap digunakan dengan TensorFlow Lite.
  2. frozen_inference_graph.pb: File buffering protokol serial yang berisi definisi grafik dan bobot model.
  3. label_map.pbtxt : File peta label yang memetakan setiap label yang digunakan ke nilai bilangan bulat.

Edge TPU

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. edgetpu_model.tflite: File yang berisi versi model untuk TensorFlow Lite, yang diteruskan melalui compiler Edge TPU agar kompatibel dengan Edge TPU.
  2. label_map.pbtxt: File peta label yang memetakan setiap label yang digunakan ke nilai bilangan bulat.

Container

OUTPUT_BUCKET yang Anda tentukan dalam permintaan menentukan tempat file output disimpan. Format direktori tempat file output disimpan mengikuti format:

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

File:

  1. frozen_inference_graph.pb: File buffering protokol serial yang berisi definisi grafik dan bobot model.
  2. label_map.pbtxt: File peta label yang memetakan setiap label yang digunakan ke nilai bilangan bulat.
  3. saved_model/saved_model.pb: File menyimpan program, atau model TensorFlow yang sebenarnya, dan serangkaian tanda tangan bernama, yang masing-masing mengidentifikasi fungsi yang menerima input tensor dan menghasilkan output tensor.
  4. saved_model/variables/: Direktori variabel berisi checkpoint pelatihan standar.