コード例 #1
0
# Get workspace
ws = Workspace.from_config(auth=cli_auth)

# Get the Image to deploy details
try:
    with open("aml_config/image.json") as f:
        config = json.load(f)
except:
    print("No new model, thus no deployment on ACI")
    # raise Exception('No new model to register as production model perform better')
    sys.exit(0)

image_name = config["image_name"]
image_version = config["image_version"]

images = Image.list(workspace=ws)
image, = (m for m in images
          if m.version == image_version and m.name == image_name)
print(
    "From image.json, Image used to deploy webservice on ACI: {}\nImage Version: {}\nImage Location = {}"
    .format(image.name, image.version, image.image_location))

# image = max(images, key=attrgetter('version'))
# print('From Max Version, Image used to deploy webservice on ACI: {}\nImage Version: {}\nImage Location = {}'.format(image.name, image.version, image.image_location))

# Check if AKS already Available
try:
    with open("aml_config/aks_webservice.json") as f:
        config = json.load(f)
    aks_name = config["aks_name"]
    aks_service_name = config["aks_service_name"]
                     # in case you need to reference multiple models, or none at all, in your scoring script.
                     models = [model],
                     image_config = image_config, 
                     workspace = ws)

# COMMAND ----------

image.wait_for_creation(show_output = True)

# COMMAND ----------

# MAGIC %md List images by tag and find out the detailed build log for debugging.

# COMMAND ----------

for i in Image.list(workspace = ws,tags = ["area"]):
    print('{}(v.{} [{}]) stored at {} with build log {}'.format(i.name, i.version, i.creation_state, i.image_location, i.image_build_log_uri))

# COMMAND ----------

# MAGIC %md ### Deploy image as web service on Azure Container Instance
# MAGIC 
# MAGIC Note that the service creation can take few minutes.

# COMMAND ----------

from azureml.core.webservice import AciWebservice

aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1, 
                                               memory_gb = 1, 
                                               tags = {'area': "Credit scoring", 'type': "classification"},
コード例 #3
0
def test_scoring_image_present(get_ws_config):
    image_list = Image.list(ws, model_name="model.pkl")
    assert len(image_list) > 0, "Image deployed with model.pkl"
    # this is the model object
    models=[model],
    image_config=image_config,
    workspace=ws)

# Monitor image creation.

# In[ ]:

image.wait_for_creation(show_output=True)

# List images and find out the detailed build log for debugging.

# In[ ]:

for i in Image.list(workspace=ws):
    print('{}(v.{} [{}]) stored at {} with build log {}'.format(
        i.name, i.version, i.creation_state, i.image_location,
        i.image_build_log_uri))

# ### Deploy image as web service on Azure Container Instance
#
# Create AKS using provisioning configuration. It defines the number of nodes, their sizes and SSL certificate for secure connection to the endpoint. Here we use the defaiult values for these parameters.

# In[ ]:

from azureml.core.compute import ComputeTarget, AksCompute
# Use the default configuration (can also provide parameters to customize)
prov_config = AksCompute.provisioning_configuration()

aks_name = 'my-aks-8'