0

Try to containerize models using docker and use this in a web service. Getting the following error "azureml.exceptions._azureml_exception.WebserviceException: WebserviceException:Message: Models must either be of type azureml.core.Model or a str path to a file or folder".

    env = Environment.from_conda_specification("env", "../Environments.yml")
    inf_conf = InferenceConfig(
    entry_script="score.py",
    environment=env)


    docker_image = Model.package(ws, [models_latest], inf_conf)
    docker_image.wait_for_creation(show_output=True) 



    # Deploy the image
    webservice_name = os.environ['WEB_SERVICE_NAME']

    retries = 2
    while retries > 0:
        try:
            service = AciWebservice(workspace = ws,
                                    name = webservice_name)
            service.update(image = docker_image)
            print('Webservice updated')   
        except:
            print('Webservice not found')
            service = Webservice.deploy_from_image(workspace = ws,
                                                name = webservice_name,
                                                image = docker_image,
                                                deployment_config = aciconfig)

        # wait for deployment, get logs if failed
        try:
            service.wait_for_deployment(show_output = True)
            break
        except:
            print(service.get_logs())
            retries -= 1
            if retries == 0:
                raise
tommyt
  • 309
  • 5
  • 15

1 Answers1

0

Get the YAML file into the accurate environment including the path using the following command.

conda activate myenv

Replace myenv with your virtual environment.

conda env export > environment.yml

export this active environment to the new file (YAML file) Make the model as standard PKL file and assign that pickle file as an input.

Example when the model is a file

model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')

Example when the model is a folder containing a file

file_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'my_model_folder', 'sklearn_regression_model.pkl')

For connecting docker image to web server properly, refer

Sairam Tadepalli
  • 1,563
  • 1
  • 3
  • 11