Search in sources :

Example 26 with OperationMetadata

use of com.google.cloud.automl.v1.OperationMetadata in project java-automl by googleapis.

the class UndeployModel method undeployModel.

// Undeploy a model from prediction
static void undeployModel(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);
        UndeployModelRequest request = UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
        OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(request);
        future.get();
        System.out.println("Model undeployment finished");
    }
}
Also used : Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1.ModelName) UndeployModelRequest(com.google.cloud.automl.v1.UndeployModelRequest) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 27 with OperationMetadata

use of com.google.cloud.automl.v1.OperationMetadata in project java-automl by googleapis.

the class VisionClassificationCreateModel method createModel.

// Create a model
static void createModel(String projectId, String datasetId, String displayName) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        // Set model metadata.
        ImageClassificationModelMetadata metadata = ImageClassificationModelMetadata.newBuilder().setTrainBudgetMilliNodeHours(24000).build();
        Model model = Model.newBuilder().setDisplayName(displayName).setDatasetId(datasetId).setImageClassificationModelMetadata(metadata).build();
        // Create a model with the model metadata in the region.
        OperationFuture<Model, OperationMetadata> future = client.createModelAsync(projectLocation, model);
        // OperationFuture.get() will block until the model is created, which may take several hours.
        // You can use OperationFuture.getInitialFuture to get a future representing the initial
        // response to the request, which contains information while the operation is in progress.
        System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName());
        System.out.println("Training started...");
    }
}
Also used : ImageClassificationModelMetadata(com.google.cloud.automl.v1.ImageClassificationModelMetadata) Model(com.google.cloud.automl.v1.Model) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 28 with OperationMetadata

use of com.google.cloud.automl.v1.OperationMetadata in project java-automl by googleapis.

the class ClassificationDeployModelNodeCount method classificationDeployModelNodeCount.

// Deploy a model with a specified node count
static void classificationDeployModelNodeCount(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);
        // Set how many nodes the model is deployed on
        ImageClassificationModelDeploymentMetadata deploymentMetadata = ImageClassificationModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).setImageClassificationModelDeploymentMetadata(deploymentMetadata).build();
        // Deploy the model
        OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
        future.get();
        System.out.println("Model deployment on 2 nodes 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) ImageClassificationModelDeploymentMetadata(com.google.cloud.automl.v1beta1.ImageClassificationModelDeploymentMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 29 with OperationMetadata

use of com.google.cloud.automl.v1.OperationMetadata in project java-automl by googleapis.

the class VisionObjectDetectionDeployModelNodeCount method visionObjectDetectionDeployModelNodeCount.

// Deploy a model for prediction with a specified node count (can be used to redeploy a model)
static void visionObjectDetectionDeployModelNodeCount(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);
        ImageObjectDetectionModelDeploymentMetadata metadata = ImageObjectDetectionModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).setImageObjectDetectionModelDeploymentMetadata(metadata).build();
        OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
        future.get();
        System.out.println("Model deployment finished");
    }
}
Also used : DeployModelRequest(com.google.cloud.automl.v1.DeployModelRequest) Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1.ModelName) ImageObjectDetectionModelDeploymentMetadata(com.google.cloud.automl.v1.ImageObjectDetectionModelDeploymentMetadata) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 30 with OperationMetadata

use of com.google.cloud.automl.v1.OperationMetadata in project java-automl by googleapis.

the class ClassificationUndeployModel method classificationUndeployModel.

// Deploy a model
static void classificationUndeployModel(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);
        // Build deploy model request.
        UndeployModelRequest undeployModelRequest = UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
        // Deploy a model with the deploy model request.
        OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(undeployModelRequest);
        future.get();
        // Display the deployment details of model.
        System.out.println("Model undeploy finished");
    }
}
Also used : Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1.ModelName) UndeployModelRequest(com.google.cloud.automl.v1.UndeployModelRequest) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Aggregations

OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)19 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)18 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)13 Empty (com.google.protobuf.Empty)13 LocationName (com.google.cloud.automl.v1.LocationName)12 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)11 ModelName (com.google.cloud.automl.v1beta1.ModelName)8 Dataset (com.google.cloud.automl.v1.Dataset)6 Model (com.google.cloud.automl.v1.Model)6 ModelName (com.google.cloud.automl.v1.ModelName)6 DeployModelRequest (com.google.cloud.automl.v1beta1.DeployModelRequest)4 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)3 LocationName (com.google.cloud.automl.v1beta1.LocationName)3 Model (com.google.cloud.automl.v1beta1.Model)3 Blob (com.google.cloud.storage.Blob)3 Bucket (com.google.cloud.storage.Bucket)3 Storage (com.google.cloud.storage.Storage)3 Page (com.google.api.gax.paging.Page)2 ClassificationType (com.google.cloud.automl.v1.ClassificationType)2 GcsSource (com.google.cloud.automl.v1.GcsSource)2