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

Viewed 225

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?

2 Answers
get_by_name(workspace, name, version='latest')

Parameters

workspace

The existing AzureML workspace in which the Dataset was registered.

name

The registration name.

version

The registration version. Defaults to 'latest'.

Returns

The registered dataset object.

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.

Related