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 027f0e5

Browse filesBrowse files
nnegreyleahecole
andauthored
automl: video beta move model samples from branch to master (GoogleCloudPlatform#2754)
* automl: video beta move model samples from branch to master * Fix region tag Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
1 parent 18105bc commit 027f0e5
Copy full SHA for 027f0e5

File tree

Expand file treeCollapse file tree

8 files changed

+297
-0
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+297
-0
lines changed

‎automl/beta/delete_model.py

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
16+
def delete_model(project_id, model_id):
17+
"""Delete a model."""
18+
# [START automl_delete_model_beta]
19+
from google.cloud import automl_v1beta1 as automl
20+
21+
# TODO(developer): Uncomment and set the following variables
22+
# project_id = "YOUR_PROJECT_ID"
23+
# model_id = "YOUR_MODEL_ID"
24+
25+
client = automl.AutoMlClient()
26+
# Get the full path of the model.
27+
model_full_id = client.model_path(project_id, "us-central1", model_id)
28+
response = client.delete_model(model_full_id)
29+
30+
print("Model deleted. {}".format(response.result()))
31+
# [END automl_delete_model_beta]

‎automl/beta/delete_model_test.py

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
17+
import delete_model
18+
19+
PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
20+
21+
22+
def test_delete_model(capsys):
23+
# As model creation can take many hours, instead try to delete a
24+
# nonexistent model and confirm that the model was not found, but other
25+
# elements of the request were valid.
26+
try:
27+
delete_model.delete_model(PROJECT_ID, "TRL0000000000000000000")
28+
out, _ = capsys.readouterr()
29+
assert "The model does not exist" in out
30+
except Exception as e:
31+
assert "The model does not exist" in e.message

‎automl/beta/get_model.py

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
16+
def get_model(project_id, model_id):
17+
"""Get a model."""
18+
# [START automl_get_model_beta]
19+
from google.cloud import automl_v1beta1 as automl
20+
21+
# TODO(developer): Uncomment and set the following variables
22+
# project_id = "YOUR_PROJECT_ID"
23+
# model_id = "YOUR_MODEL_ID"
24+
25+
client = automl.AutoMlClient()
26+
# Get the full path of the model.
27+
model_full_id = client.model_path(project_id, "us-central1", model_id)
28+
model = client.get_model(model_full_id)
29+
30+
# Retrieve deployment state.
31+
if model.deployment_state == automl.enums.Model.DeploymentState.DEPLOYED:
32+
deployment_state = "deployed"
33+
else:
34+
deployment_state = "undeployed"
35+
36+
# Display the model information.
37+
print("Model name: {}".format(model.name))
38+
print("Model id: {}".format(model.name.split("/")[-1]))
39+
print("Model display name: {}".format(model.display_name))
40+
print("Model create time:")
41+
print("\tseconds: {}".format(model.create_time.seconds))
42+
print("\tnanos: {}".format(model.create_time.nanos))
43+
print("Model deployment state: {}".format(deployment_state))
44+
# [END automl_get_model_beta]

‎automl/beta/get_model_evaluation.py

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
16+
def get_model_evaluation(project_id, model_id, model_evaluation_id):
17+
"""Get model evaluation."""
18+
# [START automl_video_classification_get_model_evaluation_beta]
19+
from google.cloud import automl_v1beta1 as automl
20+
21+
# TODO(developer): Uncomment and set the following variables
22+
# project_id = "YOUR_PROJECT_ID"
23+
# model_id = "YOUR_MODEL_ID"
24+
# model_evaluation_id = "YOUR_MODEL_EVALUATION_ID"
25+
26+
client = automl.AutoMlClient()
27+
# Get the full path of the model evaluation.
28+
model_evaluation_full_id = client.model_evaluation_path(
29+
project_id, "us-central1", model_id, model_evaluation_id
30+
)
31+
32+
# Get complete detail of the model evaluation.
33+
response = client.get_model_evaluation(model_evaluation_full_id)
34+
35+
print("Model evaluation name: {}".format(response.name))
36+
print("Model annotation spec id: {}".format(response.annotation_spec_id))
37+
print("Create Time:")
38+
print("\tseconds: {}".format(response.create_time.seconds))
39+
print("\tnanos: {}".format(response.create_time.nanos / 1e9))
40+
print(
41+
"Evaluation example count: {}".format(response.evaluated_example_count)
42+
)
43+
44+
print(
45+
"Classification model evaluation metrics: {}".format(
46+
response.classification_evaluation_metrics
47+
)
48+
)
49+
# [END automl_video_classification_get_model_evaluation_beta]
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
17+
from google.cloud import automl_v1beta1 as automl
18+
import pytest
19+
20+
import get_model_evaluation
21+
22+
PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
23+
MODEL_ID = os.environ["ENTITY_EXTRACTION_MODEL_ID"]
24+
25+
26+
@pytest.fixture(scope="function")
27+
def model_evaluation_id():
28+
client = automl.AutoMlClient()
29+
model_full_id = client.model_path(PROJECT_ID, "us-central1", MODEL_ID)
30+
generator = client.list_model_evaluations(model_full_id, "").pages
31+
page = next(generator)
32+
evaluation = page.next()
33+
model_evaluation_id = evaluation.name.split(
34+
"{}/modelEvaluations/".format(MODEL_ID)
35+
)[1].split("\n")[0]
36+
yield model_evaluation_id
37+
38+
39+
def test_get_model_evaluation(capsys, model_evaluation_id):
40+
get_model_evaluation.get_model_evaluation(
41+
PROJECT_ID, MODEL_ID, model_evaluation_id
42+
)
43+
out, _ = capsys.readouterr()
44+
assert "Model evaluation name: " in out

‎automl/beta/get_model_test.py

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
17+
import get_model
18+
19+
PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
20+
MODEL_ID = os.environ["ENTITY_EXTRACTION_MODEL_ID"]
21+
22+
23+
def test_get_model(capsys):
24+
get_model.get_model(PROJECT_ID, MODEL_ID)
25+
out, _ = capsys.readouterr()
26+
assert "Model id: " in out

‎automl/beta/list_models.py

Copy file name to clipboard
+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+
16+
def list_models(project_id):
17+
"""List models."""
18+
# [START automl_list_models_beta]
19+
from google.cloud import automl_v1beta1 as automl
20+
21+
# TODO(developer): Uncomment and set the following variables
22+
# project_id = "YOUR_PROJECT_ID"
23+
24+
client = automl.AutoMlClient()
25+
# A resource that represents Google Cloud Platform location.
26+
project_location = client.location_path(project_id, "us-central1")
27+
response = client.list_models(project_location, "")
28+
29+
print("List of models:")
30+
for model in response:
31+
# Display the model information.
32+
if (
33+
model.deployment_state
34+
== automl.enums.Model.DeploymentState.DEPLOYED
35+
):
36+
deployment_state = "deployed"
37+
else:
38+
deployment_state = "undeployed"
39+
40+
print("Model name: {}".format(model.name))
41+
print("Model id: {}".format(model.name.split("/")[-1]))
42+
print("Model display name: {}".format(model.display_name))
43+
print("Model create time:")
44+
print("\tseconds: {}".format(model.create_time.seconds))
45+
print("\tnanos: {}".format(model.create_time.nanos))
46+
print("Model deployment state: {}".format(deployment_state))
47+
# [END automl_list_models_beta]

‎automl/beta/list_models_test.py

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
17+
import list_models
18+
19+
PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
20+
21+
22+
def test_list_models(capsys):
23+
list_models.list_models(PROJECT_ID)
24+
out, _ = capsys.readouterr()
25+
assert "Model id: " in out

0 commit comments

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