Skip to content

Commit d9175da

Browse files
author
Rebecca Taylor
committed
Add AutoML Video Object Tracking samples (wip)
1 parent ae5cb5e commit d9175da

32 files changed

+4057
-0
lines changed

automl/beta/pom.xml

Lines changed: 956 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// DO NOT EDIT! This is a generated sample ("Request", "automl_natural_language_create_dataset")
17+
// sample-metadata:
18+
// title: Create Dataset
19+
// description: Create Dataset
20+
// usage: gradle run -PmainClass=com.google.cloud.examples.automl.v1beta1.AutomlNaturalLanguageCreateDataset [--args='[--display_name "My_Dataset_Name_123"] [--project "[Google Cloud Project ID]"]']
21+
22+
package com.google.cloud.examples.automl.v1beta1;
23+
24+
import com.google.cloud.automl.v1beta1.AutoMlClient;
25+
import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationType;
26+
import com.google.cloud.automl.v1beta1.CreateDatasetRequest;
27+
import com.google.cloud.automl.v1beta1.Dataset;
28+
import com.google.cloud.automl.v1beta1.LocationName;
29+
import com.google.cloud.automl.v1beta1.TextClassificationDatasetMetadata;
30+
import org.apache.commons.cli.CommandLine;
31+
import org.apache.commons.cli.DefaultParser;
32+
import org.apache.commons.cli.Option;
33+
import org.apache.commons.cli.Options;
34+
35+
public class AutomlNaturalLanguageCreateDataset {
36+
// [START automl_natural_language_create_dataset]
37+
/*
38+
* Please include the following imports to run this sample.
39+
*
40+
* import com.google.cloud.automl.v1beta1.AutoMlClient;
41+
* import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationType;
42+
* import com.google.cloud.automl.v1beta1.CreateDatasetRequest;
43+
* import com.google.cloud.automl.v1beta1.Dataset;
44+
* import com.google.cloud.automl.v1beta1.LocationName;
45+
* import com.google.cloud.automl.v1beta1.TextClassificationDatasetMetadata;
46+
*/
47+
48+
/**
49+
* Create Dataset
50+
*
51+
* @param displayName The name of the dataset to show in the interface. The name can be up to 32
52+
* characters long and can consist only of ASCII Latin letters A-Z and a-z, underscores (_),
53+
* and ASCII digits 0-9. Must be unique within the scope of the provided GCP Project and
54+
* Location.
55+
* @param project Required. Your Google Cloud Project ID.
56+
*/
57+
public static void sampleCreateDataset(String displayName, String project) {
58+
try (AutoMlClient autoMlClient = AutoMlClient.create()) {
59+
// displayName = "My_Dataset_Name_123";
60+
// project = "[Google Cloud Project ID]";
61+
LocationName parent = LocationName.of(project, "us-central1");
62+
63+
// User-provided description of dataset (optional)
64+
String description = "Description of this dataset";
65+
66+
// Type of the classification problem.
67+
// MULTICLASS: At most one label is allowed per example.
68+
// MULTILABEL: Multiple labels are allowed for one example.
69+
ClassificationType classificationType = ClassificationType.MULTILABEL;
70+
TextClassificationDatasetMetadata textClassificationDatasetMetadata =
71+
TextClassificationDatasetMetadata.newBuilder()
72+
.setClassificationType(classificationType)
73+
.build();
74+
Dataset dataset =
75+
Dataset.newBuilder()
76+
.setDisplayName(displayName)
77+
.setDescription(description)
78+
.setTextClassificationDatasetMetadata(textClassificationDatasetMetadata)
79+
.build();
80+
CreateDatasetRequest request =
81+
CreateDatasetRequest.newBuilder()
82+
.setParent(parent.toString())
83+
.setDataset(dataset)
84+
.build();
85+
Dataset response = autoMlClient.createDataset(request);
86+
System.out.println("Created Dataset.");
87+
Dataset dataset = response;
88+
// Print out the full name of the created dataset.
89+
//
90+
// This will have the format:
91+
// projects/[Google Cloud Project Number]/locations/us-central1/datasets/VOT1234567890123456789
92+
//
93+
// The Dataset ID is the generated identifer in this path, e.g. VOT1234567890123456789
94+
// You will need this ID to perform operations on the dataset as well as to create a model.
95+
//
96+
System.out.printf("Name: %s\n", dataset.getName());
97+
// Print out the Display Name (the text you provided during creation)
98+
System.out.printf("Display Name: %s\n", dataset.getDisplayName());
99+
// Print out the user-provided description (may be blank)
100+
System.out.printf("Description: %s\n", dataset.getDescription());
101+
// The number of examples in the dataset, if any.
102+
// Added by importing data via importData
103+
//
104+
System.out.printf("Example count: %s\n", dataset.getExampleCount());
105+
// Get the classification type
106+
System.out.printf(
107+
"Text Classification Type: %s\n",
108+
dataset.getTextClassificationDatasetMetadata().getClassificationType());
109+
} catch (Exception exception) {
110+
System.err.println("Failed to create the client due to: " + exception);
111+
}
112+
}
113+
// [END automl_natural_language_create_dataset]
114+
115+
public static void main(String[] args) throws Exception {
116+
Options options = new Options();
117+
options.addOption(
118+
Option.builder("").required(false).hasArg(true).longOpt("display_name").build());
119+
options.addOption(Option.builder("").required(false).hasArg(true).longOpt("project").build());
120+
121+
CommandLine cl = (new DefaultParser()).parse(options, args);
122+
String displayName = cl.getOptionValue("display_name", "My_Dataset_Name_123");
123+
String project = cl.getOptionValue("project", "[Google Cloud Project ID]");
124+
125+
sampleCreateDataset(displayName, project);
126+
}
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// DO NOT EDIT! This is a generated sample ("LongRunningRequestAsync", "automl_natural_language_delete_dataset")
17+
// sample-metadata:
18+
// title: Delete Dataset
19+
// description: Delete Dataset
20+
// usage: gradle run -PmainClass=com.google.cloud.examples.automl.v1beta1.AutomlNaturalLanguageDeleteDataset [--args='[--dataset_id "[Dataset ID]"] [--project "[Google Cloud Project ID]"]']
21+
22+
package com.google.cloud.examples.automl.v1beta1;
23+
24+
import com.google.cloud.automl.v1beta1.AutoMlClient;
25+
import com.google.cloud.automl.v1beta1.DatasetName;
26+
import com.google.cloud.automl.v1beta1.DeleteDatasetRequest;
27+
import org.apache.commons.cli.CommandLine;
28+
import org.apache.commons.cli.DefaultParser;
29+
import org.apache.commons.cli.Option;
30+
import org.apache.commons.cli.Options;
31+
32+
public class AutomlNaturalLanguageDeleteDataset {
33+
// [START automl_natural_language_delete_dataset]
34+
/*
35+
* Please include the following imports to run this sample.
36+
*
37+
* import com.google.cloud.automl.v1beta1.AutoMlClient;
38+
* import com.google.cloud.automl.v1beta1.DatasetName;
39+
* import com.google.cloud.automl.v1beta1.DeleteDatasetRequest;
40+
* import com.google.protobuf.Empty;
41+
*/
42+
43+
/**
44+
* Delete Dataset
45+
*
46+
* @param datasetId Dataset ID, e.g. VOT1234567890123456789
47+
* @param project Required. Your Google Cloud Project ID.
48+
*/
49+
public static void sampleDeleteDataset(String datasetId, String project) {
50+
try (AutoMlClient autoMlClient = AutoMlClient.create()) {
51+
// datasetId = "[Dataset ID]";
52+
// project = "[Google Cloud Project ID]";
53+
DatasetName name = DatasetName.of(project, "us-central1", datasetId);
54+
DeleteDatasetRequest request =
55+
DeleteDatasetRequest.newBuilder().setName(name.toString()).build();
56+
autoMlClient.deleteDatasetAsync(request).get();
57+
System.out.println("Deleted Dataset.");
58+
} catch (Exception exception) {
59+
System.err.println("Failed to create the client due to: " + exception);
60+
}
61+
}
62+
// [END automl_natural_language_delete_dataset]
63+
64+
public static void main(String[] args) throws Exception {
65+
Options options = new Options();
66+
options.addOption(
67+
Option.builder("").required(false).hasArg(true).longOpt("dataset_id").build());
68+
options.addOption(Option.builder("").required(false).hasArg(true).longOpt("project").build());
69+
70+
CommandLine cl = (new DefaultParser()).parse(options, args);
71+
String datasetId = cl.getOptionValue("dataset_id", "[Dataset ID]");
72+
String project = cl.getOptionValue("project", "[Google Cloud Project ID]");
73+
74+
sampleDeleteDataset(datasetId, project);
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// DO NOT EDIT! This is a generated sample ("Request", "automl_natural_language_entity_create_dataset")
17+
// sample-metadata:
18+
// title: Create Dataset
19+
// description: Create Dataset
20+
// usage: gradle run -PmainClass=com.google.cloud.examples.automl.v1beta1.AutomlNaturalLanguageEntityCreateDataset [--args='[--display_name "My_Dataset_Name_123"] [--project "[Google Cloud Project ID]"]']
21+
22+
package com.google.cloud.examples.automl.v1beta1;
23+
24+
import com.google.cloud.automl.v1beta1.AutoMlClient;
25+
import com.google.cloud.automl.v1beta1.CreateDatasetRequest;
26+
import com.google.cloud.automl.v1beta1.Dataset;
27+
import com.google.cloud.automl.v1beta1.LocationName;
28+
import com.google.cloud.automl.v1beta1.TextExtractionDatasetMetadata;
29+
import org.apache.commons.cli.CommandLine;
30+
import org.apache.commons.cli.DefaultParser;
31+
import org.apache.commons.cli.Option;
32+
import org.apache.commons.cli.Options;
33+
34+
public class AutomlNaturalLanguageEntityCreateDataset {
35+
// [START automl_natural_language_entity_create_dataset]
36+
/*
37+
* Please include the following imports to run this sample.
38+
*
39+
* import com.google.cloud.automl.v1beta1.AutoMlClient;
40+
* import com.google.cloud.automl.v1beta1.CreateDatasetRequest;
41+
* import com.google.cloud.automl.v1beta1.Dataset;
42+
* import com.google.cloud.automl.v1beta1.LocationName;
43+
* import com.google.cloud.automl.v1beta1.TextExtractionDatasetMetadata;
44+
*/
45+
46+
/**
47+
* Create Dataset
48+
*
49+
* @param displayName The name of the dataset to show in the interface. The name can be up to 32
50+
* characters long and can consist only of ASCII Latin letters A-Z and a-z, underscores (_),
51+
* and ASCII digits 0-9. Must be unique within the scope of the provided GCP Project and
52+
* Location.
53+
* @param project Required. Your Google Cloud Project ID.
54+
*/
55+
public static void sampleCreateDataset(String displayName, String project) {
56+
try (AutoMlClient autoMlClient = AutoMlClient.create()) {
57+
// displayName = "My_Dataset_Name_123";
58+
// project = "[Google Cloud Project ID]";
59+
LocationName parent = LocationName.of(project, "us-central1");
60+
61+
// User-provided description of dataset (optional)
62+
String description = "Description of this dataset";
63+
64+
// Initialized text_extraction_dataset_metadata field must be provided.
65+
// This specifies this Dataset is to be used for text extraction.
66+
TextExtractionDatasetMetadata textExtractionDatasetMetadata =
67+
TextExtractionDatasetMetadata.newBuilder().build();
68+
Dataset dataset =
69+
Dataset.newBuilder()
70+
.setDisplayName(displayName)
71+
.setDescription(description)
72+
.setTextExtractionDatasetMetadata(textExtractionDatasetMetadata)
73+
.build();
74+
CreateDatasetRequest request =
75+
CreateDatasetRequest.newBuilder()
76+
.setParent(parent.toString())
77+
.setDataset(dataset)
78+
.build();
79+
Dataset response = autoMlClient.createDataset(request);
80+
System.out.println("Created Dataset.");
81+
Dataset dataset = response;
82+
// Print out the full name of the created dataset.
83+
//
84+
// This will have the format:
85+
// projects/[Google Cloud Project Number]/locations/us-central1/datasets/VOT1234567890123456789
86+
//
87+
// The Dataset ID is the generated identifer in this path, e.g. VOT1234567890123456789
88+
// You will need this ID to perform operations on the dataset as well as to create a model.
89+
//
90+
System.out.printf("Name: %s\n", dataset.getName());
91+
// Print out the Display Name (the text you provided during creation)
92+
System.out.printf("Display Name: %s\n", dataset.getDisplayName());
93+
// Print out the user-provided description (may be blank)
94+
System.out.printf("Description: %s\n", dataset.getDescription());
95+
// The number of examples in the dataset, if any.
96+
// Added by importing data via importData
97+
//
98+
System.out.printf("Example count: %s\n", dataset.getExampleCount());
99+
} catch (Exception exception) {
100+
System.err.println("Failed to create the client due to: " + exception);
101+
}
102+
}
103+
// [END automl_natural_language_entity_create_dataset]
104+
105+
public static void main(String[] args) throws Exception {
106+
Options options = new Options();
107+
options.addOption(
108+
Option.builder("").required(false).hasArg(true).longOpt("display_name").build());
109+
options.addOption(Option.builder("").required(false).hasArg(true).longOpt("project").build());
110+
111+
CommandLine cl = (new DefaultParser()).parse(options, args);
112+
String displayName = cl.getOptionValue("display_name", "My_Dataset_Name_123");
113+
String project = cl.getOptionValue("project", "[Google Cloud Project ID]");
114+
115+
sampleCreateDataset(displayName, project);
116+
}
117+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// DO NOT EDIT! This is a generated sample ("LongRunningRequestAsync", "automl_natural_language_entity_delete_dataset")
17+
// sample-metadata:
18+
// title: Delete Dataset
19+
// description: Delete Dataset
20+
// usage: gradle run -PmainClass=com.google.cloud.examples.automl.v1beta1.AutomlNaturalLanguageEntityDeleteDataset [--args='[--dataset_id "[Dataset ID]"] [--project "[Google Cloud Project ID]"]']
21+
22+
package com.google.cloud.examples.automl.v1beta1;
23+
24+
import com.google.cloud.automl.v1beta1.AutoMlClient;
25+
import com.google.cloud.automl.v1beta1.DatasetName;
26+
import com.google.cloud.automl.v1beta1.DeleteDatasetRequest;
27+
import org.apache.commons.cli.CommandLine;
28+
import org.apache.commons.cli.DefaultParser;
29+
import org.apache.commons.cli.Option;
30+
import org.apache.commons.cli.Options;
31+
32+
public class AutomlNaturalLanguageEntityDeleteDataset {
33+
// [START automl_natural_language_entity_delete_dataset]
34+
/*
35+
* Please include the following imports to run this sample.
36+
*
37+
* import com.google.cloud.automl.v1beta1.AutoMlClient;
38+
* import com.google.cloud.automl.v1beta1.DatasetName;
39+
* import com.google.cloud.automl.v1beta1.DeleteDatasetRequest;
40+
* import com.google.protobuf.Empty;
41+
*/
42+
43+
/**
44+
* Delete Dataset
45+
*
46+
* @param datasetId Dataset ID, e.g. VOT1234567890123456789
47+
* @param project Required. Your Google Cloud Project ID.
48+
*/
49+
public static void sampleDeleteDataset(String datasetId, String project) {
50+
try (AutoMlClient autoMlClient = AutoMlClient.create()) {
51+
// datasetId = "[Dataset ID]";
52+
// project = "[Google Cloud Project ID]";
53+
DatasetName name = DatasetName.of(project, "us-central1", datasetId);
54+
DeleteDatasetRequest request =
55+
DeleteDatasetRequest.newBuilder().setName(name.toString()).build();
56+
autoMlClient.deleteDatasetAsync(request).get();
57+
System.out.println("Deleted Dataset.");
58+
} catch (Exception exception) {
59+
System.err.println("Failed to create the client due to: " + exception);
60+
}
61+
}
62+
// [END automl_natural_language_entity_delete_dataset]
63+
64+
public static void main(String[] args) throws Exception {
65+
Options options = new Options();
66+
options.addOption(
67+
Option.builder("").required(false).hasArg(true).longOpt("dataset_id").build());
68+
options.addOption(Option.builder("").required(false).hasArg(true).longOpt("project").build());
69+
70+
CommandLine cl = (new DefaultParser()).parse(options, args);
71+
String datasetId = cl.getOptionValue("dataset_id", "[Dataset ID]");
72+
String project = cl.getOptionValue("project", "[Google Cloud Project ID]");
73+
74+
sampleDeleteDataset(datasetId, project);
75+
}
76+
}

0 commit comments

Comments
 (0)