0
0

[GCP] Vertex AI 機能x検証

Last updated at Posted at 2023-11-07

GCP Vertex AI

概要

GCPのVertex AIは、機械学習(Machine Learning)モデルの開発、トレーニング、配備を簡素化するためのクラウドベースのプラットフォームです。Vertex AIは、豊富な機能セットを提供し、機械学習ソリューションの開発を迅速かつ効果的に行うことができます。

機能

モデルのトレーニングと予測

  • Vertex AIは、大規模なデータセットを使用して機械学習モデルをトレーニングするための豊富なツールセットを提供します。
  • トレーニングは、TensorFlow、PyTorch、XGBoostなどの一般的なフレームワークを使用して行うことができます。
  • Vertex AIは、分散トレーニングをサポートし、スケーラビリティとパフォーマンスを向上させます。
  • トレーニングされたモデルを使用して、新しいデータの予測を行うこともできます。

モデルのデプロイと管理

  • Vertex AIは、トレーニング済みモデルのデプロイと管理を簡単に行うことができます。
  • モデルをデプロイする際には、スケーラブルな推論インターフェースが提供されます。
  • モデルのバージョン管理やモデルのアップデートも簡単に行うことができます。
  • デプロイされたモデルは、REST APIやgRPCを使用してアクセスすることができます。

オートメイテッド マシン レーニング

  • Vertex AIは、自動機械学習(AutoML)機能も提供しています。
  • AutoMLを使用することで、モデルの選択、ハイパーパラメータの最適化、特徴量エンジニアリングなど、機械学習プロセスの一部を自動化することができます。
  • AutoMLは、開発者が機械学習の専門知識を持たなくても、高度なモデルを作成することを可能にします。

サンプルコード

Java

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1beta1.JobServiceClient;
import com.google.cloud.aiplatform.v1beta1.LocationName;
import com.google.cloud.aiplatform.v1beta1.PipelineServiceClient;
import com.google.cloud.aiplatform.v1beta1.PipelineServiceSettings;
import com.google.cloud.aiplatform.v1beta1.PipelineJob;
import com.google.cloud.aiplatform.v1beta1.PipelineJobName;
import com.google.cloud.aiplatform.v1beta1.PipelineJobStatus;
import com.google.protobuf.Duration;
import com.google.protobuf.Empty;
import com.google.protobuf.Timestamp;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class VertexAISample {

  public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
    try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
      LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
      JobServiceClient.ListPipelineJobsPagedResponse response = jobServiceClient
              .listPipelineJobs(parent);
      for (PipelineJob job : response.iterateAll()) {
        System.out.println("Pipeline Job Name: " + job.getName());
        PipelineJobName jobName = PipelineJobName.parse(job.getName());
        OperationFuture<Empty, PipelineJob> jobFuture =
                jobServiceClient.deletePipelineJobAsync(jobName);
        jobFuture.get();
        System.out.println("Pipeline Job deleted successfully.");
      }
    }
  }
}

Go

package main

import (
	"context"
	"fmt"
	"os"

	aiplatform "cloud.google.com/go/aiplatform/apiv1beta1"
	aiplatformpb "google.golang.org/genproto/googleapis/cloud/aiplatform/v1beta1"
)

func main() {
	ctx := context.Background()

	pipelineClient, err := aiplatform.NewPipelineClient(ctx)
	if err != nil {
		fmt.Printf("Failed to create client: %v\n", err)
		os.Exit(1)
	}
	defer pipelineClient.Close()

	parent := "projects/[PROJECT]/locations/[LOCATION]"
	req := &aiplatformpb.ListPipelineJobsRequest{Parent: parent}
	it := pipelineClient.ListPipelineJobs(ctx, req)
	for {
		job, err := it.Next()
		if err == aiplatform.Done {
			break // Done iterating over the results.
		}
		if err != nil {
			fmt.Printf("Failed to retrieve job: %v\n", err)
			os.Exit(1)
		}
		fmt.Printf("Pipeline Job Name: %s\n", job.GetName())

		deleteReq := &aiplatformpb.DeletePipelineJobRequest{Name: job.GetName()}
		err = pipelineClient.DeletePipelineJob(ctx, deleteReq)
		if err != nil {
			fmt.Printf("Failed to delete job: %v\n", err)
			os.Exit(1)
		}

		fmt.Println("Pipeline Job deleted successfully.")
	}
}

C#

using Google.Cloud.AIPlatform.V1;

public class VertexAISample
{
    public static void Main(string[] args)
    {
        var client = JobServiceClient.Create();

        var parent = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]");
        var response = client.ListPipelineJobs(parent);
        foreach (var job in response)
        {
            Console.WriteLine($"Pipeline Job Name: {job.Name}");

            client.DeletePipelineJob(job.Name);

            Console.WriteLine("Pipeline Job deleted successfully.");
        }
    }
}

このサンプルコードでは、Vertex AIのジョブ(Pipeline Job)を一覧し、各ジョブを削除する処理を示しています。詳細な実装については、GCPの公式ドキュメントやAPIリファレンスを参照ください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0