Search in sources :

Example 26 with LocationName

use of com.google.cloud.aiplatform.v1.LocationName in project java-aiplatform by googleapis.

the class CreateBatchPredictionJobVideoClassificationSample method createBatchPredictionJobVideoClassification.

static void createBatchPredictionJobVideoClassification(String batchPredictionDisplayName, String modelId, String gcsSourceUri, String gcsDestinationOutputUriPrefix, String project) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        VideoClassificationPredictionParams modelParamsObj = VideoClassificationPredictionParams.newBuilder().setConfidenceThreshold(((float) 0.5)).setMaxPredictions(10000).setSegmentClassification(true).setShotClassification(true).setOneSecIntervalClassification(true).build();
        Value modelParameters = ValueConverter.toValue(modelParamsObj);
        ModelName modelName = ModelName.of(project, location, modelId);
        GcsSource.Builder gcsSource = GcsSource.newBuilder();
        gcsSource.addUris(gcsSourceUri);
        InputConfig inputConfig = InputConfig.newBuilder().setInstancesFormat("jsonl").setGcsSource(gcsSource).build();
        GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
        OutputConfig outputConfig = OutputConfig.newBuilder().setPredictionsFormat("jsonl").setGcsDestination(gcsDestination).build();
        BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(batchPredictionDisplayName).setModel(modelName.toString()).setModelParameters(modelParameters).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
        BatchPredictionJob batchPredictionJobResponse = jobServiceClient.createBatchPredictionJob(locationName, batchPredictionJob);
        System.out.println("Create Batch Prediction Job Video Classification Response");
        System.out.format("\tName: %s\n", batchPredictionJobResponse.getName());
        System.out.format("\tDisplay Name: %s\n", batchPredictionJobResponse.getDisplayName());
        System.out.format("\tModel %s\n", batchPredictionJobResponse.getModel());
        System.out.format("\tModel Parameters: %s\n", batchPredictionJobResponse.getModelParameters());
        System.out.format("\tState: %s\n", batchPredictionJobResponse.getState());
        System.out.format("\tCreate Time: %s\n", batchPredictionJobResponse.getCreateTime());
        System.out.format("\tStart Time: %s\n", batchPredictionJobResponse.getStartTime());
        System.out.format("\tEnd Time: %s\n", batchPredictionJobResponse.getEndTime());
        System.out.format("\tUpdate Time: %s\n", batchPredictionJobResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", batchPredictionJobResponse.getLabelsMap());
        InputConfig inputConfigResponse = batchPredictionJobResponse.getInputConfig();
        System.out.println("\tInput Config");
        System.out.format("\t\tInstances Format: %s\n", inputConfigResponse.getInstancesFormat());
        GcsSource gcsSourceResponse = inputConfigResponse.getGcsSource();
        System.out.println("\t\tGcs Source");
        System.out.format("\t\t\tUris %s\n", gcsSourceResponse.getUrisList());
        BigQuerySource bigQuerySource = inputConfigResponse.getBigquerySource();
        System.out.println("\t\tBigquery Source");
        System.out.format("\t\t\tInput_uri: %s\n", bigQuerySource.getInputUri());
        OutputConfig outputConfigResponse = batchPredictionJobResponse.getOutputConfig();
        System.out.println("\tOutput Config");
        System.out.format("\t\tPredictions Format: %s\n", outputConfigResponse.getPredictionsFormat());
        GcsDestination gcsDestinationResponse = outputConfigResponse.getGcsDestination();
        System.out.println("\t\tGcs Destination");
        System.out.format("\t\t\tOutput Uri Prefix: %s\n", gcsDestinationResponse.getOutputUriPrefix());
        BigQueryDestination bigQueryDestination = outputConfigResponse.getBigqueryDestination();
        System.out.println("\t\tBig Query Destination");
        System.out.format("\t\t\tOutput Uri: %s\n", bigQueryDestination.getOutputUri());
        BatchDedicatedResources batchDedicatedResources = batchPredictionJobResponse.getDedicatedResources();
        System.out.println("\tBatch Dedicated Resources");
        System.out.format("\t\tStarting Replica Count: %s\n", batchDedicatedResources.getStartingReplicaCount());
        System.out.format("\t\tMax Replica Count: %s\n", batchDedicatedResources.getMaxReplicaCount());
        MachineSpec machineSpec = batchDedicatedResources.getMachineSpec();
        System.out.println("\t\tMachine Spec");
        System.out.format("\t\t\tMachine Type: %s\n", machineSpec.getMachineType());
        System.out.format("\t\t\tAccelerator Type: %s\n", machineSpec.getAcceleratorType());
        System.out.format("\t\t\tAccelerator Count: %s\n", machineSpec.getAcceleratorCount());
        ManualBatchTuningParameters manualBatchTuningParameters = batchPredictionJobResponse.getManualBatchTuningParameters();
        System.out.println("\tManual Batch Tuning Parameters");
        System.out.format("\t\tBatch Size: %s\n", manualBatchTuningParameters.getBatchSize());
        OutputInfo outputInfo = batchPredictionJobResponse.getOutputInfo();
        System.out.println("\tOutput Info");
        System.out.format("\t\tGcs Output Directory: %s\n", outputInfo.getGcsOutputDirectory());
        System.out.format("\t\tBigquery Output Dataset: %s\n", outputInfo.getBigqueryOutputDataset());
        Status status = batchPredictionJobResponse.getError();
        System.out.println("\tError");
        System.out.format("\t\tCode: %s\n", status.getCode());
        System.out.format("\t\tMessage: %s\n", status.getMessage());
        List<Any> details = status.getDetailsList();
        for (Status partialFailure : batchPredictionJobResponse.getPartialFailuresList()) {
            System.out.println("\tPartial Failure");
            System.out.format("\t\tCode: %s\n", partialFailure.getCode());
            System.out.format("\t\tMessage: %s\n", partialFailure.getMessage());
            List<Any> partialFailureDetailsList = partialFailure.getDetailsList();
        }
        ResourcesConsumed resourcesConsumed = batchPredictionJobResponse.getResourcesConsumed();
        System.out.println("\tResources Consumed");
        System.out.format("\t\tReplica Hours: %s\n", resourcesConsumed.getReplicaHours());
        CompletionStats completionStats = batchPredictionJobResponse.getCompletionStats();
        System.out.println("\tCompletion Stats");
        System.out.format("\t\tSuccessful Count: %s\n", completionStats.getSuccessfulCount());
        System.out.format("\t\tFailed Count: %s\n", completionStats.getFailedCount());
        System.out.format("\t\tIncomplete Count: %s\n", completionStats.getIncompleteCount());
    }
}
Also used : Status(com.google.rpc.Status) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) ModelName(com.google.cloud.aiplatform.v1.ModelName) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) ManualBatchTuningParameters(com.google.cloud.aiplatform.v1.ManualBatchTuningParameters) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) MachineSpec(com.google.cloud.aiplatform.v1.MachineSpec) BigQueryDestination(com.google.cloud.aiplatform.v1.BigQueryDestination) Any(com.google.protobuf.Any) LocationName(com.google.cloud.aiplatform.v1.LocationName) OutputInfo(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo) BatchDedicatedResources(com.google.cloud.aiplatform.v1.BatchDedicatedResources) OutputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig) ResourcesConsumed(com.google.cloud.aiplatform.v1.ResourcesConsumed) VideoClassificationPredictionParams(com.google.cloud.aiplatform.v1.schema.predict.params.VideoClassificationPredictionParams) Value(com.google.protobuf.Value) InputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) BigQuerySource(com.google.cloud.aiplatform.v1.BigQuerySource) CompletionStats(com.google.cloud.aiplatform.v1.CompletionStats)

