# Does a custom dataset need to always inherit the Dataset class?

**URL:** <https://discuss.pytorch.org/t/does-a-custom-dataset-need-to-always-inherit-the-dataset-class/112474>\
**Category:** vision\
**Created:** [February 21, 2021, 1:23am UTC](https://discuss.pytorch.org/t/does-a-custom-dataset-need-to-always-inherit-the-dataset-class/112474 "2021-02-21T01:23:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smth\_w](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/c67d28/32.png) [@Smth\_w](https://discuss.pytorch.org/u/Smth_w)\
**Post date:** [February 21, 2021, 1:23am UTC](https://discuss.pytorch.org/t/does-a-custom-dataset-need-to-always-inherit-the-dataset-class/112474/1 "2021-02-21T01:23:07Z")

</div>

It may be a trivial question but while reading this tutorial: [TorchVision Object Detection Finetuning Tutorial — PyTorch Tutorials 1.7.1 documentation](https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html)

I found this custom Dataset

```auto
class PennFudanDataset(object):
    def __init__ (self, root, transforms):
        #random code

```

Which does not inherit torch.utils.data.Dataset (even though pytorch itself recommends us to "inherit `Dataset` ")

My question is simple, can I just create a custom dataset with just ‘object’ and not ‘Dataset’? if so is there a drawback for using ‘object’ instead of ‘Dataset’?

And since we are already here, why do we need to inherit ‘torch.utils.data.Dataset’ to create a custom dataset?  
I’ve checked the source code and it only contains **getitem** and **add** , do we do it only because of “good practices” or is there something about this class I’m missing here??

Thanks for any help!!

---

<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:** [February 21, 2021, 5:59am UTC](https://discuss.pytorch.org/t/does-a-custom-dataset-need-to-always-inherit-the-dataset-class/112474/2 "2021-02-21T05:59:53Z")

</div>

It’s not strictly necessary, as the base [`Dataset`](https://github.com/pytorch/pytorch/blob/a61a8d059efa0fb139a09e479b1a2c8dd1cf1a44/torch/utils/data/dataset.py#L16-L40) implements the ` __add__ ` method for you and defines the ` __getitem__ `, but for the sake of code clarity I would still recommend to derive your custom class from `Dataset`.
