Search in sources :

Example 1 with BatchPredictionJob

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

the class JobServiceClientTest method listBatchPredictionJobsTest2.

@Test
public void listBatchPredictionJobsTest2() throws Exception {
    BatchPredictionJob responsesElement = BatchPredictionJob.newBuilder().build();
    ListBatchPredictionJobsResponse expectedResponse = ListBatchPredictionJobsResponse.newBuilder().setNextPageToken("").addAllBatchPredictionJobs(Arrays.asList(responsesElement)).build();
    mockJobService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListBatchPredictionJobsPagedResponse pagedListResponse = client.listBatchPredictionJobs(parent);
    List<BatchPredictionJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBatchPredictionJobsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockJobService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBatchPredictionJobsRequest actualRequest = ((ListBatchPredictionJobsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListBatchPredictionJobsPagedResponse(com.google.cloud.aiplatform.v1.JobServiceClient.ListBatchPredictionJobsPagedResponse) Test(org.junit.Test)

Example 2 with BatchPredictionJob

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

the class GetBatchPredictionJobSample method getBatchPredictionJobSample.

static void getBatchPredictionJobSample(String project, String batchPredictionJobId) 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";
        BatchPredictionJobName batchPredictionJobName = BatchPredictionJobName.of(project, location, batchPredictionJobId);
        BatchPredictionJob batchPredictionJob = jobServiceClient.getBatchPredictionJob(batchPredictionJobName);
        System.out.println("Get Batch Prediction Job Response");
        System.out.format("\tName: %s\n", batchPredictionJob.getName());
        System.out.format("\tDisplay Name: %s\n", batchPredictionJob.getDisplayName());
        System.out.format("\tModel: %s\n", batchPredictionJob.getModel());
        System.out.format("\tModel Parameters: %s\n", batchPredictionJob.getModelParameters());
        System.out.format("\tState: %s\n", batchPredictionJob.getState());
        System.out.format("\tCreate Time: %s\n", batchPredictionJob.getCreateTime());
        System.out.format("\tStart Time: %s\n", batchPredictionJob.getStartTime());
        System.out.format("\tEnd Time: %s\n", batchPredictionJob.getEndTime());
        System.out.format("\tUpdate Time: %s\n", batchPredictionJob.getUpdateTime());
        System.out.format("\tLabels: %s\n", batchPredictionJob.getLabelsMap());
        InputConfig inputConfig = batchPredictionJob.getInputConfig();
        System.out.println("\tInput Config");
        System.out.format("\t\tInstances Format: %s\n", inputConfig.getInstancesFormat());
        GcsSource gcsSource = inputConfig.getGcsSource();
        System.out.println("\t\tGcs Source");
        System.out.format("\t\t\tUris: %s\n", gcsSource.getUrisList());
        BigQuerySource bigquerySource = inputConfig.getBigquerySource();
        System.out.println("\t\tBigquery Source");
        System.out.format("\t\t\tInput Uri: %s\n", bigquerySource.getInputUri());
        OutputConfig outputConfig = batchPredictionJob.getOutputConfig();
        System.out.println("\tOutput Config");
        System.out.format("\t\tPredictions Format: %s\n", outputConfig.getPredictionsFormat());
        GcsDestination gcsDestination = outputConfig.getGcsDestination();
        System.out.println("\t\tGcs Destination");
        System.out.format("\t\t\tOutput Uri Prefix: %s\n", gcsDestination.getOutputUriPrefix());
        BigQueryDestination bigqueryDestination = outputConfig.getBigqueryDestination();
        System.out.println("\t\tBigquery Destination");
        System.out.format("\t\t\tOutput Uri: %s\n", bigqueryDestination.getOutputUri());
        OutputInfo outputInfo = batchPredictionJob.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 = batchPredictionJob.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> detailsList = status.getDetailsList();
        for (Status partialFailure : batchPredictionJob.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> details = partialFailure.getDetailsList();
        }
        ResourcesConsumed resourcesConsumed = batchPredictionJob.getResourcesConsumed();
        System.out.println("\tResources Consumed");
        System.out.format("\t\tReplica Hours: %s\n", resourcesConsumed.getReplicaHours());
        CompletionStats completionStats = batchPredictionJob.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) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) BigQueryDestination(com.google.cloud.aiplatform.v1.BigQueryDestination) Any(com.google.protobuf.Any) OutputInfo(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo) OutputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig) ResourcesConsumed(com.google.cloud.aiplatform.v1.ResourcesConsumed) BatchPredictionJobName(com.google.cloud.aiplatform.v1.BatchPredictionJobName) InputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig) BigQuerySource(com.google.cloud.aiplatform.v1.BigQuerySource) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) CompletionStats(com.google.cloud.aiplatform.v1.CompletionStats)

