# How to load image dataset using csv to get proper dataset datatype

**URL:** <https://discuss.huggingface.co/t/how-to-load-image-dataset-using-csv-to-get-proper-dataset-datatype/23680>\
**Category:** Beginners\
**Created:** [September 27, 2022, 2:00pm UTC](https://discuss.huggingface.co/t/how-to-load-image-dataset-using-csv-to-get-proper-dataset-datatype/23680 "2022-09-27T14:00:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddharth963](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@siddharth963](https://discuss.huggingface.co/u/siddharth963)\
**Post date:** [September 27, 2022, 2:00pm UTC](https://discuss.huggingface.co/t/how-to-load-image-dataset-using-csv-to-get-proper-dataset-datatype/23680/1 "2022-09-27T14:00:25Z")

</div>

Hi, I’m working on image classification. I have csv file which has image names, and their label mappings.  
I tried as suggested [here.](https://huggingface.co/docs/datasets/v2.5.1/en/package_reference/loading_methods#datasets.load_dataset), 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:

```auto
>> 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:

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/dd27985bbc66aff3a8c6e770ca54b532bc8d765c.png)  
(this image is from a [colab notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb#scrollTo=BnnL3yHBI7Z3) provided by huggingface)

How can I get it right?

---

<div class="post-metadata">

**Author:** ![NimaBoscarino](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nimaboscarino/32/4358_2.png) [@NimaBoscarino](https://discuss.huggingface.co/u/NimaBoscarino)\
**Post date:** [September 27, 2022, 6:42pm UTC](https://discuss.huggingface.co/t/how-to-load-image-dataset-using-csv-to-get-proper-dataset-datatype/23680/2 "2022-09-27T18:42:20Z")

</div>

That notebook uses the ImageFolder loading strategy, but since you’re using a CSV file you can just cast the image\_id column to an `Image()` after you’ve loaded the dataset. i.e. you can just run

```python
from datasets import Image
ds = ds.cast_column("image_id", Image())

```

(From [Load image data](https://huggingface.co/docs/datasets/v2.5.1/en/image_load#local-files))

And when you check the features again you’ll see that image\_id will be an image!

---

<div class="post-metadata">

**Author:** ![siddharth963](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@siddharth963](https://discuss.huggingface.co/u/siddharth963)\
**Post date:** [September 28, 2022, 11:46am UTC](https://discuss.huggingface.co/t/how-to-load-image-dataset-using-csv-to-get-proper-dataset-datatype/23680/3 "2022-09-28T11:46:48Z")

</div>

Thanks for the reply.  
By following that, I get this error -

```auto
>> 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

```
