# Using Hugging Face dataset class as pytorch class

**URL:** <https://discuss.huggingface.co/t/using-hugging-face-dataset-class-as-pytorch-class/10385>\
**Category:** Beginners\
**Created:** [September 29, 2021, 9:45am UTC](https://discuss.huggingface.co/t/using-hugging-face-dataset-class-as-pytorch-class/10385 "2021-09-29T09:45:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unknown-User](https://avatars.discourse-cdn.com/v4/letter/u/cdc98d/32.png) [@Unknown-User](https://discuss.huggingface.co/u/Unknown-User)\
**Post date:** [September 29, 2021, 9:45am UTC](https://discuss.huggingface.co/t/using-hugging-face-dataset-class-as-pytorch-class/10385/1 "2021-09-29T09:45:53Z")

</div>

Hi,

I have created a custom dataset class using hugging face, and for some reason I would like to use this class as a pytorch dataset class. (with get\_item etc…)

Is it possible ?

Thanks

---

<div class="post-metadata">

**Author:** ![BramVanroy](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bramvanroy/32/47360_2.png) [@BramVanroy](https://discuss.huggingface.co/u/BramVanroy)\
**Post date:** [September 29, 2021, 11:01am UTC](https://discuss.huggingface.co/t/using-hugging-face-dataset-class-as-pytorch-class/10385/2 "2021-09-29T11:01:37Z")

</div>

This is possible by default. What exactly do you want to do? You can simply use such dataset in a PT dataloader as well, as long as you set the format to torch. For instance:

```auto
dataset.set_format(type='torch', columns=['input_ids', 'token_type_ids', 'attention_mask', 'labels'])

```

---

<div class="post-metadata">

**Author:** ![Unknown-User](https://avatars.discourse-cdn.com/v4/letter/u/cdc98d/32.png) [@Unknown-User](https://discuss.huggingface.co/u/Unknown-User)\
**Post date:** [September 29, 2021, 11:57am UTC](https://discuss.huggingface.co/t/using-hugging-face-dataset-class-as-pytorch-class/10385/3 "2021-09-29T11:57:07Z")

</div>

Thanks,

I would like to apply data augmentation to a dataset (of images) which is an instance of my hugging face custom dataset class. For it to be easier, I’d like to convert this dataset to a pytorch dataset so that I can then be able to add the attribute “transform=” to it when I instanciate my dataset class.

An example : train\_loader = torch.utils.data.DataLoader(datasets.CIFAR10(root=data\_root, train=True, transform=transform\_train))

Here, CIFAR10 is a custom dataset of pytorch, and hence we can give it the attribute transform, I would like to do the same thing.

Is it possible ?

Thanks

---

<div class="post-metadata">

**Author:** ![BramVanroy](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bramvanroy/32/47360_2.png) [@BramVanroy](https://discuss.huggingface.co/u/BramVanroy)\
**Post date:** [September 29, 2021, 12:24pm UTC](https://discuss.huggingface.co/t/using-hugging-face-dataset-class-as-pytorch-class/10385/4 "2021-09-29T12:24:41Z")

</div>

Not sure. Maybe others can help.