Example 27 with LocationName

use of com.google.cloud.aiplatform.v1.LocationName in project java-aiplatform by googleapis.

the class CreateBatchPredictionJobVideoObjectTrackingSample method batchPredictionJobVideoObjectTracking.

static void batchPredictionJobVideoObjectTracking(String batchPredictionDisplayName, String modelId, String gcsSourceUri, String gcsDestinationOutputUriPrefix, String project) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        ModelName modelName = ModelName.of(project, location, modelId);
        VideoObjectTrackingPredictionParams modelParamsObj = VideoObjectTrackingPredictionParams.newBuilder().setConfidenceThreshold(((float) 0.5)).build();
        Value modelParameters = ValueConverter.toValue(modelParamsObj);
        GcsSource.Builder gcsSource = GcsSource.newBuilder();
        gcsSource.addUris(gcsSourceUri);
        InputConfig inputConfig = InputConfig.newBuilder().setInstancesFormat("jsonl").setGcsSource(gcsSource).build();
        GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
        OutputConfig outputConfig = OutputConfig.newBuilder().setPredictionsFormat("jsonl").setGcsDestination(gcsDestination).build();
        BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(batchPredictionDisplayName).setModel(modelName.toString()).setModelParameters(modelParameters).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
        BatchPredictionJob batchPredictionJobResponse = jobServiceClient.createBatchPredictionJob(locationName, batchPredictionJob);
        System.out.println("Create Batch Prediction Job Video Object Tracking Response");
        System.out.format("\tName: %s\n", batchPredictionJobResponse.getName());
        System.out.format("\tDisplay Name: %s\n", batchPredictionJobResponse.getDisplayName());
        System.out.format("\tModel %s\n", batchPredictionJobResponse.getModel());
        System.out.format("\tModel Parameters: %s\n", batchPredictionJobResponse.getModelParameters());
        System.out.format("\tState: %s\n", batchPredictionJobResponse.getState());
        System.out.format("\tCreate Time: %s\n", batchPredictionJobResponse.getCreateTime());
        System.out.format("\tStart Time: %s\n", batchPredictionJobResponse.getStartTime());
        System.out.format("\tEnd Time: %s\n", batchPredictionJobResponse.getEndTime());
        System.out.format("\tUpdate Time: %s\n", batchPredictionJobResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", batchPredictionJobResponse.getLabelsMap());
        InputConfig inputConfigResponse = batchPredictionJobResponse.getInputConfig();
        System.out.println("\tInput Config");
        System.out.format("\t\tInstances Format: %s\n", inputConfigResponse.getInstancesFormat());
        GcsSource gcsSourceResponse = inputConfigResponse.getGcsSource();
        System.out.println("\t\tGcs Source");
        System.out.format("\t\t\tUris %s\n", gcsSourceResponse.getUrisList());
        BigQuerySource bigQuerySource = inputConfigResponse.getBigquerySource();
        System.out.println("\t\tBigquery Source");
        System.out.format("\t\t\tInput_uri: %s\n", bigQuerySource.getInputUri());
        OutputConfig outputConfigResponse = batchPredictionJobResponse.getOutputConfig();
        System.out.println("\tOutput Config");
        System.out.format("\t\tPredictions Format: %s\n", outputConfigResponse.getPredictionsFormat());
        GcsDestination gcsDestinationResponse = outputConfigResponse.getGcsDestination();
        System.out.println("\t\tGcs Destination");
        System.out.format("\t\t\tOutput Uri Prefix: %s\n", gcsDestinationResponse.getOutputUriPrefix());
        BigQueryDestination bigQueryDestination = outputConfigResponse.getBigqueryDestination();
        System.out.println("\t\tBig Query Destination");
        System.out.format("\t\t\tOutput Uri: %s\n", bigQueryDestination.getOutputUri());
        BatchDedicatedResources batchDedicatedResources = batchPredictionJobResponse.getDedicatedResources();
        System.out.println("\tBatch Dedicated Resources");
        System.out.format("\t\tStarting Replica Count: %s\n", batchDedicatedResources.getStartingReplicaCount());
        System.out.format("\t\tMax Replica Count: %s\n", batchDedicatedResources.getMaxReplicaCount());
        MachineSpec machineSpec = batchDedicatedResources.getMachineSpec();
        System.out.println("\t\tMachine Spec");
        System.out.format("\t\t\tMachine Type: %s\n", machineSpec.getMachineType());
        System.out.format("\t\t\tAccelerator Type: %s\n", machineSpec.getAcceleratorType());
        System.out.format("\t\t\tAccelerator Count: %s\n", machineSpec.getAcceleratorCount());
        ManualBatchTuningParameters manualBatchTuningParameters = batchPredictionJobResponse.getManualBatchTuningParameters();
        System.out.println("\tManual Batch Tuning Parameters");
        System.out.format("\t\tBatch Size: %s\n", manualBatchTuningParameters.getBatchSize());
        OutputInfo outputInfo = batchPredictionJobResponse.getOutputInfo();
        System.out.println("\tOutput Info");
        System.out.format("\t\tGcs Output Directory: %s\n", outputInfo.getGcsOutputDirectory());
        System.out.format("\t\tBigquery Output Dataset: %s\n", outputInfo.getBigqueryOutputDataset());
        Status status = batchPredictionJobResponse.getError();
        System.out.println("\tError");
        System.out.format("\t\tCode: %s\n", status.getCode());
        System.out.format("\t\tMessage: %s\n", status.getMessage());
        List<Any> details = status.getDetailsList();
        for (Status partialFailure : batchPredictionJobResponse.getPartialFailuresList()) {
            System.out.println("\tPartial Failure");
            System.out.format("\t\tCode: %s\n", partialFailure.getCode());
            System.out.format("\t\tMessage: %s\n", partialFailure.getMessage());
            List<Any> partialFailureDetailsList = partialFailure.getDetailsList();
        }
        ResourcesConsumed resourcesConsumed = batchPredictionJobResponse.getResourcesConsumed();
        System.out.println("\tResources Consumed");
        System.out.format("\t\tReplica Hours: %s\n", resourcesConsumed.getReplicaHours());
        CompletionStats completionStats = batchPredictionJobResponse.getCompletionStats();
        System.out.println("\tCompletion Stats");
        System.out.format("\t\tSuccessful Count: %s\n", completionStats.getSuccessfulCount());
        System.out.format("\t\tFailed Count: %s\n", completionStats.getFailedCount());
        System.out.format("\t\tIncomplete Count: %s\n", completionStats.getIncompleteCount());
    }
}
Also used : Status(com.google.rpc.Status) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) VideoObjectTrackingPredictionParams(com.google.cloud.aiplatform.v1.schema.predict.params.VideoObjectTrackingPredictionParams) ModelName(com.google.cloud.aiplatform.v1.ModelName) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) ManualBatchTuningParameters(com.google.cloud.aiplatform.v1.ManualBatchTuningParameters) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) MachineSpec(com.google.cloud.aiplatform.v1.MachineSpec) BigQueryDestination(com.google.cloud.aiplatform.v1.BigQueryDestination) Any(com.google.protobuf.Any) LocationName(com.google.cloud.aiplatform.v1.LocationName) OutputInfo(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo) BatchDedicatedResources(com.google.cloud.aiplatform.v1.BatchDedicatedResources) OutputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig) ResourcesConsumed(com.google.cloud.aiplatform.v1.ResourcesConsumed) Value(com.google.protobuf.Value) InputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) BigQuerySource(com.google.cloud.aiplatform.v1.BigQuerySource) CompletionStats(com.google.cloud.aiplatform.v1.CompletionStats)

