edgarschnfld / CADA-VAE-PyTorch

Official implementation of the paper "Generalized Zero- and Few-Shot Learning via Aligned Variational Autoencoders" (CVPR 2019)
MIT License
283 stars 57 forks source link

TypeError: object of type 'DATA_LOADER' has no len() #17

Closed VisintZJ closed 4 years ago

VisintZJ commented 4 years ago

Hi, I meet a problem when I run "python single_experiment.py --dataset CUB --num_shots 0 --generalized True" which is that "TypeError: object of type 'DATA_LOADER' has no len()". My pytorch version is 1.1.0. Do you have any idea to solve this problem? Thank you!

edgarschnfld commented 4 years ago

Hi, Yes, I could reproduce the error in my pytorch 1.1.10. environment:

Traceback (most recent call last): File "single_experiment.py", line 175, in losses = model.train_vae() File "/home/esc2rng/repositories/CADA-VAE-PyTorch/model/vaemodel.py", line 206, in train_vae self.dataloader = data.DataLoader(self.dataset,batch_size= self.batch_size,shuffle= True,drop_last=True)#,num_workers = 4) File "/software/esc2rng/anaconda/envs/testenv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 176, in init sampler = RandomSampler(dataset) File "/software/esc2rng/anaconda/envs/testenv/lib/python3.6/site-packages/torch/utils/data/sampler.py", line 64, in init if not isinstance(self.num_samples, int) or self.num_samples <= 0: File "/software/esc2rng/anaconda/envs/testenv/lib/python3.6/site-packages/torch/utils/data/sampler.py", line 72, in num_samples return len(self.data_source) TypeError: object of type 'DATA_LOADER' has no len()

I've come across this error before, and I think it's related to the PyTorch version. PyTorch version 1 wasn't released yet when this code was written :) If you create a python virtual environment (conda or virtualenv) with Python 3.5.6 and the packages below it should work: torch==0.4.1 numpy==1.14.3 scipy==1.1.0 scikit_learn==0.20.3 networkx==1.11

VisintZJ commented 4 years ago

Hi, Yes, I could reproduce the error in my pytorch 1.1.10. environment:

Traceback (most recent call last): File "single_experiment.py", line 175, in losses = model.train_vae() File "/home/esc2rng/repositories/CADA-VAE-PyTorch/model/vaemodel.py", line 206, in train_vae self.dataloader = data.DataLoader(self.dataset,batch_size= self.batch_size,shuffle= True,drop_last=True)#,num_workers = 4) File "/software/esc2rng/anaconda/envs/testenv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 176, in init sampler = RandomSampler(dataset) File "/software/esc2rng/anaconda/envs/testenv/lib/python3.6/site-packages/torch/utils/data/sampler.py", line 64, in init if not isinstance(self.num_samples, int) or self.num_samples <= 0: File "/software/esc2rng/anaconda/envs/testenv/lib/python3.6/site-packages/torch/utils/data/sampler.py", line 72, in num_samples return len(self.data_source) TypeError: object of type 'DATA_LOADER' has no len()

I've come across this error before, and I think it's related to the PyTorch version. PyTorch version 1 wasn't released yet when this code was written :) If you create a python virtual environment (conda or virtualenv) with Python 3.5.6 and the packages below it should work: torch==0.4.1 numpy==1.14.3 scipy==1.1.0 scikit_learn==0.20.3 networkx==1.11

Thank you! I have run the code successfully. Thanks for your reply!