Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,202 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I try to deploy a model to an online endpoint. However I have an error when I use local endpoints. I want to deploy a deep learning model for object detection in images.
Here's what I did :
ws = Workspace(subscription_id, resource_group, workspace_name) # connection to the Azure ML Workspace
ml_client = MLClient(
DefaultAzureCredential(), subscription_id, resource_group, workspace_name
)
# Get a previous training
Id_experiment = "valid-model"
automl_image_run = AutoMLRun(experiment=Experiment(ws,experiment_name), run_id=Id_experiment)
best_child_run = automl_image_run.get_best_child()
model_name = best_child_run.properties['model_name']
model_name = 'model_window_detection'
registered_model = Model(workspace=ws, name=model_name)
model_path = registered_model.download(target_dir='.', exist_ok=True)
# Configure an endpoint
import datetime
endpoint_name = "window-detection-endpoint"
endpoint_name = "endpt-" + datetime.datetime.now().strftime("%m%d%H%M%f")
endpoint = ManagedOnlineEndpoint(
name = endpoint_name,
description="this is a sample endpoint",
auth_mode="key"
)
# Configure a deployment
# model is registered_model
existing_env_name = "azureml_py38" #Name of my existing virtual environment
# Create the environment object using the existing environment
env = Environment(name=existing_env_name)
code_config = CodeConfiguration(
code="./",
scoring_script="score.py"
)
# Create the deployment using the specified environment
deployment = ManagedOnlineDeployment(
name="blue",
endpoint_name=endpoint_name,
model=registered_model,
environment=env, # Use the existing Conda environment
code_configuration=code_config,
instance_type="Standard_NC6s_v3",
instance_count=1
)
ml_client.online_endpoints.begin_create_or_update(endpoint, local=True) #Works
ml_client.online_deployments.begin_create_or_update(
deployment=deployment, local=True
) #This is the line that generates an error
The error :
{
"name": "Exception",
"message": "['Non-string passed to RegistryStr for model', 'Non-string passed to ArmStr for model', \"'Model' object has no attribute '_intellectual_property'\"]",
"stack": "---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/azure/ai/ml/operations/_local_deployment_helper.py:82, in _LocalDeploymentHelper.create_or_update(self, deployment, local_endpoint_mode, local_enable_gpu)
80 operation_message = \"Creating local deployment\"
---> 82 deployment_metadata = json.dumps(deployment._to_dict())
83 endpoint_metadata = (
84 endpoint_metadata
85 if endpoint_metadata
86 else _get_stubbed_endpoint_metadata(endpoint_name=deployment.endpoint_name)
87 )
File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/azure/ai/ml/entities/_deployment/online_deployment.py:748, in ManagedOnlineDeployment._to_dict(self)
747 def _to_dict(self) -> Dict:
--> 748 return ManagedOnlineDeploymentSchema(context={BASE_PATH_CONTEXT_KEY: \"./\"}).dump(self)
File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/marshmallow/schema.py:549, in Schema.dump(self, obj, many)
547 processed_obj = obj
--> 549 result = self._serialize(processed_obj, many=many)
551 if self._has_processors(POST_DUMP):
File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/marshmallow/schema.py:517, in Schema._serialize(self, obj, many)
516 for attr_name, field_obj in self.dump_fields.items():
--> 517 value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
518 if value is missing:
File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/azure/ai/ml/_exception_helper.py:337, in log_and_raise_error(error, debug, yaml_operation)
334 else:
335 raise error
--> 337 raise Exception(formatted_error)
Exception: ['Non-string passed to RegistryStr for model', 'Non-string passed to ArmStr for model', \"'Model' object has no attribute '_intellectual_property'\"]"
}
I can also give you my script score.py :
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
import os
from azureml.automl.core.shared import logging_utilities
from azureml.automl.dnn.vision.object_detection.writers.score import _score_with_model
from azureml.automl.dnn.vision.common.logging_utils import get_logger
from azureml.automl.dnn.vision.common.model_export_utils import (
load_model, run_inference_helper)
from azureml.automl.dnn.vision.common.utils import _set_logging_parameters
from azureml.contrib.services.aml_request import rawhttp
from azureml.contrib.services.aml_response import AMLResponse
from azureml.core.model import Model
TASK_TYPE = 'image-object-detection'
logger = get_logger('azureml.automl.core.scoring_script_images')
def init():
global model
# Set up logging
_set_logging_parameters(TASK_TYPE, {})
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'model.pt')
if not os.path.exists(model_path):
model_path = Model.get_model_path(model_name='AutoML322455a460')
try:
logger.info("Loading model from path: {}.".format(model_path))
model_settings = {"min_size": 600, "max_size": 1333, "box_score_thresh": 0.3, "nms_iou_thresh": 0.5, "box_detections_per_img": 100,
"tile_grid_size": None, "tile_overlap_ratio": 0.25, "tile_predictions_nms_thresh": 0.25}
model = load_model(TASK_TYPE, model_path, **model_settings)
logger.info("Loading successful.")
except Exception as e:
logging_utilities.log_traceback(e, logger)
raise
@rawhttp
def run(request):
logger.info("Request: [{0}]".format(request))
if request.method == "GET":
response_body = str.encode(request.full_path)
return AMLResponse(response_body, 200)
elif request.method == "POST":
request_body = request.get_data()
logger.info("Running inference.")
result = run_inference_helper(model, request_body, _score_with_model, TASK_TYPE)
logger.info("Finished inferencing.")
return AMLResponse(result, 200)
else:
return AMLResponse("bad request", 500)