Example 28 with LocationName

use of com.google.cloud.aiplatform.v1.LocationName in project java-aiplatform by googleapis.

the class CreateDataLabelingJobActiveLearningSample method createDataLabelingJobActiveLearningSample.

static void createDataLabelingJobActiveLearningSample(String project, String displayName, String dataset, String instructionUri, String inputsSchemaUri, String annotationSpec) throws IOException {
    JobServiceSettings settings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    String location = "us-central1";
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient client = JobServiceClient.create(settings)) {
        JsonArray jsonAnnotationSpecs = new JsonArray();
        jsonAnnotationSpecs.add(annotationSpec);
        JsonObject jsonInputs = new JsonObject();
        jsonInputs.add("annotation_specs", jsonAnnotationSpecs);
        Value.Builder inputsBuilder = Value.newBuilder();
        JsonFormat.parser().merge(jsonInputs.toString(), inputsBuilder);
        Value inputs = inputsBuilder.build();
        ActiveLearningConfig activeLearningConfig = ActiveLearningConfig.newBuilder().setMaxDataItemCount(1).build();
        String datasetName = DatasetName.of(project, location, dataset).toString();
        DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).addDatasets(datasetName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri(inputsSchemaUri).setInputs(inputs).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "data_labeling_job_active_learning").setActiveLearningConfig(activeLearningConfig).build();
        LocationName parent = LocationName.of(project, location);
        DataLabelingJob response = client.createDataLabelingJob(parent, dataLabelingJob);
        System.out.format("response: %s\n", response);
        System.out.format("Name: %s\n", response.getName());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ActiveLearningConfig(com.google.cloud.aiplatform.v1.ActiveLearningConfig) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) JsonObject(com.google.gson.JsonObject) DataLabelingJob(com.google.cloud.aiplatform.v1.DataLabelingJob) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 29 with LocationName

use of com.google.cloud.aiplatform.v1.LocationName in project java-aiplatform by googleapis.

the class CreateDataLabelingJobImageSample method createDataLabelingJobImage.

static void createDataLabelingJobImage(String project, String displayName, String datasetId, String instructionUri, String annotationSpec) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
        Value.Builder annotationSpecValue = Value.newBuilder();
        JsonFormat.parser().merge(jsonString, annotationSpecValue);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri("gs://google-cloud-aiplatform/schema/datalabelingjob/inputs/" + "image_classification.yaml").addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
        DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
        System.out.println("Create Data Labeling Job Image Response");
        System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
        System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
        System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
        System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
        System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
        System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
        System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
        System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
        System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
        System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
        System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
        System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
        for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
            System.out.println("\tAnnotation Level");
            System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
            System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
        }
        Money money = dataLabelingJobResponse.getCurrentSpend();
        System.out.println("\tCurrent Spend");
        System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
        System.out.format("\t\tUnits: %s\n", money.getUnits());
        System.out.format("\t\tNanos: %s\n", money.getNanos());
    }
}
Also used : Money(com.google.type.Money) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) DataLabelingJob(com.google.cloud.aiplatform.v1.DataLabelingJob) Map(java.util.Map) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 30 with LocationName

use of com.google.cloud.aiplatform.v1.LocationName in project java-aiplatform by googleapis.

