Skip to content

ValueError when using BalancedBatchSampler #71

@SergioQuijanoRey

Description

@SergioQuijanoRey

Hi! I am using your custom sampler for a project of mine. I am currently using MNIST dataset loaded from torchvision. When I use your sampler I got the following error:

ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.7/dist-packages/torchvision/datasets/mnist.py", line 127, in __getitem__
    img, target = self.data[index], int(self.targets[index])
ValueError: only one element tensors can be converted to Python scalars

I don't know what may be causing this error. Maybe different pytorch versions? I am currently using 1.10.0. Thanks in advance for your time 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions