Men-deploy model Anda

Deployment model awal

Men-deploy model Deteksi Objek akan dikenai biaya. Untuk mengetahui informasi selengkapnya, lihat halaman Harga.

Setelah membuat (melatih) model, Anda harus men-deploy model tersebut sebelum dapat melakukan panggilan online (atau sinkron) ke model tersebut.

Sekarang Anda juga dapat memperbarui deployment model jika memerlukan kapasitas prediksi online tambahan.

UI web

  1. Buka AutoML Vision Object Detection UI lalu pilih tab Models di menu navigasi sebelah kiri untuk menampilkan model yang tersedia.

    Untuk melihat model project yang berbeda, pilih project dari menu drop-down di kanan atas panel judul.

  2. Pilih baris untuk model yang ingin Anda gunakan untuk memberi label pada gambar.
  3. Pilih tab Pengujian & Penggunaan tepat di bawah panel judul.
  4. Pilih Deploy model dari banner di bawah nama model Anda untuk membuka jendela opsi deployment model.

    Uji dan gunakan halaman model deploy menu pop-up

    Di jendela ini, Anda dapat memilih jumlah node yang akan di-deploy dan melihat kueri prediksi per detik (QPS) yang tersedia.

  5. Pilih Deploy untuk memulai deployment model.

    deployment model
  6. Anda akan menerima email saat deployment model selesai.

    deploy email yang sudah selesai

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • project-id: Project ID GCP Anda.
  • model-id: ID model Anda, dari respons saat membuat model. ID adalah elemen terakhir dari nama model Anda. Misalnya:
    • nama model: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • ID Model: IOD4412217016962778756

Pertimbangan kolom:

  • nodeCount - Jumlah node tempat model akan di-deploy. Nilainya harus antara 1 dan 100, inklusif di kedua ujungnya. Node adalah abstraksi resource mesin, yang dapat menangani kueri prediksi online per detik (QPS) seperti yang diberikan dalam qps_per_node model.

Metode HTTP dan URL:

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

Isi JSON permintaan:

{
  "imageObjectDetectionModelDeploymentMetadata": {
    "nodeCount": 2
  }
}

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 "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID:deploy"

PowerShell

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

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

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

Anda akan melihat output yang serupa dengan berikut ini: Anda dapat menggunakan ID operasi untuk mendapatkan status tugas. Sebagai contoh, lihat Bekerja dengan operasi yang berjalan lama.

{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-08-07T22:00:20.692109Z",
    "updateTime": "2019-08-07T22:00:20.692109Z",
    "deployModelDetails": {}
  }
}

Anda bisa mendapatkan status operasi dengan metode HTTP dan URL berikut:

GET https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID

Status operasi yang selesai akan terlihat mirip dengan status berikut:

{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-06-21T16:47:21.704674Z",
    "updateTime": "2019-06-21T17:01:00.802505Z",
    "deployModelDetails": {}
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.protobuf.Empty"
  }
}

Go

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

import (
	"context"
	"fmt"
	"io"

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

// deployModel deploys a model.
func deployModel(w io.Writer, projectID string, location string, modelID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// modelID := "TRL123456789..."

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

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

	op, err := client.DeployModel(ctx, req)
	if err != nil {
		return fmt.Errorf("DeployModel: %w", err)
	}
	fmt.Fprintf(w, "Processing operation name: %q\n", op.Name())

	if err := op.Wait(ctx); err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

	fmt.Fprintf(w, "Model deployed.\n")

	return nil
}

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

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

class DeployModel {

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

  // Deploy a model for prediction
  static void deployModel(String projectId, String modelId)
      throws IOException, ExecutionException, InterruptedException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // Get the full path of the model.
      ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
      DeployModelRequest request =
          DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
      OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);

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

Node.js

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

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

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

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

async function deployModel() {
  // Construct request
  const request = {
    name: client.modelPath(projectId, location, modelId),
  };

  const [operation] = await client.deployModel(request);

  // Wait for operation to complete.
  const [response] = await operation.promise();
  console.log(`Model deployment finished. ${response}`);
}

deployModel();

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

from google.cloud import automl

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

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

print(f"Model deployment finished. {response.result()}")

Bahasa tambahan

C# : Ikuti Petunjuk penyiapan C# di halaman library klien, lalu kunjungi Dokumentasi referensi Deteksi Objek Vision AutoML untuk .NET.

PHP : Ikuti petunjuk penyiapan PHP di halaman library klien, lalu kunjungi dokumentasi referensi Deteksi Objek AutoML Vision untuk PHP.

Ruby : Ikuti Petunjuk penyiapan Ruby di halaman library klien, lalu kunjungi Dokumentasi referensi AutoML Vision Object Detection untuk Ruby.

Memperbarui Nomor Node Model

Setelah memiliki model yang di-deploy dan dilatih, Anda dapat memperbarui jumlah node tempat model di-deploy untuk merespons jumlah traffic tertentu. Misalnya, jika Anda mendapati jumlah kueri per detik (QPS) yang lebih tinggi dari yang diperkirakan.

Anda dapat mengubah nomor node ini tanpa harus membatalkan deployment model terlebih dahulu. Memperbarui deployment akan mengubah nomor node tanpa mengganggu traffic prediksi yang Anda salurkan.

UI web

  1. Di AutoML Vision Object Detection UI pilih tab Models (dengan ikon bohlam) di menu navigasi kiri untuk menampilkan model yang tersedia.

    Untuk melihat model project yang berbeda, pilih project dari menu drop-down di kanan atas panel judul.

  2. Pilih model terlatih Anda yang di-deploy.
  3. Pilih tab Uji & Gunakan tepat di bawah kolom judul.
  4. Pesan akan ditampilkan dalam kotak di bagian atas halaman yang bertuliskan "Model Anda telah di-deploy dan tersedia untuk permintaan prediksi online". Pilih opsi Update deployment di samping teks ini.

    gambar tombol update deployment
  5. Di jendela Update deployment yang terbuka, pilih nomor node baru untuk men-deploy model Anda dari daftar. Nomor node menampilkan perkiraan kueri prediksi per detik (QPS). gambar jendela pop-up update deployment
  6. Setelah memilih nomor node baru dari daftar, pilih Update deployment untuk memperbarui nomor node tempat model di-deploy.

    memperbarui jendela deployment setelah memilih nomor node baru
  7. Anda akan dikembalikan ke jendela Test & Use tempat Anda melihat kotak teks sekarang menampilkan "Deploying model...". deployment model
  8. Setelah model berhasil di-deploy pada nomor node baru, Anda akan menerima email di alamat yang terkait dengan project Anda.

REST

Metode yang sama yang awalnya Anda gunakan untuk men-deploy model digunakan untuk mengubah nomor node model yang di-deploy.

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • project-id: Project ID GCP Anda.
  • model-id: ID model Anda, dari respons saat membuat model. ID adalah elemen terakhir dari nama model Anda. Misalnya:
    • nama model: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • ID Model: IOD4412217016962778756

Pertimbangan kolom:

  • nodeCount - Jumlah node tempat model akan di-deploy. Nilainya harus antara 1 dan 100, inklusif di kedua ujungnya. Node adalah abstraksi resource mesin, yang dapat menangani kueri prediksi online per detik (QPS) seperti yang diberikan dalam qps_per_node model.

Metode HTTP dan URL:

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

Isi JSON permintaan:

{
  "imageObjectDetectionModelDeploymentMetadata": {
    "nodeCount": 2
  }
}

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 "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID:deploy"

PowerShell

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

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

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

Anda akan melihat output yang serupa dengan berikut ini: Anda dapat menggunakan ID operasi untuk mendapatkan status tugas. Sebagai contoh, lihat Bekerja dengan operasi yang berjalan lama.

{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-08-07T22:00:20.692109Z",
    "updateTime": "2019-08-07T22:00:20.692109Z",
    "deployModelDetails": {}
  }
}

