Azure ML dataset: label column of dataset is None

Daniel 1 Reputation point
2020-11-18T14:25:09.727+00:00

Hi,

For a project we need to load some data and its labels from an azure ML dataset. However when using the following sample code in python:

    from azureml.core import Workspace, Dataset
    subscription_id = 'sub-id...'
    resource_group = 'res-grp...'
    workspace_name = 'ws-name...'
    ds_name = 'name-of-ds'

    workspace = Workspace(subscription_id, resource_group, workspace_name)
    dataset = Dataset.get_by_name(workspace, name=ds_name).to_pandas_dataframe()

the labels are None. The dataset was exported from a "Image Classification Multi-label" project. For a dataset exported from a "Image Classification Multi-class" the code works fine. Currently I work on a local PC in Pycharm with Python 3.5 (due to easier debugging). Can you maybe help me with that?

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,880 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. romungi-MSFT 45,556 Reputation points Microsoft Employee
    2020-11-19T04:54:47.477+00:00

    @Daniel Here are the detailed steps to handle datasets with labels while loading to a pandas dataframe. For example:

    import azureml.core  
    import azureml.contrib.dataset  
    from azureml.core import Dataset, Workspace  
    from azureml.contrib.dataset import FileHandlingOption  
      
    # get animal_labels dataset from the workspace  
    animal_labels = Dataset.get_by_name(workspace, 'animal_labels')  
    animal_pd = animal_labels.to_pandas_dataframe(file_handling_option=FileHandlingOption.DOWNLOAD, target_path='./download/', overwrite_download=True)  
      
    import matplotlib.pyplot as plt  
    import matplotlib.image as mpimg  
      
    #read images from downloaded path  
    img = mpimg.imread(animal_pd.loc[0,'image_url'])  
    imgplot = plt.imshow(img)  
    

    A sample notebook to try these scenarios is also available here. We hope this helps!!

    0 comments No comments

  2. Daniel 1 Reputation point
    2020-11-25T12:28:45.993+00:00

    @romungi-MSFT thanks for the answer! Actually I'm not trying to download the images but only get the labels with it's corresponding image_url's. When I use the sample code provided I get the following error:

    TypeError: lstat: illegal type for path parameter  
    During handling of the above exception, another exception occurred:  
    azureml._common.exceptions.AzureMLException: AzureMLException:  
     Message: Execution failed in operation 'to_pandas_dataframe' for Dataset(id='subs_id...', name='ds_name...', version=1, exception_type=TypeError)  
     InnerException lstat: illegal type for path parameter  
     ErrorResponse   
    {  
    "error": {  
        "message": "Execution failed in operation 'to_pandas_dataframe' for Dataset(id='subs_id...', name='ds_name...', version=1, exception_type=TypeError)"  
    }  
    

    }

    However the data gets downloaded to './download' but I still cant access the labels of the datapoints.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.