Search in sources :

Example 51 with AutoMlClient

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

the class TablesCreateDataset method createDataset.

// Create a dataset
static void createDataset(String projectId, String displayName) throws IOException {
    // 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");
        TablesDatasetMetadata metadata = TablesDatasetMetadata.newBuilder().build();
        Dataset dataset = Dataset.newBuilder().setDisplayName(displayName).setTablesDatasetMetadata(metadata).build();
        Dataset createdDataset = client.createDataset(projectLocation, dataset);
        // 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 : TablesDatasetMetadata(com.google.cloud.automl.v1beta1.TablesDatasetMetadata) Dataset(com.google.cloud.automl.v1beta1.Dataset) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) LocationName(com.google.cloud.automl.v1beta1.LocationName)

Example 52 with AutoMlClient

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

the class TablesCreateModel method createModel.

// Create a model
static void createModel(String projectId, String datasetId, String tableSpecId, String columnSpecId, 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");
        // Get the complete path of the column.
        ColumnSpecName columnSpecName = ColumnSpecName.of(projectId, "us-central1", datasetId, tableSpecId, columnSpecId);
        // Build the get column spec.
        ColumnSpec targetColumnSpec = ColumnSpec.newBuilder().setName(columnSpecName.toString()).build();
        // Set model metadata.
        TablesModelMetadata metadata = TablesModelMetadata.newBuilder().setTargetColumnSpec(targetColumnSpec).setTrainBudgetMilliNodeHours(24000).build();
        Model model = Model.newBuilder().setDisplayName(displayName).setDatasetId(datasetId).setTablesModelMetadata(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 : ColumnSpecName(com.google.cloud.automl.v1beta1.ColumnSpecName) ColumnSpec(com.google.cloud.automl.v1beta1.ColumnSpec) TablesModelMetadata(com.google.cloud.automl.v1beta1.TablesModelMetadata) Model(com.google.cloud.automl.v1beta1.Model) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) LocationName(com.google.cloud.automl.v1beta1.LocationName)

Example 53 with AutoMlClient

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

the class VideoClassificationCreateModel 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.
        VideoClassificationModelMetadata metadata = VideoClassificationModelMetadata.newBuilder().build();
        Model model = Model.newBuilder().setDisplayName(displayName).setDatasetId(datasetId).setVideoClassificationModelMetadata(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 : VideoClassificationModelMetadata(com.google.cloud.automl.v1beta1.VideoClassificationModelMetadata) Model(com.google.cloud.automl.v1beta1.Model) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) LocationName(com.google.cloud.automl.v1beta1.LocationName)

Example 54 with AutoMlClient

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

the class LanguageSentimentAnalysisCreateModel 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.
        System.out.println(datasetId);
        TextSentimentModelMetadata metadata = TextSentimentModelMetadata.newBuilder().build();
        Model model = Model.newBuilder().setDisplayName(displayName).setDatasetId(datasetId).setTextSentimentModelMetadata(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 : TextSentimentModelMetadata(com.google.cloud.automl.v1.TextSentimentModelMetadata) 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 55 with AutoMlClient

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

the class LanguageTextClassificationCreateDataset 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;
        // Specify the text classification type for the dataset.
        TextClassificationDatasetMetadata metadata = TextClassificationDatasetMetadata.newBuilder().setClassificationType(classificationType).build();
        Dataset dataset = Dataset.newBuilder().setDisplayName(displayName).setTextClassificationDatasetMetadata(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 : Dataset(com.google.cloud.automl.v1.Dataset) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) ClassificationType(com.google.cloud.automl.v1.ClassificationType) TextClassificationDatasetMetadata(com.google.cloud.automl.v1.TextClassificationDatasetMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

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