Example 3 with BatchPredictionJob

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

the class CreateBatchPredictionJobTextClassificationSample method createBatchPredictionJobTextClassificationSample.

static void createBatchPredictionJobTextClassificationSample(String project, String location, String displayName, String modelId, String gcsSourceUri, String gcsDestinationOutputUriPrefix) throws IOException {
    // The AI Platform services require regional API endpoints.
    JobServiceSettings settings = 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 client = JobServiceClient.create(settings)) {
        try {
            String modelName = ModelName.of(project, location, modelId).toString();
            GcsSource gcsSource = GcsSource.newBuilder().addUris(gcsSourceUri).build();
            BatchPredictionJob.InputConfig inputConfig = BatchPredictionJob.InputConfig.newBuilder().setInstancesFormat("jsonl").setGcsSource(gcsSource).build();
            GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
            BatchPredictionJob.OutputConfig outputConfig = BatchPredictionJob.OutputConfig.newBuilder().setPredictionsFormat("jsonl").setGcsDestination(gcsDestination).build();
            BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
            LocationName parent = LocationName.of(project, location);
            BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
            System.out.format("response: %s\n", response);
        } catch (ApiException ex) {
            System.out.format("Exception: %s\n", ex.getLocalizedMessage());
        }
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) LocationName(com.google.cloud.aiplatform.v1.LocationName) ApiException(com.google.api.gax.rpc.ApiException)

Example 4 with BatchPredictionJob

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

the class CreateBatchPredictionJobTextSentimentAnalysisSample method createBatchPredictionJobTextSentimentAnalysisSample.

static void createBatchPredictionJobTextSentimentAnalysisSample(String project, String location, String displayName, String modelId, String gcsSourceUri, String gcsDestinationOutputUriPrefix) throws IOException {
    // The AI Platform services require regional API endpoints.
    JobServiceSettings settings = 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 client = JobServiceClient.create(settings)) {
        try {
            String modelName = ModelName.of(project, location, modelId).toString();
            GcsSource gcsSource = GcsSource.newBuilder().addUris(gcsSourceUri).build();
            BatchPredictionJob.InputConfig inputConfig = BatchPredictionJob.InputConfig.newBuilder().setInstancesFormat("jsonl").setGcsSource(gcsSource).build();
            GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
            BatchPredictionJob.OutputConfig outputConfig = BatchPredictionJob.OutputConfig.newBuilder().setPredictionsFormat("jsonl").setGcsDestination(gcsDestination).build();
            BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
            LocationName parent = LocationName.of(project, location);
            BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
            System.out.format("response: %s\n", response);
        } catch (ApiException ex) {
            System.out.format("Exception: %s\n", ex.getLocalizedMessage());
        }
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) LocationName(com.google.cloud.aiplatform.v1.LocationName) ApiException(com.google.api.gax.rpc.ApiException)

Example 5 with BatchPredictionJob

use of com.google.cloud.aiplatform.v1.BatchPredictionJob 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)

Aggregations

BatchPredictionJob (com.google.cloud.aiplatform.v1.BatchPredictionJob)9 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)9 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)9 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)8 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)8 LocationName (com.google.cloud.aiplatform.v1.LocationName)8 Value (com.google.protobuf.Value)5 BigQueryDestination (com.google.cloud.aiplatform.v1.BigQueryDestination)4 BigQuerySource (com.google.cloud.aiplatform.v1.BigQuerySource)4 ApiException (com.google.api.gax.rpc.ApiException)3 BatchDedicatedResources (com.google.cloud.aiplatform.v1.BatchDedicatedResources)3 InputConfig (com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig)3 OutputConfig (com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig)3 OutputInfo (com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo)3 CompletionStats (com.google.cloud.aiplatform.v1.CompletionStats)3 MachineSpec (com.google.cloud.aiplatform.v1.MachineSpec)3 ResourcesConsumed (com.google.cloud.aiplatform.v1.ResourcesConsumed)3 Any (com.google.protobuf.Any)3 Status (com.google.rpc.Status)3 ListBatchPredictionJobsPagedResponse (com.google.cloud.aiplatform.v1.JobServiceClient.ListBatchPredictionJobsPagedResponse)2