C#
C#과 Google Vertex AI 통합 - AI 모델 구축 및 배포
samie
2025. 3. 27. 11:17
C#과 Google Vertex AI 통합 - AI 모델 구축 및 배포
이 가이드에서는 C#을 사용하여 Google Vertex AI를 활용하는 방법을 소개합니다.
1. Google Vertex AI란?
Vertex AI는 Google Cloud에서 제공하는 통합 AI 플랫폼으로, 모델 학습, 배포, MLOps 등을 지원합니다. C#을 활용하여 Vertex AI의 기능을 효과적으로 활용할 수 있습니다.
2. Vertex AI와 C# 연동을 위한 사전 준비
- Google Cloud Platform (GCP) 계정 생성
- Vertex AI API 활성화
- Google Cloud SDK 및 .NET용 Google 클라이언트 라이브러리 설치
dotnet add package Google.Cloud.AIPlatform.V1
3. C#에서 Vertex AI API 사용
3.1 Vertex AI 클라이언트 초기화
using Google.Cloud.AIPlatform.V1;
using Google.Protobuf;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string projectId = "your-gcp-project-id";
string location = "us-central1";
EndpointServiceClient client = await EndpointServiceClient.CreateAsync();
Console.WriteLine("Vertex AI 클라이언트 초기화 완료");
}
}
3.2 AI 모델 배포
public async Task DeployModelAsync()
{
EndpointServiceClient client = await EndpointServiceClient.CreateAsync();
string endpointName = "projects/your-gcp-project-id/locations/us-central1/endpoints/your-endpoint-id";
DeployModelRequest request = new DeployModelRequest
{
Endpoint = endpointName,
DeployedModel = new DeployedModel
{
Model = "projects/your-gcp-project-id/locations/us-central1/models/your-model-id"
}
};
var response = await client.DeployModelAsync(request);
Console.WriteLine("AI 모델 배포 완료");
}
4. Vertex AI 활용 예제
4.1 이미지 분류 모델 호출
public async Task PredictAsync(string imagePath)
{
PredictionServiceClient client = await PredictionServiceClient.CreateAsync();
string endpoint = "projects/your-gcp-project-id/locations/us-central1/endpoints/your-endpoint-id";
ByteString imageBytes = ByteString.CopyFrom(System.IO.File.ReadAllBytes(imagePath));
PredictRequest request = new PredictRequest
{
Endpoint = endpoint,
Instances = { new Value { StructValue = new Google.Protobuf.WellKnownTypes.Struct() } }
};
var response = await client.PredictAsync(request);
Console.WriteLine("예측 결과: " + response);
}
5. 결론
C#을 활용하여 Google Vertex AI와 상호작용하는 방법을 살펴보았습니다. GCP의 강력한 AI 기능을 활용하여 머신러닝 모델을 효과적으로 배포하고 운영할 수 있습니다.