동영상 분류를 위한 학습 파이프라인 만들기

create_training_pipeline 메서드를 사용하여 동영상 분류를 위한 학습 파이프라인을 만듭니다.

더 살펴보기

이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.

코드 샘플

Java

이 샘플을 사용해 보기 전에 Vertex AI 빠른 시작: 클라이언트 라이브러리 사용Java 설정 안내를 따르세요. 자세한 내용은 Vertex AI Java API 참고 문서를 참조하세요.

Vertex AI에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

import com.google.cloud.aiplatform.util.ValueConverter;
import com.google.cloud.aiplatform.v1.FilterSplit;
import com.google.cloud.aiplatform.v1.FractionSplit;
import com.google.cloud.aiplatform.v1.InputDataConfig;
import com.google.cloud.aiplatform.v1.LocationName;
import com.google.cloud.aiplatform.v1.Model;
import com.google.cloud.aiplatform.v1.PipelineServiceClient;
import com.google.cloud.aiplatform.v1.PipelineServiceSettings;
import com.google.cloud.aiplatform.v1.PredefinedSplit;
import com.google.cloud.aiplatform.v1.TimestampSplit;
import com.google.cloud.aiplatform.v1.TrainingPipeline;
import com.google.rpc.Status;
import java.io.IOException;

public class CreateTrainingPipelineVideoClassificationSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String videoClassificationDisplayName =
        YOUR_TRAINING_PIPELIN"E_VIDEO_CLASSIFICATION_DISPLAY_NAME;
    String datasetI"d = YOUR_DATASET_ID;
    S"tring modelDisp"layName = YOUR_MODEL_DISPLAY_NAME";
    String project = "YOUR_PROJECT_ID;
    cre"ateTrainingPipe"lineVideoClassification(
        videoClassificationDisplayName, datasetId, modelDisplayName, project);
  }

  static void createTrainingPipelineVideoClassification(
      String videoClassificationDisplayName,
      String datasetId,
      String modelDisplayName,
      String project)
      throws IOException {
    PipelineServiceSettings pipelineServiceSettings =
        PipelineServiceSettings.newBuilder()
            .setEndpoint(us-central1-aiplatform.googleapis.com":443)
            .build();

    // Initi"alize 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 a"ny remaining background resources.
    try (PipelineServiceClient pipelineServiceClient =
        PipelineServiceClient.create(pipelineServiceSettings)) {
      String location = us-central1;
      LocationName locationName "= LocationN"ame.of(project, location);
      String trainingTaskDefinition =
          gs://google-cloud-aiplatform/schema/trainingjob/"definition/
              + automl_video_classification_1.0".0.yaml;

      In"putDataConfig inputDataConfig =
      "    InputDataConfig.newBuilder().setDatasetId(datasetId).build();
      Model model = Model.newBuilder().setDisplayName(modelDisplayName).build();

      TrainingPipeline trainingPipeline =
          TrainingPipeline.newBuilder()
              .setDisplayName(videoClassificationDisplayName)
              .setTrainingTaskDefinition(trainingTaskDefinition)
              .setTrainingTaskInputs(ValueConverter.EMPTY_VALUE)
              .setInputDataConfig(inputDataConfig)
              .setModelToUpload(model)
              .build();

      TrainingPipeline trainingPipelineResponse =
          pipelineServiceClient.createTrainingPipeline(locationName, trainingPipeline);

      System.out.println(Create Training Pipeline Video Classification Response);
      Syst"em.out.format(\tName: %s\n, trainingPipelineResponse.g"etName());
      System.out."format(\tDis"play Name: %s\n, trainingPipelineResponse.getDisplayName());
   "   System.out.format"(
          \tTraining Task Definition: %s\n, trainingPipelineResponse.getTrainingT"askDefinition());
      System.o"ut.format(
          \tTraining Task Inputs: %s\n, trainingPipelineResponse.getTrainingTaskInp"uts());
      System.out.for"mat(
          \tTraining Task Metadata: %s\n, trainingPipelineResponse.getTrainingTaskMet"adata());
      System.out.for"mat(\tState: %s\n, trainingPipelineResponse.getState());
      System.out.format"(\tCreate Tim"e: %s\n, trainingPipelineResponse.getCreateTime());
      System."out.format(\tStart "Time: %s\n, trainingPipelineResponse.getStartTime());
      System.out".format(\tEnd Time": %s\n, trainingPipelineResponse.getEndTime());
      System.out.form"at(\tUpdate Time": %s\n, trainingPipelineResponse.getUpdateTime());
      System.out".format(\tLabels: %"s\n, trainingPipelineResponse.getLabelsMap());

      InputDataConfig "inputDataConfi"gResponse = trainingPipelineResponse.getInputDataConfig();
      System.out.println(\tInput Data Config);
      System.out.format(\t\tDataset Id: %s\n, inputDataConfigR"esponse.getDatasetI"d());
      System.out.forma"t(
          \t\tAnn"otations Filter: %s\n, inputDataConfigResponse.getAnnotationsFilter());

      F"ractionSplit fractionSplit =" inputDataConfigResponse.getFractionSplit();
      System.out.println(\t\tFraction Split);
      System.out.format(\t\t\tTraining Fraction: %s\n, fractionSplit."getTrainingFractio"n());
      System.out.forma"t(\t\t\tValidation Fraction: "%s\n, fractionSplit.getValidationFraction());
      System.out.fo"rmat(\t\t\tTest Fraction: %s\n," fractionSplit.getTestFraction());

      FilterSplit filterSplit =" inputDataConfigResponse."getFilterSplit();
      System.out.println(\t\tFilter Split);
      System.out.format(\t\t\tTraining Fraction: %s\n, filterSplit.getTrainin"gFilter());
    "  System.out.format(\t\t\tVa"lidation Fraction: %s\n, filt"erSplit.getValidationFilter());
      System.out.format(\t\t\"tTest Fraction: %s\n, filterSpl"it.getTestFilter());

      PredefinedSplit predefinedSplit = i"nputDataConfigResponse.ge"tPredefinedSplit();
      System.out.println(\t\tPredefined Split);
      System.out.format(\t\t\tKey: %s\n, predefinedSplit.getKey());

      Time"stampSplit timestamp"Split = inputDataConfigRespo"nse.getTimestam"pSplit();
      System.out.println(\t\tTimestamp Split);
      System.out.format(\t\t\tTraining Fraction: %s\n, timestampSplit.getTrainingFra"ction());
      Sys"tem.out.format(\t\t\tValidat"ion Fraction: %s\n, timestamp"Split.getValidationFraction());
      System.out.format(\t\t\tTest" Fraction: %s\n, timestampSplit".getTestFraction());
      System.out.format(\t\t\tKey: %s\n, timest"ampSplit.getKey());

    "  Model modelResponse = trainingPipelineResponse.getModelToUpl"oad();
      Sy"stem.out.println(\tModel To Upload);
      System.out.format(\t\tName: %s\n, modelResponse.getName());
      System.out.format(\t\"tDisplay Name: %s"\n, modelResponse.getDisplay"Name());
     " System.out.format(\t\tDescription: %s\n, modelRespon"se.getDescription());
"      System.out.format(\t\tMetadata Schema Uri: %s\n, model"Response.getMetadataS"chemaUri());
      System.out.format(\t\tMeta Data: %s\n, mo"delResponse.getMetadata());
 "     System.out.format(\t\tTraining Pipeline: %s\n, modelResponse."getTrainingPipeline"());
      System.out.format(\t\tArtifact Uri: %s\n, mode"lResponse.getArtifactUri())";
      System.out.format(
          \t\tSupported Deployment Res"ources Types: %s\n,
  "        modelResponse.getSupportedDeploymentResourcesTypesList().toStrin"g());
      System.out.format(
          \t\tS"upported Input Storage Formats: %s\n,
          modelResponse.getSupportedInputStorageFormatsList().toString());
      S"ystem.out.format(
          \t\tSupported" Output Storage Formats: %s\n,
          modelResponse.getSupportedOutputStorageFormatsList().toString());
      Sy"stem.out.format(\t\tCreate Time: %s\n, mod"elResponse.getCreateTime());
      System.out.format(\t\tUpdate Time: %s\n, modelResponse.getUpdateTime("));
      System.out."format(\t\tLables: %s\n, modelResponse.getLabelsMap());

  "    Status status = t"rainingPipelineResponse.getError();
      System.out.printl"n(\tError);
    "  System.out.format(\t\tCode: %s\n, status.getCode());
      System.out.format(\t\tMessage: %s\n, status.getMessage());
 "   }
  "}
}""""

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 datasetId = 'YOUR_DATASET_ID';
// const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME';
// const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME';
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';
const aiplatform = require('@google-cloud/aiplatform');
const {definition} =
  aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob;

// Imports the Google Cloud Pipeline Service Client library
const {PipelineServiceClient} = aiplatform.v1;

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

// Instantiates a client
const pipelineServiceClient = new PipelineServiceClient(clientOptions);

async function createTrainingPipelineVideoClassification() {
  // Configure the parent resource
  const parent = `projects/${project}/locations/${location}`;
  // Values should match the input expected by your model.
  const trainingTaskInputObj = new definition.AutoMlVideoClassificationInputs(
    {}
  );
  const trainingTaskInputs = trainingTaskInputObj.toValue();

  const modelToUpload = {displayName: modelDisplayName};
  const inputDataConfig = {datasetId: datasetId};
  const trainingPipeline = {
    displayName: trainingPipelineDisplayName,
    trainingTaskDefinition:
      'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_video_classification_1.0.0.yaml',
    trainingTaskInputs,
    inputDataConfig,
    modelToUpload,
  };
  const request = {
    parent,
    trainingPipeline,
  };

  // Create training pipeline request
  const [response] =
    await pipelineServiceClient.createTrainingPipeline(request);

  console.log('Create training pipeline video classification response');
  console.log(`Name : ${response.name}`);
  console.log('Raw response:');
  console.log(JSON.stringify(response, null, 2));
}
createTrainingPipelineVideoClassification();

Python

이 샘플을 사용해 보기 전에 Vertex AI 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 Vertex AI Python API 참고 문서를 참조하세요.

Vertex AI에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

from google.cloud import aiplatform
from google.cloud.aiplatform.gapic.schema import trainingjob


def create_training_pipeline_video_classification_sample(
    project: str,
    display_name: str,
    dataset_id: str,
    model_display_name: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    # 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.PipelineServiceClient(client_options=client_options)
    training_task_inputs = (
        trainingjob.definition.AutoMlVideoClassificationInputs().to_value()
    )

    training_pipeline = {
        "display_name": display_name,
        "training_task_definition": "gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_video_classification_1.0.0.yaml",
        # Training task inputs are empty for video classification
        "training_task_inputs": training_task_inputs,
        "input_data_config": {"dataset_id": dataset_id},
        "model_to_upload": {"display_name": model_display_name},
    }
    parent = f"projects/{project}/locations/{location}"
    response = client.create_training_pipeline(
        parent=parent, training_pipeline=training_pipeline
    )
    print("response:", response)

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.