EDSR-PyTorch: ValueError: num_samples should be a positive integer value, but got num_samples=0
RUNDIR: runs\seg_pascal\1980 Traceback (most recent call last): File "train.py", line 226, in <module> train(cfg, writer, logger) File "train.py", line 61, in train t_loader, batch_size=cfg["training"]["batch_size"], num_workers=cfg["training"]["n_workers"], shuffle=True File "C:\Users\yp\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 176, in __init__ sampler = RandomSampler(dataset) File "C:\Users\yp\Anaconda3\lib\site-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
How can I solve this problem?Thank you!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 22 (1 by maintainers)
You set the wrong path and model cannot find the training data to start training!
Hi, I checked the input data path and it was correct. But still i’m getting “ValueError: num_samples should be a positive integer value, but got num_samples=0”.
Could some one help or provide any work around.
The question means the number of train dataset is zero.Maybe you set wrong path, and you should check your code.
As @SonwYang said, the meaning of the error message is that the dataset has a size of 0. You can check that with
print(len(dataset)).In my case, it was not due to a wrong path, but to the fact that my code was creating a subset of the original dataset, larger than the original one. I had:
dataset = torch.utils.data.Subset(dataset, indices[:-50])while my dataset only comprised 30 elements. Setting a smaller subset solved the issue for me.
Hello.
You have to specify the exact location where your training data is.
You can use the
printfunction to see if you assigned a proper directory after this line.Ex)
Thank you.