Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automl cleanup #1621

Merged
merged 15 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions automl/cloud-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# AutoML Samples

<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=vision/beta/cloud-client/README.md">
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>


This directory contains samples for the [Google Cloud AutoML APIs](https://cloud.google.com/automl/) - [docs](https://cloud.google.com/automl/docs/)

We highly reccommend that you refer to the official documentation pages:
<!--* AutoML Natural Language
* [Classification](https://cloud.google.com/natural-language/automl/docs)
* [Entity Extraction](https://cloud.google.com/natural-language/automl/entity-analysis/docs)
* [Sentiment Analysis](https://cloud.google.com/natural-language/automl/sentiment/docs) -->
* [AutoML Translation](https://cloud.google.com/translate/automl/docs)
<!--* AutoML Video Intelligence
* [Classification](https://cloud.google.com/video-intelligence/automl/docs)
* [Object Tracking](https://cloud.google.com/video-intelligence/automl/object-tracking/docs)
* AutoML Vision
* [Classification](https://cloud.google.com/vision/automl/docs)
* [Edge](https://cloud.google.com/vision/automl/docs/edge-quickstart)
* [Object Detection](https://cloud.google.com/vision/automl/object-detection/docs)
* [AutoML Tables](https://cloud.google.com/automl-tables/docs)-->

This API is part of the larger collection of Cloud Machine Learning APIs.

These Java samples demonstrates how to access the Cloud AutoML API
using the [Google Cloud Client Library for Java][google-cloud-java].

[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java

## Build the samples

Install [Maven](http://maven.apache.org/).

Build your project with:

```
mvn clean package
```

## Sample Types
There are two types of samples: Base and API Specific

The base samples make up a set of samples that have code that
is identical or nearly identical for each AutoML Type. Meaning that for "Base" samples you can use them with any AutoML
Type. However, for API Specific samples, there will be a unique sample for each AutoML type. See the below list for more info.

## Base Samples
### Dataset Management
* [Import Dataset](src/main/java/com/example/automl/ImportDataset.java)
* [List Datasets](src/main/java/com/example/automl/ListDatasets.java) - For each AutoML Type the `metadata` field inside the dataset is unique, therefore each AutoML Type will have a
small section of code to print out the `metadata` field.
* [Get Dataset](src/main/java/com/example/automl/GetDataset.java) - For each AutoML Type the `metadata` field inside the dataset is unique, therefore each AutoML Type will have a
small section of code to print out the `metadata` field.
* [Export Dataset](src/main/java/com/example/automl/ExportDataset.java)
* [Delete Dataset](src/main/java/com/example/automl/DeleteDataset.java)
### Model Management
* [List Models](src/main/java/com/example/automl/ListModels.java)
* [List Model Evaluation](src/main/java/com/example/automl/ListModelEvaluations.java)
* [Get Model](src/main/java/com/example/automl/)
* [Get Model Evaluation](src/main/java/com/example/automl/GetModelEvaluation.java)
* [Delete Model](src/main/java/com/example/automl/DeleteModel.java)

### Operation Management
* [List Operation Statuses](src/main/java/com/example/automl/ListOperationStatus.java)
* [Get Operation Status](src/main/java/com/example/automl/GetOperationStatus.java)

## AutoML Type Specific Samples
### Translation
* [Translate Create Dataset](src/main/java/com/example/automl/TranslateCreateDataset.java)
* [Translate Create Model](src/main/java/com/example/automl/TranslateCreateModel.java)
* [Translate Predict](src/main/java/com/example/automl/TranslatePredict.java)
68 changes: 68 additions & 0 deletions automl/cloud-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!--
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.automl</groupId>
<artifactId>automl-google-cloud-samples</artifactId>
<packaging>jar</packaging>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.0.11</version>
</parent>

<properties>
<maven.compiler.target>1.11</maven.compiler.target>
<maven.compiler.source>1.11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- [START automl_java_dependencies] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-automl</artifactId>
<version>0.114.0-beta</version>
</dependency>
<!-- [END automl_java_dependencies] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.83.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
<version>0.8.1</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.41</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions automl/cloud-client/resources/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tell me how this ends
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package com.google.cloud.translate.automl;
package com.example.automl;

// [START automl_translate_delete_dataset]
// [START automl_delete_dataset]
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.DatasetName;
import com.google.protobuf.Empty;
Expand All @@ -26,11 +26,16 @@

class DeleteDataset {

// Delete a dataset
static void deleteDataset(String projectId, String datasetId) {
// String projectId = "YOUR_PROJECT_ID";
// String datasetId = "YOUR_DATASET_ID";
static void deleteDataset() throws IOException, ExecutionException, InterruptedException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String datasetId = "YOUR_DATASET_ID";
deleteDataset(projectId, datasetId);
}

// Delete a dataset
static void deleteDataset(String projectId, String datasetId)
throws IOException, ExecutionException, InterruptedException {
// 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.
Expand All @@ -39,9 +44,7 @@ static void deleteDataset(String projectId, String datasetId) {
DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
Empty response = client.deleteDatasetAsync(datasetFullId).get();
System.out.format("Dataset deleted. %s\n", response);
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
// [END automl_translate_delete_dataset]
// [END automl_delete_dataset]
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package com.google.cloud.translate.automl;
package com.example.automl;

// [START automl_translate_delete_model]
// [START automl_delete_model]
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.ModelName;
import com.google.protobuf.Empty;
Expand All @@ -26,11 +26,16 @@

class DeleteModel {

// Get a model
static void deleteModel(String projectId, String modelId) {
// String projectId = "YOUR_PROJECT_ID";
// String modelId = "YOUR_MODEL_ID";
static void deleteModel() throws IOException, ExecutionException, InterruptedException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String modelId = "YOUR_MODEL_ID";
deleteModel(projectId, modelId);
}

// Get a model
static void deleteModel(String projectId, String modelId)
throws IOException, ExecutionException, InterruptedException {
// 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.
Expand All @@ -43,9 +48,7 @@ static void deleteModel(String projectId, String modelId) {

System.out.println("Model deletion started...");
System.out.println(String.format("Model deleted. %s", response));
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
// [END automl_translate_delete_model]
// [END automl_delete_model]
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package com.google.cloud.translate.automl;
package com.example.automl;

// [START automl_translate_export_dataset]
// [START automl_export_dataset]
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.DatasetName;
import com.google.cloud.automl.v1.GcsDestination;
Expand All @@ -28,12 +28,17 @@

class ExportDataset {

// Export a dataset
static void exportDataset(String projectId, String datasetId, String gcsUri) {
// String projectId = "YOUR_PROJECT_ID";
// String datasetId = "YOUR_DATASET_ID";
// String gcsUri = "gs://BUCKET_ID/path_to_export/";
static void exportDataset() throws IOException, ExecutionException, InterruptedException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String datasetId = "YOUR_DATASET_ID";
String gcsUri = "gs://BUCKET_ID/path_to_export/";
exportDataset(projectId, datasetId, gcsUri);
}

// Export a dataset
static void exportDataset(String projectId, String datasetId, String gcsUri)
throws IOException, ExecutionException, InterruptedException {
// 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.
Expand All @@ -50,9 +55,7 @@ static void exportDataset(String projectId, String datasetId, String gcsUri) {
System.out.println("Processing export...");
Empty response = client.exportDataAsync(datasetFullId, outputConfig).get();
System.out.format("Dataset exported. %s\n", response);
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
// [END automl_translate_export_dataset]
// [END automl_export_dataset]
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

package com.google.cloud.translate.automl;
package com.example.automl;

// [START automl_translate_get_dataset]

import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.Dataset;
import com.google.cloud.automl.v1.DatasetName;
Expand All @@ -25,11 +26,15 @@

class GetDataset {

// Get a dataset
static void getDataset(String projectId, String datasetId) {
// String projectId = "YOUR_PROJECT_ID";
// String datasetId = "YOUR_DATASET_ID";
static void getDataset() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String datasetId = "YOUR_DATASET_ID";
getDataset(projectId, datasetId);
}

// Get a dataset
static void getDataset(String projectId, String datasetId) throws IOException {
// 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.
Expand Down Expand Up @@ -57,8 +62,6 @@ static void getDataset(String projectId, String datasetId) {
System.out.println("Dataset create time:");
System.out.format("\tseconds: %s\n", dataset.getCreateTime().getSeconds());
System.out.format("\tnanos: %s\n", dataset.getCreateTime().getNanos());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package com.google.cloud.translate.automl;
package com.example.automl;

// [START automl_translate_get_model]
// [START automl_get_model]
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.ModelName;
Expand All @@ -25,11 +25,15 @@

class GetModel {

// Get a model
static void getModel(String projectId, String modelId) {
// String projectId = "YOUR_PROJECT_ID";
// String modelId = "YOUR_MODEL_ID";
static void getModel() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String modelId = "YOUR_MODEL_ID";
getModel(projectId, modelId);
}

// Get a model
static void getModel(String projectId, String modelId) throws IOException {
// 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.
Expand All @@ -51,9 +55,7 @@ static void getModel(String projectId, String modelId) {
System.out.format("\tseconds: %s\n", model.getCreateTime().getSeconds());
System.out.format("\tnanos: %s\n", model.getCreateTime().getNanos());
System.out.format("Model deployment state: %s\n", model.getDeploymentState());
} catch (IOException e) {
e.printStackTrace();
}
}
}
// [END automl_translate_get_model]
// [END automl_get_model]
Loading