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 2a35d64

Browse filesBrowse files
nnegreyandrewferlitsch
authored andcommitted
Add missing deploy / undeploy samples (GoogleCloudPlatform#2433)
* Add missing deploy / undeploy samples * Add new node count sample, update style * Update automl_vision_object_detection_deploy_model.py * Update automl_vision_object_detection_deploy_node_count.py * Update automl_vision_object_detection_undeploy_model.py
1 parent f3fb377 commit 2a35d64
Copy full SHA for 2a35d64
Expand file treeCollapse file tree

4 files changed

+226
-0
lines changed
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2019 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+
import argparse
17+
18+
19+
def deploy_model(project_id, model_id):
20+
"""Deploy a model."""
21+
# [START automl_vision_object_detection_deploy_model]
22+
from google.cloud import automl_v1beta1 as automl
23+
24+
# project_id = 'YOUR_PROJECT_ID'
25+
# model_name = 'YOUR_MODEL_ID'
26+
27+
client = automl.AutoMlClient()
28+
29+
# The full path to your model
30+
full_model_id = client.model_path(project_id, 'us-central1', model_id)
31+
32+
# Deploy the model
33+
response = client.deploy_model(full_model_id)
34+
35+
print(u'Model deployment finished'.format(response.result()))
36+
# [END automl_vision_object_detection_deploy_model]
37+
38+
39+
if __name__ == '__main__':
40+
parser = argparse.ArgumentParser(
41+
description=__doc__,
42+
formatter_class=argparse.RawDescriptionHelpFormatter,
43+
)
44+
45+
parser.add_argument(
46+
'--project-id',
47+
help='YOUR_PROJECT_ID',
48+
required=True)
49+
parser.add_argument(
50+
'--model-id',
51+
help='YOUR_MODEL_ID',
52+
required=True)
53+
54+
args = parser.parse_args()
55+
56+
deploy_model(args.project_id, args.model_id)
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2019 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+
import argparse
17+
18+
19+
def deploy_model_node_count(project_id, model_id):
20+
"""Deploy a model."""
21+
# [START automl_vision_object_detection_deploy_model_node_count]
22+
from google.cloud import automl_v1beta1 as automl
23+
24+
# project_id = 'YOUR_PROJECT_ID'
25+
# model_name = 'YOUR_MODEL_ID'
26+
27+
client = automl.AutoMlClient()
28+
29+
# The full path to your model
30+
full_model_id = client.model_path(project_id, 'us-central1', model_id)
31+
32+
# Set how many nodes the model is deployed on
33+
model_deployment_metadata = (
34+
automl.types.ImageObjectDetectionModelDeploymentMetadata(node_count=2))
35+
36+
# Deploy the model
37+
response = client.deploy_model(full_model_id, model_deployment_metadata)
38+
39+
print(u'Model deployment on 2 nodes finished'.format(response.result()))
40+
# [END automl_vision_object_detection_deploy_model_node_count]
41+
42+
43+
if __name__ == '__main__':
44+
parser = argparse.ArgumentParser(
45+
description=__doc__,
46+
formatter_class=argparse.RawDescriptionHelpFormatter,
47+
)
48+
49+
parser.add_argument(
50+
'--project-id',
51+
help='YOUR_PROJECT_ID',
52+
required=True)
53+
parser.add_argument(
54+
'--model-id',
55+
help='YOUR_MODEL_ID',
56+
required=True)
57+
58+
args = parser.parse_args()
59+
60+
deploy_model_node_count(args.project_id, args.model_id)
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2019 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 pytest
18+
19+
import automl_vision_object_detection_deploy_model
20+
import automl_vision_object_detection_deploy_node_count
21+
import automl_vision_object_detection_undeploy_model
22+
23+
PROJECT_ID = os.environ['GCLOUD_PROJECT']
24+
MODEL_ID = 'IOD6143103405779845120'
25+
26+
27+
@pytest.mark.slow
28+
def test_object_detection_deploy_undeploy_model(capsys):
29+
automl_vision_object_detection_deploy_model.deploy_model(
30+
PROJECT_ID, MODEL_ID)
31+
32+
out, _ = capsys.readouterr()
33+
assert 'Model deployment finished' in out
34+
35+
automl_vision_object_detection_undeploy_model.undeploy_model(
36+
PROJECT_ID, MODEL_ID)
37+
38+
out, _ = capsys.readouterr()
39+
assert 'Model undeploy finished' in out
40+
41+
42+
@pytest.mark.slow
43+
def test_object_detection_deploy_node_count_undeploy_model(capsys):
44+
automl_vision_object_detection_deploy_node_count.deploy_model_node_count(
45+
PROJECT_ID, MODEL_ID)
46+
47+
out, _ = capsys.readouterr()
48+
assert 'Model deployment on 2 nodes finished' in out
49+
50+
automl_vision_object_detection_undeploy_model.undeploy_model(
51+
PROJECT_ID, MODEL_ID)
52+
53+
out, _ = capsys.readouterr()
54+
assert 'Model undeploy finished' in out
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2019 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+
import argparse
17+
18+
19+
def undeploy_model(project_id, model_id):
20+
"""Undeploy a model."""
21+
# [START automl_vision_object_detection_undeploy_model]
22+
from google.cloud import automl_v1beta1 as automl
23+
24+
# project_id = 'YOUR_PROJECT_ID'
25+
# model_name = 'YOUR_MODEL_ID'
26+
27+
client = automl.AutoMlClient()
28+
29+
# The full path to your model
30+
full_model_id = client.model_path(project_id, 'us-central1', model_id)
31+
32+
# Undeploy the model
33+
response = client.undeploy_model(full_model_id)
34+
35+
print(u'Model undeploy finished'.format(response.result()))
36+
# [END automl_vision_object_detection_undeploy_model]
37+
38+
39+
if __name__ == '__main__':
40+
parser = argparse.ArgumentParser(
41+
description=__doc__,
42+
formatter_class=argparse.RawDescriptionHelpFormatter,
43+
)
44+
45+
parser.add_argument(
46+
'--project-id',
47+
help='YOUR_PROJECT_ID',
48+
required=True)
49+
parser.add_argument(
50+
'--model-id',
51+
help='YOUR_MODEL_ID',
52+
required=True)
53+
54+
args = parser.parse_args()
55+
56+
undeploy_model(args.project_id, args.model_id)

0 commit comments

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