# How to create Pytorch dataset with filepath label format

**URL:** <https://discuss.pytorch.org/t/how-to-create-pytorch-dataset-with-filepath-label-format/135362>\
**Category:** vision\
**Created:** [October 28, 2021, 10:58pm UTC](https://discuss.pytorch.org/t/how-to-create-pytorch-dataset-with-filepath-label-format/135362 "2021-10-28T22:58:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gordon\_Lim](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/gordon_lim/32/43412_2.png) [@Gordon\_Lim](https://discuss.pytorch.org/u/Gordon_Lim)\
**Post date:** [October 28, 2021, 10:58pm UTC](https://discuss.pytorch.org/t/how-to-create-pytorch-dataset-with-filepath-label-format/135362/1 "2021-10-28T22:58:22Z")

</div>

I want to create a Pytorch dataset for RVL-CDIP to feed to a pytorch dataloader. This is the format

imagesq/q/o/c/qoc54c00/80035521.tif 15  
where 15 is a label

is there a pytorch datasets function to create said dataset.

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [October 29, 2021, 7:16am UTC](https://discuss.pytorch.org/t/how-to-create-pytorch-dataset-with-filepath-label-format/135362/2 "2021-10-29T07:16:33Z")

</div>

I would suggest to write a custom `Dataset` as described [here](https://pytorch.org/tutorials/beginner/data_loading_tutorial.html). This would allow you to define the logic to load and process each sample manually. Based on your description I guess the path and label might be stored as a string or `tuple` etc. so splitting them into a list containing image paths and the corresponding target tensor should work.
