def create_dict_images_per_label(data_source):
    """
            Compute and returns dictionary of images per label
            Args:
                data_source (ListDataset) : The data set containing the images
            Returns:
                dict: each key maps to a list of the images which contain at least one target which label is the key
            """
    images_per_label={}

    for index in range(len(data_source)):
        try:
            targets = data_source[index][2]
            if targets is not None:
                for target in targets:
                    label = int(target[1])
                    if label not in images_per_label:
                        images_per_label[label] = []
                    if len(images_per_label[label]) == 0 or images_per_label[label][-1] != index:
                        images_per_label[label].append(index)
                if index % 100 == 0:
                    print('{index}/{length_data_source} images considered'.format(
                        index=index,
                        length_data_source=len(data_source))
                    )
        except OSError:
            print('Corrupted image : {image_index}'.format(image_index=index))
    return images_per_label