Search code examples
azure-machine-learning-service

How to extract a dataset from azureml.core.model.Model Class?


Azure Machine Learning Service's Model Artifact has the ability to store references to the Datasets associated with the model. We can use azureml.core.model.Model.add_dataset_references([('relation-as-a-string', Dataset)]) to add these dataset references. How do we retrieve a Dataset from the references stored in this Model class by using a reference to the Model Class?


Solution

  • Consider that a Dataset was added as a reference to a Model with the name 'training_dataset'

    In order to get a reference to this Dataset we use:

    model = Model(workspace, name)
    dataset_id = next(dictionary['id'] for dictionary in model.serialize()['datasets'] if dictionary["name"] == 'training_dataset')
    dataset_reference = Dataset.get_by_id(workspace, dataset_id )
    

    After this step we can use dataset_reference as any other AzureML Dataset Class object.