Search in sources :

Example 46 with AutoMlClient

use of com.google.cloud.automl.v1.AutoMlClient 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 47 with AutoMlClient

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

the class VisionClassificationCreateDataset method createDataset.

// Create a dataset
static void createDataset(String projectId, 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");
        // Specify the classification type
        // Types:
        // MultiLabel: Multiple labels are allowed for one example.
        // MultiClass: At most one label is allowed per example.
        ClassificationType classificationType = ClassificationType.MULTILABEL;
        ImageClassificationDatasetMetadata metadata = ImageClassificationDatasetMetadata.newBuilder().setClassificationType(classificationType).build();
        Dataset dataset = Dataset.newBuilder().setDisplayName(displayName).setImageClassificationDatasetMetadata(metadata).build();
        OperationFuture<Dataset, OperationMetadata> future = client.createDatasetAsync(projectLocation, dataset);
        Dataset createdDataset = future.get();
        // Display the dataset information.
        System.out.format("Dataset name: %s\n", createdDataset.getName());
        // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
        // required for other methods.
        // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
        String[] names = createdDataset.getName().split("/");
        String datasetId = names[names.length - 1];
        System.out.format("Dataset id: %s\n", datasetId);
    }
}
Also used : ImageClassificationDatasetMetadata(com.google.cloud.automl.v1.ImageClassificationDatasetMetadata) Dataset(com.google.cloud.automl.v1.Dataset) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) ClassificationType(com.google.cloud.automl.v1.ClassificationType) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 48 with AutoMlClient

use of com.google.cloud.automl.v1.AutoMlClient 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 49 with AutoMlClient

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

the class VisionClassificationDeployModelNodeCount method visionClassificationDeployModelNodeCount.

// Deploy a model for prediction with a specified node count (can be used to redeploy a model)
static void visionClassificationDeployModelNodeCount(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);
        ImageClassificationModelDeploymentMetadata metadata = ImageClassificationModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).setImageClassificationModelDeploymentMetadata(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) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) ImageClassificationModelDeploymentMetadata(com.google.cloud.automl.v1.ImageClassificationModelDeploymentMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 50 with AutoMlClient

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

the class SetEndpoint method setEndpoint.

// Change your endpoint
static void setEndpoint(String projectId) throws IOException {
    // [START automl_set_endpoint]
    AutoMlSettings settings = AutoMlSettings.newBuilder().setEndpoint("eu-automl.googleapis.com:443").build();
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    AutoMlClient client = AutoMlClient.create(settings);
    // A resource that represents Google Cloud Platform location.
    LocationName projectLocation = LocationName.of(projectId, "eu");
    // [END automl_set_endpoint]
    ListDatasetsRequest request = ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).setFilter("translation_dataset_metadata:*").build();
    // List all the datasets available
    System.out.println("List of datasets:");
    for (Dataset dataset : client.listDatasets(request).iterateAll()) {
        System.out.println(dataset);
    }
    client.close();
}
Also used : Dataset(com.google.cloud.automl.v1beta1.Dataset) AutoMlSettings(com.google.cloud.automl.v1beta1.AutoMlSettings) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) LocationName(com.google.cloud.automl.v1beta1.LocationName) ListDatasetsRequest(com.google.cloud.automl.v1beta1.ListDatasetsRequest)

Aggregations

AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)41 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)31 Empty (com.google.protobuf.Empty)20 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)18 LocationName (com.google.cloud.automl.v1.LocationName)17 Model (com.google.cloud.automl.v1.Model)16 ModelName (com.google.cloud.automl.v1.ModelName)16 LocationName (com.google.cloud.automl.v1beta1.LocationName)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 PrintStream (java.io.PrintStream)12 Before (org.junit.Before)12 ModelName (com.google.cloud.automl.v1beta1.ModelName)11 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)11 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)10 Dataset (com.google.cloud.automl.v1.Dataset)8 Model (com.google.cloud.automl.v1beta1.Model)8 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 Operation (com.google.longrunning.Operation)6 DatasetName (com.google.cloud.automl.v1.DatasetName)5 DatasetName (com.google.cloud.automl.v1beta1.DatasetName)5