use of com.google.cloud.aiplatform.v1beta1.JobServiceSettings in project java-aiplatform by googleapis.
the class CreateBatchPredictionJobBigquerySample method createBatchPredictionJobBigquerySample.
static void createBatchPredictionJobBigquerySample(String project, String displayName, String model, String instancesFormat, String bigquerySourceInputUri, String predictionsFormat, String bigqueryDestinationOutputUri) 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)) {
JsonObject jsonModelParameters = new JsonObject();
Value.Builder modelParametersBuilder = Value.newBuilder();
JsonFormat.parser().merge(jsonModelParameters.toString(), modelParametersBuilder);
Value modelParameters = modelParametersBuilder.build();
BigQuerySource bigquerySource = BigQuerySource.newBuilder().setInputUri(bigquerySourceInputUri).build();
BatchPredictionJob.InputConfig inputConfig = BatchPredictionJob.InputConfig.newBuilder().setInstancesFormat(instancesFormat).setBigquerySource(bigquerySource).build();
BigQueryDestination bigqueryDestination = BigQueryDestination.newBuilder().setOutputUri(bigqueryDestinationOutputUri).build();
BatchPredictionJob.OutputConfig outputConfig = BatchPredictionJob.OutputConfig.newBuilder().setPredictionsFormat(predictionsFormat).setBigqueryDestination(bigqueryDestination).build();
String modelName = ModelName.of(project, location, model).toString();
BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setModelParameters(modelParameters).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
LocationName parent = LocationName.of(project, location);
BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
System.out.format("response: %s\n", response);
System.out.format("\tName: %s\n", response.getName());
}
}
use of com.google.cloud.aiplatform.v1beta1.JobServiceSettings in project java-aiplatform by googleapis.
the class CreateBatchPredictionJobSample method createBatchPredictionJobSample.
static void createBatchPredictionJobSample(String project, String displayName, String model, String instancesFormat, String gcsSourceUri, String predictionsFormat, String gcsDestinationOutputUriPrefix) 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)) {
// Passing in an empty Value object for model parameters
Value modelParameters = ValueConverter.EMPTY_VALUE;
GcsSource gcsSource = GcsSource.newBuilder().addUris(gcsSourceUri).build();
BatchPredictionJob.InputConfig inputConfig = BatchPredictionJob.InputConfig.newBuilder().setInstancesFormat(instancesFormat).setGcsSource(gcsSource).build();
GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
BatchPredictionJob.OutputConfig outputConfig = BatchPredictionJob.OutputConfig.newBuilder().setPredictionsFormat(predictionsFormat).setGcsDestination(gcsDestination).build();
MachineSpec machineSpec = MachineSpec.newBuilder().setMachineType("n1-standard-2").setAcceleratorType(AcceleratorType.NVIDIA_TESLA_K80).setAcceleratorCount(1).build();
BatchDedicatedResources dedicatedResources = BatchDedicatedResources.newBuilder().setMachineSpec(machineSpec).setStartingReplicaCount(1).setMaxReplicaCount(1).build();
String modelName = ModelName.of(project, location, model).toString();
BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setModelParameters(modelParameters).setInputConfig(inputConfig).setOutputConfig(outputConfig).setDedicatedResources(dedicatedResources).build();
LocationName parent = LocationName.of(project, location);
BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
System.out.format("response: %s\n", response);
System.out.format("\tName: %s\n", response.getName());
}
}
use of com.google.cloud.aiplatform.v1beta1.JobServiceSettings in project java-aiplatform by googleapis.
the class CreateBatchPredictionJobTextEntityExtractionSample method createBatchPredictionJobTextEntityExtractionSample.
static void createBatchPredictionJobTextEntityExtractionSample(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);
System.out.format("\tname:%s\n", response.getName());
} catch (ApiException ex) {
System.out.format("Exception: %s\n", ex.getLocalizedMessage());
}
}
}
use of com.google.cloud.aiplatform.v1beta1.JobServiceSettings in project java-aiplatform by googleapis.
the class CreateBatchPredictionJobVideoActionRecognitionSample method createBatchPredictionJobVideoActionRecognitionSample.
static void createBatchPredictionJobVideoActionRecognitionSample(String project, String displayName, String model, String gcsSourceUri, String gcsDestinationOutputUriPrefix) 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)) {
Value modelParameters = ValueConverter.EMPTY_VALUE;
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();
String modelName = ModelName.of(project, location, model).toString();
BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setModelParameters(modelParameters).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
LocationName parent = LocationName.of(project, location);
BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
System.out.format("response: %s\n", response);
System.out.format("\tName: %s\n", response.getName());
}
}
use of com.google.cloud.aiplatform.v1beta1.JobServiceSettings in project java-aiplatform by googleapis.
the class CreateDataLabelingJobSpecialistPoolSample method createDataLabelingJobSpecialistPoolSample.
static void createDataLabelingJobSpecialistPoolSample(String project, String displayName, String dataset, String specialistPool, 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();
String datasetName = DatasetName.of(project, location, dataset).toString();
String specialistPoolName = SpecialistPoolName.of(project, location, specialistPool).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_specialist_pool").addSpecialistPools(specialistPoolName).build();
LocationName parent = LocationName.of(project, location);
DataLabelingJob response = client.createDataLabelingJob(parent, dataLabelingJob);
System.out.format("response: %s\n", response);
}
}
Aggregations