Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4c6103

Browse files
author
Rebecca Taylor
committed
Add AutoML Video Intelligence Object Tracking samples
1 parent 72f6763 commit a4c6103

20 files changed

+1827
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This sample is HAND-WRITTEN
18+
19+
# To install the latest published package dependency, execute the following:
20+
# pip install google-cloud-automl
21+
22+
# sample-metadata
23+
# title: Cancel Long-Running Operation
24+
# description: Cancel Long-Running Operation
25+
# usage: python3 samples/v1beta1/automl_cancel_operation.py [--project "[Google Cloud Project ID]"] [--operation_id "[Operation ID]"]
26+
import sys
27+
28+
# [START automl_cancel_operation]
29+
30+
from google.cloud import automl_v1beta1
31+
32+
33+
def sample_cancel_operation(project, operation_id):
34+
"""
35+
Cancel Long-Running Operation
36+
37+
Args:
38+
project Required. Your Google Cloud Project ID.
39+
operation_id Required. The ID of the Operation.
40+
"""
41+
42+
client = automl_v1beta1.AutoMlClient()
43+
44+
operations_client = client.transport._operations_client
45+
46+
# project = '[Google Cloud Project ID]'
47+
# operation_id = '[Operation ID]'
48+
name = "projects/{}/locations/us-central1/operations/{}".format(
49+
project, operation_id
50+
)
51+
52+
operations_client.cancel_operation(name)
53+
54+
print(u"Cancelled operation: {}".format(name))
55+
56+
57+
# [END automl_cancel_operation]
58+
59+
60+
def main():
61+
import argparse
62+
63+
parser = argparse.ArgumentParser()
64+
parser.add_argument("--project", type=str, default="[Google Cloud Project ID]")
65+
parser.add_argument("--operation_id", type=str, default="[Operation ID]")
66+
args = parser.parse_args()
67+
68+
sample_cancel_operation(args.project, args.operation_id)
69+
70+
71+
if __name__ == "__main__":
72+
main()
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This sample is HAND-WRITTEN
18+
19+
# To install the latest published package dependency, execute the following:
20+
# pip install google-cloud-automl
21+
22+
# sample-metadata
23+
# title: Get Long-Running Operation Status
24+
# description: Get Long-Running Operation Status
25+
# usage: python3 samples/v1beta1/automl_get_operation.py [--project "[Google Cloud Project ID]"] [--operation_id "[Operation ID]"]
26+
import sys
27+
28+
# [START automl_get_operation]
29+
30+
from google.cloud import automl_v1beta1
31+
32+
33+
def sample_get_operation(project, operation_id):
34+
"""
35+
Get Long-Running Operation Status
36+
37+
Args:
38+
project Required. Your Google Cloud Project ID.
39+
operation_id Required. The ID of the Operation.
40+
"""
41+
42+
client = automl_v1beta1.AutoMlClient()
43+
44+
operations_client = client.transport._operations_client
45+
46+
# project = '[Google Cloud Project ID]'
47+
# operation_id = '[Operation ID]'
48+
name = "projects/{}/locations/us-central1/operations/{}".format(
49+
project, operation_id
50+
)
51+
52+
operation = operations_client.get_operation(name)
53+
54+
# Print Operation status and info
55+
print(u"Operation Name: {}".format(operation.name))
56+
print(u"Done: {}".format(operation.done))
57+
print(u"Response: {}".format(operation.response))
58+
print(u"Metadata: {}".format(operation.metadata))
59+
60+
61+
# [END automl_get_operation]
62+
63+
64+
def main():
65+
import argparse
66+
67+
parser = argparse.ArgumentParser()
68+
parser.add_argument("--project", type=str, default="[Google Cloud Project ID]")
69+
parser.add_argument("--operation_id", type=str, default="[Operation ID]")
70+
args = parser.parse_args()
71+
72+
sample_get_operation(args.project, args.operation_id)
73+
74+
75+
if __name__ == "__main__":
76+
main()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This sample is HAND-WRITTEN
18+
19+
# To install the latest published package dependency, execute the following:
20+
# pip install google-cloud-automl
21+
22+
# sample-metadata
23+
# title: List Long-Running Operations
24+
# description: List Long-Running Operations
25+
# usage: python3 samples/v1beta1/automl_list_operations.py [--project "[Google Cloud Project ID]"] [--filter ""]
26+
import sys
27+
28+
# [START automl_list_operations]
29+
30+
from google.cloud import automl_v1beta1
31+
32+
33+
def sample_list_operations(project, filter_):
34+
"""
35+
List Long-Running Operations
36+
37+
Args:
38+
project Required. Your Google Cloud Project ID.
39+
filter_ Filter operations
40+
"""
41+
42+
client = automl_v1beta1.AutoMlClient()
43+
44+
operations_client = client.transport._operations_client
45+
46+
# project = '[Google Cloud Project ID]'
47+
name = client.location_path(project, "us-central1")
48+
49+
# Iterate over all results
50+
for response_item in operations_client.list_operations(name, filter_=filter_):
51+
operation = response_item
52+
print(u"Operation Name: {}".format(operation.name))
53+
print(u"Done: {}".format(operation.done))
54+
print(u"Response: {}".format(operation.response))
55+
print(u"Metadata: {}".format(operation.metadata))
56+
57+
58+
# [END automl_list_operations]
59+
60+
61+
def main():
62+
import argparse
63+
64+
parser = argparse.ArgumentParser()
65+
parser.add_argument("--project", type=str, default="[Google Cloud Project ID]")
66+
parser.add_argument("--filter", type=str, default="")
67+
args = parser.parse_args()
68+
69+
sample_list_operations(args.project, args.filter)
70+
71+
72+
if __name__ == "__main__":
73+
main()
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# DO NOT EDIT! This is a generated sample ("LongRunningPromise", "automl_video_object_tracking_batch_predict")
18+
19+
# To install the latest published package dependency, execute the following:
20+
# pip install google-cloud-automl
21+
22+
# sample-metadata
23+
# title: AutoML Batch Predict
24+
# description: AutoML Batch Predict
25+
# usage: python3 samples/v1beta1/automl_video_object_tracking_batch_predict.py [--gcs_output_prefix "[gs://your-output-bucket/your-object-id]"] [--model_id "[Model ID]"] [--project "[Google Cloud Project ID]"]
26+
import sys
27+
28+
# [START automl_video_object_tracking_batch_predict]
29+
30+
from google.cloud import automl_v1beta1
31+
32+
33+
def sample_batch_predict(gcs_output_prefix, model_id, project):
34+
"""
35+
AutoML Batch Predict
36+
37+
Args:
38+
gcs_output_prefix Identifies where to store the output of your prediction
39+
request
40+
in your Google Cloud Storage bucket.
41+
You must have write permissions to the Google Cloud Storage bucket.
42+
project Required. Your Google Cloud Project ID.
43+
"""
44+
45+
client = automl_v1beta1.PredictionServiceClient()
46+
47+
# gcs_output_prefix = '[gs://your-output-bucket/your-object-id]'
48+
# model_id = '[Model ID]'
49+
# project = '[Google Cloud Project ID]'
50+
name = client.model_path(project, "us-central1", model_id)
51+
input_uris_element = (
52+
"gs://automl-video-datasets/youtube_8m_videos_animal_batchpredict.csv"
53+
)
54+
input_uris = [input_uris_element]
55+
gcs_source = {"input_uris": input_uris}
56+
input_config = {"gcs_source": gcs_source}
57+
gcs_destination = {"output_uri_prefix": gcs_output_prefix}
58+
output_config = {"gcs_destination": gcs_destination}
59+
60+
operation = client.batch_predict(name, input_config, output_config)
61+
62+
print(u"Waiting for operation to complete...")
63+
response = operation.result()
64+
65+
print(u"Batch Prediction results saved to Cloud Storage")
66+
67+
68+
# [END automl_video_object_tracking_batch_predict]
69+
70+
71+
def main():
72+
import argparse
73+
74+
parser = argparse.ArgumentParser()
75+
parser.add_argument(
76+
"--gcs_output_prefix",
77+
type=str,
78+
default="[gs://your-output-bucket/your-object-id]",
79+
)
80+
parser.add_argument("--model_id", type=str, default="[Model ID]")
81+
parser.add_argument("--project", type=str, default="[Google Cloud Project ID]")
82+
args = parser.parse_args()
83+
84+
sample_batch_predict(args.gcs_output_prefix, args.model_id, args.project)
85+
86+
87+
if __name__ == "__main__":
88+
main()

0 commit comments

Comments
 (0)