Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d93085b

Browse filesBrowse files
authored
automl: move video object tracking samples out of branch (GoogleCloudPlatform#3043)
* automl: move video object tracking samples out of branch * fix uuid and create test * fix project * use global var for testing * Update video_object_tracking_create_model_test.py
1 parent fadb04c commit d93085b
Copy full SHA for d93085b
Expand file treeCollapse file tree

4 files changed

+178
-0
lines changed
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START automl_video_object_tracking_create_dataset_beta]
16+
from google.cloud import automl_v1beta1 as automl
17+
18+
19+
def create_dataset(
20+
project_id="YOUR_PROJECT_ID", display_name="your_datasets_display_name"
21+
):
22+
"""Create a automl video object tracking dataset."""
23+
client = automl.AutoMlClient()
24+
25+
# A resource that represents Google Cloud Platform location.
26+
project_location = client.location_path(project_id, "us-central1")
27+
metadata = automl.types.VideoObjectTrackingDatasetMetadata()
28+
dataset = automl.types.Dataset(
29+
display_name=display_name,
30+
video_object_tracking_dataset_metadata=metadata,
31+
)
32+
33+
# Create a dataset with the dataset metadata in the region.
34+
created_dataset = client.create_dataset(project_location, dataset)
35+
# Display the dataset information
36+
print("Dataset name: {}".format(created_dataset.name))
37+
print("Dataset id: {}".format(created_dataset.name.split("/")[-1]))
38+
# [END automl_video_object_tracking_create_dataset_beta]
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import uuid
17+
18+
from google.cloud import automl_v1beta1 as automl
19+
import pytest
20+
21+
import video_object_tracking_create_dataset
22+
23+
PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
24+
DATASET_ID = None
25+
26+
27+
@pytest.fixture(scope="function", autouse=True)
28+
def teardown():
29+
yield
30+
31+
# Delete the created dataset
32+
client = automl.AutoMlClient()
33+
dataset_full_id = client.dataset_path(
34+
PROJECT_ID, "us-central1", DATASET_ID
35+
)
36+
response = client.delete_dataset(dataset_full_id)
37+
response.result()
38+
39+
40+
def test_video_classification_create_dataset(capsys):
41+
# create dataset
42+
dataset_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
43+
video_object_tracking_create_dataset.create_dataset(
44+
PROJECT_ID, dataset_name
45+
)
46+
out, _ = capsys.readouterr()
47+
assert "Dataset id: " in out
48+
49+
# Get the dataset id for deletion
50+
global DATASET_ID
51+
DATASET_ID = out.splitlines()[1].split()[2]
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START automl_video_object_tracking_create_model_beta]
16+
from google.cloud import automl_v1beta1 as automl
17+
18+
19+
def create_model(
20+
project_id="YOUR_PROJECT_ID",
21+
dataset_id="YOUR_DATASET_ID",
22+
display_name="your_models_display_name",
23+
):
24+
"""Create a automl video classification model."""
25+
client = automl.AutoMlClient()
26+
27+
# A resource that represents Google Cloud Platform loacation.
28+
project_location = client.location_path(project_id, "us-central1")
29+
# Leave model unset to use the default base model provided by Google
30+
metadata = automl.types.VideoObjectTrackingModelMetadata()
31+
model = automl.types.Model(
32+
display_name=display_name,
33+
dataset_id=dataset_id,
34+
video_object_tracking_model_metadata=metadata,
35+
)
36+
37+
# Create a model with the model metadata in the region.
38+
response = client.create_model(project_location, model)
39+
40+
print("Training operation name: {}".format(response.operation.name))
41+
print("Training started...")
42+
# [END automl_video_object_tracking_create_model_beta]
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import uuid
17+
18+
from google.cloud import automl_v1beta1 as automl
19+
import pytest
20+
21+
import video_object_tracking_create_model
22+
23+
PROJECT_ID = os.environ["GCLOUD_PROJECT"]
24+
DATASET_ID = "VOT2823376535338090496"
25+
OPERATION_ID = None
26+
27+
28+
@pytest.fixture(scope="function", autouse=True)
29+
def teardown():
30+
yield
31+
32+
# Cancel the training operation
33+
client = automl.AutoMlClient()
34+
client.transport._operations_client.cancel_operation(OPERATION_ID)
35+
36+
37+
def test_video_classification_create_model(capsys):
38+
model_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
39+
video_object_tracking_create_model.create_model(
40+
PROJECT_ID, DATASET_ID, model_name
41+
)
42+
out, _ = capsys.readouterr()
43+
assert "Training started" in out
44+
45+
# Cancel the operation
46+
global OPERATION_ID
47+
OPERATION_ID = out.split("Training operation name: ")[1].split("\n")[0]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.