# Custom dataset based on CIFAR10

**URL:** <https://discuss.pytorch.org/t/custom-dataset-based-on-cifar10/171136>\
**Category:** vision\
**Created:** [January 26, 2023, 8:05pm UTC](https://discuss.pytorch.org/t/custom-dataset-based-on-cifar10/171136 "2023-01-26T20:05:04Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![thecho7](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/t/eada6e/32.png) [@thecho7](https://discuss.pytorch.org/u/thecho7)\
**Post date:** [January 27, 2023, 1:54pm UTC](https://discuss.pytorch.org/t/custom-dataset-based-on-cifar10/171136/4 "2023-01-27T13:54:50Z")

</div>

It seems `self.dst_train` is not a tensor but a list.  
From the example which is @ptrblck mentioned,

> [@How to use BatchSampler with \_\_getitem\_\_ dataset](https://discuss.pytorch.org/t/how-to-use-batchsampler-with-getitem-dataset/78788/4):
>
> Maybe this code snippet might be helpful: class MyDataset(Dataset): def \_\_init\_\_(self): self.data = torch.arange(100).view(100, 1).float() def \_\_getitem\_\_(self, index): x = self.data[index] return x def \_\_len\_\_(self): return len(self.data) dataset = MyDataset() sampler = torch.utils.data.sampler.BatchSampler( torch.utils.data.sampler.RandomSampler(dataset), batch\_size=10, drop\_last=False) loader = DataLoader( da…

The dataset is a tensor has size of (100, 1) but your `self.dst_train` is a list.  
List type cannot be indexed with list where a tensor can do.

Try convert `self.dst_train` to a tensor.  
Should work

---

_[View the full topic](https://discuss.pytorch.org/t/custom-dataset-based-on-cifar10/171136)._
