How to load image dataset using csv to get proper dataset datatype
Hi, I’m working on image classification. I have csv file which has image names, and their label mappings.I tried as suggestedhere., but I want the image to be in the form of PIL format, and also labels has to be detected.this is what I’m getting:>> data_files = {'train': 'train.csv', 'test': 'test.csv'}
ds = load_dataset('csv', data_files=data_files, data_dir='/kaggle/input/cassava-leaf-disease-classification/train_images/')
>> ds
DatasetDict({
    train: Dataset({
        features: ['Unnamed: 0', 'image_id', 'label'],
        num_rows: 17118
    })
    test: Dataset({
        features: ['Unnamed: 0', 'image_id', 'label'],
        num_rows: 4279
    })
})

>>ds['train'].features
{'Unnamed: 0': Value(dtype='int64', id=None),
 'image_id': Value(dtype='string', id=None),
 'label': Value(dtype='int64', id=None)}This is how I want it to be:image1836×468 36.1 KB(this image is from acolab notebookprovided by huggingface)How can I get it right?
2022-09-27T18:42:20Z
That notebook uses the ImageFolder loading strategy, but since you’re using a CSV file you can just cast the image_id column to anImage()after you’ve loaded the dataset. i.e. you can just runfrom datasets import Image
ds = ds.cast_column("image_id", Image())(FromLoad image data)And when you check the features again you’ll see that image_id will be an image!
2022-09-28T11:46:48Z
Thanks for the reply.By following that, I get this error ->> ds = ds.cast_column("image_id", Image())
---------------------------------------------------------------------------
ArrowNotImplementedError                  Traceback (most recent call last)
<ipython-input-22-8d1f43006898> in <module>
----> 1 ds = ds.cast_column("image_id", Image())

19 frames
/usr/local/lib/python3.7/dist-packages/pyarrow/error.pxi in pyarrow.lib.check_status()

ArrowNotImplementedError: Unsupported cast from int64 to struct using function cast_struct