-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_image.py
52 lines (37 loc) · 1.72 KB
/
create_image.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
48
49
50
51
"""
create_image.py
By: Sebastian D. Goodfellow, Ph.D., 2019
"""
from azureml.core import Workspace
from azureml.core.model import Model
from azureml.core.image import Image, ContainerImage
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
def create_image(args):
"""Create Docker image from registered model"""
# Get workspace
workspace = Workspace.get(name='mnist-azure', subscription_id=args.subscription_id,
resource_group=args.resource_group)
# Get registered model
model = Model(workspace=workspace, name=args.model_name, version=args.model_id)
# Configure image
image_config = ContainerImage.image_configuration(runtime='python', execution_script='scoring.py',
conda_file='service_env.yml')
# Create image
image = Image.create(name=args.image_name, models=[model], image_config=image_config, workspace=workspace)
image.wait_for_creation(show_output=True)
def get_parser():
"""Get parser object for script upload_data.py."""
# Initialize parser
parser = ArgumentParser(description=__doc__, formatter_class=ArgumentDefaultsHelpFormatter)
# Setup arguments
parser.add_argument('--image_name', dest='image_name', type=str)
parser.add_argument('--model_name', dest='model_name', type=str)
parser.add_argument('--model_id', dest='model_id', type=int)
parser.add_argument('--subscription_id', dest='subscription_id', type=str)
parser.add_argument('--resource_group', dest='resource_group', type=str)
return parser
if __name__ == '__main__':
# Parse arguments
arguments = get_parser().parse_args()
# Run main function
create_image(args=arguments)