Search in sources :

Example 1 with JobServiceSettings

use of com.google.cloud.aiplatform.v1.JobServiceSettings 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 2 with JobServiceSettings

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

the class GetHyperparameterTuningJobSample method getHyperparameterTuningJobSample.

static void getHyperparameterTuningJobSample(String project, String hyperparameterTuningJobId) 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)) {
        HyperparameterTuningJobName name = HyperparameterTuningJobName.of(project, location, hyperparameterTuningJobId);
        HyperparameterTuningJob response = client.getHyperparameterTuningJob(name);
        System.out.format("response: %s\n", response);
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) HyperparameterTuningJob(com.google.cloud.aiplatform.v1.HyperparameterTuningJob) HyperparameterTuningJobName(com.google.cloud.aiplatform.v1.HyperparameterTuningJobName) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient)

Example 3 with JobServiceSettings

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

the class CreateHyperparameterTuningJobSampleTest method tearDown.

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException, TimeoutException {
    JobServiceSettings settings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    try (JobServiceClient client = JobServiceClient.create(settings)) {
        // Cancel hyper parameter job
        String hyperparameterJobName = String.format("projects/%s/locations/us-central1/hyperparameterTuningJobs/%s", PROJECT, hyperparameterJobId);
        client.cancelHyperparameterTuningJob(hyperparameterJobName);
        TimeUnit.MINUTES.sleep(1);
        // Delete the created job
        client.deleteHyperparameterTuningJobAsync(hyperparameterJobName);
        System.out.flush();
        System.setOut(originalPrintStream);
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1beta1.JobServiceSettings) JobServiceClient(com.google.cloud.aiplatform.v1beta1.JobServiceClient) After(org.junit.After)

Example 4 with JobServiceSettings

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

the class CreateHyperparameterTuningJobSample method createHyperparameterTuningJobSample.

static void createHyperparameterTuningJobSample(String project, String displayName, String containerImageUri) 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)) {
        StudySpec.MetricSpec metric0 = StudySpec.MetricSpec.newBuilder().setMetricId("accuracy").setGoal(StudySpec.MetricSpec.GoalType.MAXIMIZE).build();
        StudySpec.ParameterSpec.DoubleValueSpec doubleValueSpec = StudySpec.ParameterSpec.DoubleValueSpec.newBuilder().setMinValue(0.001).setMaxValue(0.1).build();
        StudySpec.ParameterSpec parameter0 = StudySpec.ParameterSpec.newBuilder().setParameterId("lr").setDoubleValueSpec(doubleValueSpec).build();
        StudySpec studySpec = StudySpec.newBuilder().addMetrics(metric0).addParameters(parameter0).build();
        MachineSpec machineSpec = MachineSpec.newBuilder().setMachineType("n1-standard-4").setAcceleratorType(AcceleratorType.NVIDIA_TESLA_K80).setAcceleratorCount(1).build();
        ContainerSpec containerSpec = ContainerSpec.newBuilder().setImageUri(containerImageUri).build();
        WorkerPoolSpec workerPoolSpec0 = WorkerPoolSpec.newBuilder().setMachineSpec(machineSpec).setReplicaCount(1).setContainerSpec(containerSpec).build();
        CustomJobSpec trialJobSpec = CustomJobSpec.newBuilder().addWorkerPoolSpecs(workerPoolSpec0).build();
        HyperparameterTuningJob hyperparameterTuningJob = HyperparameterTuningJob.newBuilder().setDisplayName(displayName).setMaxTrialCount(2).setParallelTrialCount(1).setMaxFailedTrialCount(1).setStudySpec(studySpec).setTrialJobSpec(trialJobSpec).build();
        LocationName parent = LocationName.of(project, location);
        HyperparameterTuningJob response = client.createHyperparameterTuningJob(parent, hyperparameterTuningJob);
        System.out.format("response: %s\n", response);
        System.out.format("Name: %s\n", response.getName());
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) StudySpec(com.google.cloud.aiplatform.v1.StudySpec) ContainerSpec(com.google.cloud.aiplatform.v1.ContainerSpec) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) CustomJobSpec(com.google.cloud.aiplatform.v1.CustomJobSpec) MachineSpec(com.google.cloud.aiplatform.v1.MachineSpec) LocationName(com.google.cloud.aiplatform.v1.LocationName) HyperparameterTuningJob(com.google.cloud.aiplatform.v1.HyperparameterTuningJob) WorkerPoolSpec(com.google.cloud.aiplatform.v1.WorkerPoolSpec)

Example 5 with JobServiceSettings

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

Aggregations

JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)21 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)21 LocationName (com.google.cloud.aiplatform.v1.LocationName)15 Value (com.google.protobuf.Value)10 BatchPredictionJob (com.google.cloud.aiplatform.v1.BatchPredictionJob)9 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)8 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)8 DataLabelingJob (com.google.cloud.aiplatform.v1.DataLabelingJob)5 MachineSpec (com.google.cloud.aiplatform.v1.MachineSpec)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 BatchPredictionJobName (com.google.cloud.aiplatform.v1.BatchPredictionJobName)3 CompletionStats (com.google.cloud.aiplatform.v1.CompletionStats)3 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)3 HyperparameterTuningJob (com.google.cloud.aiplatform.v1.HyperparameterTuningJob)3