[Python] Azure ML - can't use the model path

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use the model path, unfortunately I can't. This is the code:

    Setting up the environment and correct access:

    subscription_id = "xxxxxxxxxxx"
    resource_group = "xxxxxxxx"
    workspace = "xxxxxxxxxx"

    ml_client = MLClient(DefaultAzureCredential(), subscription_id, resource_group, workspace)
    ws = ml_client.workspaces.get("xxxxxxxxxx")
    print(ws.location, ":", ws.resource_group)


    I'm getting confirmation that I'm in the right location and correct resource. Next, I'm registering the model.

    from azure.ai.ml.entities import Model
    from azure.ai.ml.constants import ModelType

    cloud_model = Model(
    path="model.pt",
    name="model_name",
    type="custom",
    description="Model created from cloud path."
    )
    ml_client.models.create_or_update(cloud_model)

    latest_model_version = max([int(m.version) for m in ml_client.models.list(name="model_name")])

    registered_model = ml_client.models.get(name="model_name", version=latest_model_version)


    The code above executed correcly the model have been registered and I can access it. The next block of code is the one, where the issue comes from.

    from ultralytics import YOLO

    def init():
    """
    This function is called when the container is initialized/started, typically after create/update of the deployment.
    You can write the logic here to perform init operations like caching the model in memory
    """
    global model
    # AZUREML_MODEL_DIR is an environment variable created during deployment.
    # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)
    model_path = registered_model.path
    # deserialize the model file back into a sklearn model
    model = YOLO(model_path)
    logging.info("Init complete")

    init()


    The error: FileNotFoundError: [Errno 2] No such file or directory:. Really can't wrap my head arround, how in the previous lines I can access the model and it's path, but I can't use it further down the road?

    Continue reading...

Compartilhe esta Página