Num_samples should be a positive integer value, but got num_samples=0

Hello everybody, I am new to PyTorch. I have a problem when I tried to train my data. When I run my program there is an error like following:

Traceback (most recent call last):
File “/home/riza/Documents/D E F E C T D E T E C T I O N/code/GAN/WGAN.py”, line 140, in
dataloader = torch.utils.data.DataLoader(dataset, batch_size=opt.batch_size, shuffle=True, drop_last=True)
File “/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py”, line 176, in init
sampler = RandomSampler(dataset)
File “/usr/local/lib/python3.5/dist-packages/torch/utils/data/sampler.py”, line 66, in init
“value, but got num_samples={}”.format(self.num_samples))
ValueError: num_samples should be a positive integer value, but got num_samples=0

Please help me to solve the problem, Thank you

Could you post the definition of your Dataset?

import os
dirpath = os.getcwd()
print("current directory is : " + dirpath)
current directory is : /media/riza/EA62E27862E248C1/ubuntu_ppt/GAN_final/GAN/Defect/back/crack

That is I checked from my terminal, I directly open terminal from my dataset folder

What kind of Dataset are you using? Is it ImageFolder or a custom implementation?

custom implementation dataset. It is my own dataset

Could you check, what len(dataset) returns, as it’s apparently returning a length of 0.

1 Like

Sorry, I just fixed the problem. when I check len(dataset) the value is 0. Thank you for your help

1 Like

Ahmad how u fix it? Plzz help me

Brother what should we return to solve this error…plzz help

Make sure the __len__ method of your Dataset returns a valid number of samples (>0).
How are you passing (or loading) the data and how are you calculating the length of the Dataset?

Hello, sorry I just know your message, may I know your listing code?

Hello
I am having the same error
I am using an arabic dataset with utf-8 encoding
Can anyone help me plz ?