bomri / code-for-posts

code scripts for blog posts I published
13 stars 5 forks source link

How can I solve Imagefolder dataset problem? #1

Closed donaldaq closed 4 years ago

donaldaq commented 4 years ago

Thank you for your posts I have a problem about imagefolder in pytorch?


AttributeError Traceback (most recent call last)

in 17 sampler=BalancedBatchSchedulerSampler(dataset=image_datasets['train'],batch_size=16), 18 shuffle=False, num_workers=4) ---> 19 for x in ['train', 'val', 'test']} 20 21 dataset_sizes = {x: len(image_datasets[x]) for x in ['train', 'val', 'test']} in (.0) 17 sampler=BalancedBatchSchedulerSampler(dataset=image_datasets['train'],batch_size=16), 18 shuffle=False, num_workers=4) ---> 19 for x in ['train', 'val', 'test']} 20 21 dataset_sizes = {x: len(image_datasets[x]) for x in ['train', 'val', 'test']} ~/ml/pytorch-image-classification/imbalancedbatch/balanced_sampler.py in __init__(self, dataset, batch_size) 22 self.dataset = dataset 23 self.batch_size = batch_size ---> 24 self.number_of_datasets = len(dataset.datasets) 25 26 def __len__(self): AttributeError: 'ImageFolder' object has no attribute 'datasets'
bomri commented 4 years ago

Hey @donaldaq,

The BalancedBatchSchedulerSampler expect to get a dataset of type ConcatDataset, if you are working with only one dataset you should use ImbalancedDatasetSampler. If you do try to work with multiple datasets can you please share the code you are using.

donaldaq commented 4 years ago

Hey @donaldaq,

The BalancedBatchSchedulerSampler expect to get a dataset of type ConcatDataset, if you are working with only one dataset you should use ImbalancedDatasetSampler. If you do try to work with multiple datasets can you please share the code you are using.

Thanks. I got it