-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
47 lines (38 loc) · 1.26 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sagemaker
from sagemaker.amazon.amazon_estimator import get_image_uri
from utils.env import role, saved_model_folder, endpoint_name, instance_size, region
import sys
import boto3
sagemaker_session = sagemaker.Session()
bucket = sagemaker_session.default_bucket()
prefix = "sar/semantic-segmentation"
saved_model_location = (
f"s3://{bucket}/{prefix}/output/{saved_model_folder}/output/model.tar.gz"
)
sagemaker_session = sagemaker.Session()
training_image = get_image_uri(
sagemaker_session.boto_region_name, "semantic-segmentation", repo_version="latest"
)
# Delete endpoint
def undeploy():
sagemaker_client = boto3.client("sagemaker", region_name=region)
sagemaker_client.delete_endpoint_config(EndpointConfigName=endpoint_name)
# Deploy trained model to sagemaker endpoint
def deploy():
trained_model = sagemaker.model.Model(
image=training_image,
model_data=saved_model_location,
role=role,
)
trained_model.deploy(
initial_instance_count=1,
instance_type=instance_size,
endpoint_name=endpoint_name,
)
if __name__ == "__main__":
if len(sys.argv) == 0:
deploy()
elif sys.argv[0].lower() == "deploy":
deploy()
elif sys.argv[0].lower() == "undeploy":
undeploy()