tristandeleu / pytorch-meta

A collection of extensions and data-loaders for few-shot learning & meta-learning in PyTorch
https://tristandeleu.github.io/pytorch-meta/
MIT License
1.98k stars 256 forks source link

how to create a custom dataset #113

Closed raymond00000 closed 3 years ago

raymond00000 commented 3 years ago

I could not figure out how to create a custom dataset.

I have a dataset that return (x, target), let it called "trainset" I have a collate function, let it called "collate_fn"

so, I tried:

metaDataLoader = MetaDataLoader(trainset, collate_fn=collate_fn) bmetaDataLoader = BatchMetaDataLoader(metaDataLoader) for batch in bmetaDataLoader: print(batch)

but it returned

data = [self.dataset[idx] for idx in possibly_batched_index]

TypeError: 'MetaDataLoader' object does not support indexing

tristandeleu commented 3 years ago

The datasets used in Torchmeta, and inside a MetaDataLoader are inherited from the MetaDataset class. There is no way at the moment to automatically transform a standard PyTorch dataset into a MetaDataset, because it really depends on the way you want to formulate your problem (is it a few-shot regression problem?, is it a few-shot classification problem?).

In order to create your own dataset, I suggest you to look at some of the existing datasets for inspiration:

Look also at https://github.com/tristandeleu/pytorch-meta/issues/102#issuecomment-726741999 for a more detailed description of the inner-workings.

I hope this helps!