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());
" }
"}
}""""