use of com.google.cloud.automl.v1.BatchPredictOutputConfig in project java-automl by googleapis.
the class BatchPredict method batchPredict.
static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient client = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, "us-central1", modelId);
// Configure the source of the file from a GCS bucket
GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build();
BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build();
// Configure where to store the output in a GCS bucket
GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build();
BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
// Build the request that will be sent to the API
BatchPredictRequest request = BatchPredictRequest.newBuilder().setName(name.toString()).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
// Start an asynchronous request
OperationFuture<BatchPredictResult, OperationMetadata> future = client.batchPredictAsync(request);
System.out.println("Waiting for operation to complete...");
BatchPredictResult response = future.get();
System.out.println("Batch Prediction results saved to specified Cloud Storage bucket.");
}
}
use of com.google.cloud.automl.v1.BatchPredictOutputConfig in project java-automl by googleapis.
the class TablesBatchPredictBigQuery method batchPredict.
static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient client = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, "us-central1", modelId);
// Configure the source of the file from BigQuery
BigQuerySource bigQuerySource = BigQuerySource.newBuilder().setInputUri(inputUri).build();
BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().setBigquerySource(bigQuerySource).build();
// Configure where to store the output in BigQuery
BigQueryDestination bigQueryDestination = BigQueryDestination.newBuilder().setOutputUri(outputUri).build();
BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().setBigqueryDestination(bigQueryDestination).build();
// Build the request that will be sent to the API
BatchPredictRequest request = BatchPredictRequest.newBuilder().setName(name.toString()).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
// Start an asynchronous request
OperationFuture<BatchPredictResult, OperationMetadata> future = client.batchPredictAsync(request);
System.out.println("Waiting for operation to complete...");
BatchPredictResult response = future.get();
System.out.println("Batch Prediction results saved to BigQuery.");
}
}
use of com.google.cloud.automl.v1.BatchPredictOutputConfig in project java-automl by googleapis.
the class BatchPredict method batchPredict.
static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient client = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, "us-central1", modelId);
GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build();
BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build();
GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build();
BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
BatchPredictRequest request = BatchPredictRequest.newBuilder().setName(name.toString()).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
OperationFuture<BatchPredictResult, OperationMetadata> future = client.batchPredictAsync(request);
System.out.println("Waiting for operation to complete...");
BatchPredictResult response = future.get();
System.out.println("Batch Prediction results saved to specified Cloud Storage bucket.");
}
}
Aggregations