Search in sources :

Example 46 with Model

use of com.google.cloud.automl.v1beta1.Model in project java-automl by googleapis.

the class DeleteModel method deleteModel.

// Delete a model
static void deleteModel(String projectId, String modelId) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the model.
        ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
        // Delete a model.
        Empty response = client.deleteModelAsync(modelFullId).get();
        System.out.println("Model deletion started...");
        System.out.println(String.format("Model deleted. %s", response));
    }
}
Also used : Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1beta1.ModelName) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 47 with Model

use of com.google.cloud.automl.v1beta1.Model in project java-automl by googleapis.

the class DeployModel method deployModel.

// Deploy a model for prediction
static void deployModel(String projectId, String modelId) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the model.
        ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
        OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
        future.get();
        System.out.println("Model deployment finished");
    }
}
Also used : DeployModelRequest(com.google.cloud.automl.v1beta1.DeployModelRequest) Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1beta1.ModelName) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 48 with Model

use of com.google.cloud.automl.v1beta1.Model 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.");
    }
}
Also used : BatchPredictRequest(com.google.cloud.automl.v1beta1.BatchPredictRequest) ModelName(com.google.cloud.automl.v1beta1.ModelName) GcsSource(com.google.cloud.automl.v1beta1.GcsSource) BatchPredictInputConfig(com.google.cloud.automl.v1beta1.BatchPredictInputConfig) BatchPredictOutputConfig(com.google.cloud.automl.v1beta1.BatchPredictOutputConfig) BatchPredictResult(com.google.cloud.automl.v1beta1.BatchPredictResult) GcsDestination(com.google.cloud.automl.v1beta1.GcsDestination) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) PredictionServiceClient(com.google.cloud.automl.v1beta1.PredictionServiceClient)

Example 49 with Model

use of com.google.cloud.automl.v1beta1.Model 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.");
    }
}
Also used : BatchPredictRequest(com.google.cloud.automl.v1beta1.BatchPredictRequest) ModelName(com.google.cloud.automl.v1beta1.ModelName) BatchPredictInputConfig(com.google.cloud.automl.v1beta1.BatchPredictInputConfig) BatchPredictOutputConfig(com.google.cloud.automl.v1beta1.BatchPredictOutputConfig) BatchPredictResult(com.google.cloud.automl.v1beta1.BatchPredictResult) BigQuerySource(com.google.cloud.automl.v1beta1.BigQuerySource) BigQueryDestination(com.google.cloud.automl.v1beta1.BigQueryDestination) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) PredictionServiceClient(com.google.cloud.automl.v1beta1.PredictionServiceClient)

Example 50 with Model

use of com.google.cloud.automl.v1beta1.Model in project java-automl by googleapis.

the class TablesGetModel method getModel.

// Demonstrates using the AutoML client to get model details.
public static void getModel(String projectId, String computeRegion, String modelId) throws IOException, StatusRuntimeException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the model.
        ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId);
        // Get complete detail of the model.
        Model model = client.getModel(modelFullId);
        // Display the model information.
        System.out.format("Model name: %s%n", model.getName());
        System.out.format("Model Id: %s\n", model.getName().split("/")[model.getName().split("/").length - 1]);
        System.out.format("Model display name: %s%n", model.getDisplayName());
        System.out.format("Dataset Id: %s%n", model.getDatasetId());
        System.out.println("Tables Model Metadata: ");
        System.out.format("\tTraining budget: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());
        System.out.format("\tTraining cost: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        String createTime = dateFormat.format(new java.util.Date(model.getCreateTime().getSeconds() * 1000));
        System.out.format("Model create time: %s%n", createTime);
        System.out.format("Model deployment state: %s%n", model.getDeploymentState());
        // Get features of top importance
        for (TablesModelColumnInfo info : model.getTablesModelMetadata().getTablesModelColumnInfoList()) {
            System.out.format("Column: %s - Importance: %.2f%n", info.getColumnDisplayName(), info.getFeatureImportance());
        }
    }
}
Also used : TablesModelColumnInfo(com.google.cloud.automl.v1beta1.TablesModelColumnInfo) ModelName(com.google.cloud.automl.v1beta1.ModelName) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Model(com.google.cloud.automl.v1beta1.Model) SimpleDateFormat(java.text.SimpleDateFormat) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Aggregations

Test (org.junit.Test)51 Model (org.eclipse.xtext.valueconverter.bug250313.Model)30 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)17 Model (com.google.cloud.aiplatform.v1.Model)16 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)16 Model (com.google.cloud.automl.v1.Model)16 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)16 ModelName (com.google.cloud.automl.v1beta1.ModelName)15 LocationName (com.google.cloud.aiplatform.v1.LocationName)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)14 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)14 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)14 InputDataConfig (com.google.cloud.aiplatform.v1.InputDataConfig)13 ModelContainerSpec (com.google.cloud.aiplatform.v1.ModelContainerSpec)13 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)12 FilterSplit (com.google.cloud.aiplatform.v1.FilterSplit)11 FractionSplit (com.google.cloud.aiplatform.v1.FractionSplit)11 PredefinedSplit (com.google.cloud.aiplatform.v1.PredefinedSplit)11 TimestampSplit (com.google.cloud.aiplatform.v1.TimestampSplit)11 Status (com.google.rpc.Status)11