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 - minor bug fixes #1168

Merged
merged 19 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from 18 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
9 changes: 6 additions & 3 deletions language/automl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
<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>

[Google Cloud Natural Language API][language] provides feature detection for images.

[Google Cloud AutoML Natural Language API][language] provides feature detection for images.

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

This sample Java application demonstrates how to access the Cloud Natural Language AutoML API
using the [Google Cloud Client Library for Java][google-cloud-java].

[language]: https://cloud.google.com/language/docs/

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

## Set the environment variables
Expand Down Expand Up @@ -46,7 +49,7 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.language.samples.DatasetApi" -D

#### Import data
```
mvn exec:java -Dexec.mainClass="com.google.cloud.language.samples.DatasetApi" -Dexec.args="import_data gs://java-docs-samples-testing/happiness.csv"
mvn exec:java -Dexec.mainClass="com.google.cloud.language.samples.DatasetApi" -Dexec.args="import_data [dataset-id] gs://java-docs-samples-testing/happiness.csv"
```

### Model API
Expand Down
2 changes: 1 addition & 1 deletion language/automl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.vision</groupId>
<groupId>com.google.cloud.language.samples</groupId>
<artifactId>language-automl</artifactId>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ public static void listModels(String projectId, String computeRegion, String fil
LocationName projectLocation = LocationName.of(projectId, computeRegion);

// Create list models request.
ListModelsRequest listModlesRequest =
ListModelsRequest listModelsRequest =
ListModelsRequest.newBuilder()
.setParent(projectLocation.toString())
.setFilter(filter)
.build();

System.out.println("List of models:");
for (Model model : client.listModels(listModlesRequest).iterateAll()) {
for (Model model : client.listModels(listModelsRequest).iterateAll()) {
// Display the model information.
System.out.println(String.format("Model name: %s", model.getName()));
System.out.println(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class DatasetApiIT {

private static final String PROJECT_ID = "java-docs-samples-testing";
private static final String BUCKET = PROJECT_ID + "-vcm";
private static final String BUCKET = PROJECT_ID + "-lcm";
private static final String COMPUTE_REGION = "us-central1";
private static final String DATASET_NAME = "test_language_dataset";
private ByteArrayOutputStream bout;
Expand Down
10 changes: 8 additions & 2 deletions translate/automl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
<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>

[Google Cloud Translate API][translate] provides feature AutoML.

[Google Cloud AutoML Translation API][translate] provides feature AutoML.

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

This sample Java application demonstrates how to access the Cloud Translate AutoML API
using the [Google Cloud Client Library for Java][google-cloud-java].


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

## Set the environment variables

PROJECT_ID = [Id of the project]
Expand Down Expand Up @@ -43,7 +49,7 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.translate.samples.DatasetApi" -

#### Import data
```
mvn exec:java -Dexec.mainClass="com.google.cloud.translate.samples.DatasetApi" -Dexec.args="import_data gs://java-docs-samples-testing/en-ja.csv"
mvn exec:java -Dexec.mainClass="com.google.cloud.translate.samples.DatasetApi" -Dexec.args="import_data [dataset-id] gs://java-docs-samples-testing/en-ja.csv"
```

### Model API
Expand Down
2 changes: 1 addition & 1 deletion translate/automl/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2016 Google Inc.
Copyright 2018 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
public class DatasetApi {

// [START automl_translate_create_dataset]
// [START automl_translation_create_dataset]
/**
* Demonstrates using the AutoML client to create a dataset
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

/**
* Google Cloud AutoML Translate API sample application. Example usage: mvn package exec:java
* -Dexec.mainClass ='com.google.cloud.vision.samples.automl.PredictionApi' -Dexec.args='predict
* [modelId] [path-to-image] [scoreThreshold]'
* -Dexec.mainClass ='com.google.cloud.translate.automl.PredictionApi' -Dexec.args='predict
* [modelId] [file-path]'
*/
public class PredictionApi {

Expand All @@ -61,16 +61,11 @@ public class PredictionApi {
* @param computeRegion the Region name.
* @param modelId the Id of the model which will be used for text classification.
* @param filePath the Local text file path of the content to be classified.
* @param translationAllowFallback set to true to use a Google translation.
* @throws IOException on Input/Output errors.
*/
public static void predict(
String projectId,
String computeRegion,
String modelId,
String filePath,
boolean translationAllowFallback)
throws IOException {
String projectId, String computeRegion, String modelId, String filePath) throws IOException {

// Instantiate client for prediction service.
PredictionServiceClient predictionClient = PredictionServiceClient.create();

Expand All @@ -87,9 +82,6 @@ public static void predict(

// Additional parameters that can be provided for prediction
Map<String, String> params = new HashMap<>();
if (translationAllowFallback) {
params.put("translation_allow_fallback", "True");//Allow Google Translation Model
}

PredictResponse response = predictionClient.predict(name, payload, params);
TextSnippet translatedContent = response.getPayload(0).getTranslation().getTranslatedContent();
Expand All @@ -104,20 +96,17 @@ public static void main(String[] args) throws IOException {
}

public static void argsHelper(String[] args, PrintStream out) throws IOException {
ArgumentParser parser = ArgumentParsers.newFor("PredictionApi")
.build()
.defaultHelp(true)
.description("Prediction API Operation");
ArgumentParser parser =
ArgumentParsers.newFor("PredictionApi")
.build()
.defaultHelp(true)
.description("Prediction API Operation");

Subparsers subparsers = parser.addSubparsers().dest("command");

Subparser predictParser = subparsers.addParser("predict");
predictParser.addArgument("modelId");
predictParser.addArgument("filePath");
predictParser
.addArgument("translationAllowFallback")
.nargs("?")
.type(Boolean.class)
.setDefault(Boolean.FALSE);

String projectId = System.getenv("PROJECT_ID");
String computeRegion = System.getenv("REGION_NAME");
Expand All @@ -126,12 +115,8 @@ public static void argsHelper(String[] args, PrintStream out) throws IOException
try {
ns = parser.parseArgs(args);
if (ns.get("command").equals("predict")) {
predict(
projectId,
computeRegion,
ns.getString("modelId"),
ns.getString("filePath"),
ns.getBoolean("translationAllowFallback"));
predict(projectId, computeRegion, ns.getString("modelId"), ns.getString("filePath"));

}
} catch (ArgumentParserException e) {
parser.handleError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.cloud.translate.automl;

import static com.google.common.truth.Truth.assertThat;
import static java.lang.Boolean.FALSE;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
Expand Down Expand Up @@ -55,7 +54,7 @@ public void tearDown() {
@Test
public void testPredict() throws Exception {
// Act
PredictionApi.predict(PROJECT_ID, COMPUTE_REGION, modelId, filePath,FALSE);
PredictionApi.predict(PROJECT_ID, COMPUTE_REGION, modelId, filePath);

// Assert
String got = bout.toString();
Expand Down
12 changes: 7 additions & 5 deletions vision/automl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
<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>

[Google Cloud Vision API][vision] provides feature detection for images.
[Google Cloud AutoML Vision API][vision] provides feature detection for images.

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

This sample Java application demonstrates how to access the Cloud Vision API
using the [Google Cloud Client Library for Java][google-cloud-java].

[vision]: https://cloud.google.com/vision/docs/

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

## Set the environment variables
Expand Down Expand Up @@ -45,14 +47,14 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.DatasetAp

#### Import data
```
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.DatasetApi" -Dexec.args="import_data gs://java-docs-samples-testing/flower_traindata.csv"
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.DatasetApi" -Dexec.args="import_data [dataset-id] gs://java-docs-samples-testing/flower_traindata.csv"
```

### Model API

#### Create Model
```
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi" -Dexec.args="create_model test_model"
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi" -Dexec.args="create_model [dataset-id] test_model [training-budget] "
```

#### List Models
Expand All @@ -77,7 +79,7 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi"

#### Delete Model
```
mvn exec:java-Dexec.mainClass="com.google.cloud.vision.samples.automl.ModeltApi" -Dexec.args="delete_model [model-id]"
mvn exec:java-Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi" -Dexec.args="delete_model [model-id]"
```
### Predict API

Expand Down
2 changes: 1 addition & 1 deletion vision/automl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.vision</groupId>
<groupId>com.example.vision.samples.automl</groupId>
<artifactId>vision-automl</artifactId>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void predict(
// Additional parameters that can be provided for prediction e.g. Score Threshold
Map<String, String> params = new HashMap<>();
if (scoreThreshold != null) {
params.put("scoreThreshold", scoreThreshold);
params.put("score_threshold", scoreThreshold);
}
// Perform the AutoML Prediction request
PredictResponse response = predictionClient.predict(name, examplePayload, params);
Expand Down