the class CreateDataLabelingJobSample method createDataLabelingJob.

static void createDataLabelingJob(String project, String displayName, String datasetId, String instructionUri, String inputsSchemaUri, String annotationSpec) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
        Value.Builder annotationSpecValue = Value.newBuilder();
        JsonFormat.parser().merge(jsonString, annotationSpecValue);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri(inputsSchemaUri).addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
        DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
        System.out.println("Create Data Labeling Job Response");
        System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
        System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
        System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
        System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
        System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
        System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
        System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
        System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
        System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
        System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
        System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
        System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
        for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
            System.out.println("\tAnnotation Level");
            System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
            System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
        }
        Money money = dataLabelingJobResponse.getCurrentSpend();
        System.out.println("\tCurrent Spend");
        System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
        System.out.format("\t\tUnits: %s\n", money.getUnits());
        System.out.format("\t\tNanos: %s\n", money.getNanos());
    }
}
Also used : Money(com.google.type.Money) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) DataLabelingJob(com.google.cloud.aiplatform.v1.DataLabelingJob) Map(java.util.Map) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Aggregations

Test (org.junit.Test)54 AbstractMessage (com.google.protobuf.AbstractMessage)37 LocationName (com.google.cloud.aiplatform.v1.LocationName)36 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 LocationName (com.google.cloud.translate.v3beta1.LocationName)18 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)18 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)15 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)15 Value (com.google.protobuf.Value)15 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)14 Model (com.google.cloud.aiplatform.v1.Model)14 StatusRuntimeException (io.grpc.StatusRuntimeException)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)13 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)13 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)13 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13