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