Go

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

import (
	"context"
	"fmt"
	"io"

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

// visionObjectDetectionDeployModelWithNodeCount deploys a model with node count.
func visionObjectDetectionDeployModelWithNodeCount(w io.Writer, projectID string, location string, modelID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// modelID := "IOD123456789..."

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

	req := &automlpb.DeployModelRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID),
		ModelDeploymentMetadata: &automlpb.DeployModelRequest_ImageObjectDetectionModelDeploymentMetadata{
			ImageObjectDetectionModelDeploymentMetadata: &automlpb.ImageObjectDetectionModelDeploymentMetadata{
				NodeCount: 2,
			},
		},
	}

	op, err := client.DeployModel(ctx, req)
	if err != nil {
		return fmt.Errorf("DeployModel: %w", err)
	}
	fmt.Fprintf(w, "Processing operation name: %q\n", op.Name())

	if err := op.Wait(ctx); err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

	fmt.Fprintf(w, "Model deployed.\n")

	return nil
}

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

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

class VisionObjectDetectionDeployModelNodeCount {

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

  // Deploy a model for prediction with a specified node count (can be used to redeploy a model)
  static void visionObjectDetectionDeployModelNodeCount(String projectId, String modelId)
      throws IOException, ExecutionException, InterruptedException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // Get the full path of the model.
      ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
      ImageObjectDetectionModelDeploymentMetadata metadata =
          ImageObjectDetectionModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
      DeployModelRequest request =
          DeployModelRequest.newBuilder()
              .setName(modelFullId.toString())
              .setImageObjectDetectionModelDeploymentMetadata(metadata)
              .build();
      OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);

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

Node.js

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

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

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

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

async function deployModelWithNodeCount() {
  // Construct request
  const request = {
    name: client.modelPath(projectId, location, modelId),
    imageObjectDetectionModelDeploymentMetadata: {
      nodeCount: 2,
    },
  };

  const [operation] = await client.deployModel(request);

  // Wait for operation to complete.
  const [response] = await operation.promise();
  console.log(`Model deployment finished. ${response}`);
}

deployModelWithNodeCount();

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan untuk bahasa ini di halaman Library Klien.

from google.cloud import automl

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

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

# node count determines the number of nodes to deploy the model on.
# https://cloud.google.com/automl/docs/reference/rpc/google.cloud.automl.v1#imageobjectdetectionmodeldeploymentmetadata
metadata = automl.ImageObjectDetectionModelDeploymentMetadata(node_count=2)

request = automl.DeployModelRequest(
    name=model_full_id,
    image_object_detection_model_deployment_metadata=metadata,
)
response = client.deploy_model(request=request)

print(f"Model deployment finished. {response.result()}")

Bahasa tambahan

C# : Ikuti Petunjuk penyiapan C# di halaman library klien, lalu kunjungi Dokumentasi referensi Deteksi Objek Vision AutoML untuk .NET.

PHP : Ikuti petunjuk penyiapan PHP di halaman library klien, lalu kunjungi dokumentasi referensi Deteksi Objek AutoML Vision untuk PHP.

Ruby: Ikuti Petunjuk penyiapan Ruby di halaman client libraries lalu kunjungi Dokumentasi referensi Deteksi Objek AutoML Vision untuk Ruby.