0
$\begingroup$

I made a torchvision.datasets dataloader for torchvision.datasets.SBDataset :

sbd_data = torchvision.datasets.SBDataset('./',transforms = data_transforms['train'],download=False)
data_loader = torch.utils.data.DataLoader(sbd_data,
                                          batch_size=4,
                                          shuffle=True,
                                          num_workers=4)

Here the data_transforms['train'] is a transforms.Compose instance. And to show a batch i used this function :

def imshow(inp, title=None):
    """Imshow for Tensor."""
    inp = inp.numpy().transpose((1, 2, 0))
    inp = np.clip(inp, 0, 1)
    plt.imshow(inp)
    if title is not None:
        plt.title(title)
    plt.pause(0.001)  # pause a bit so that plots are updated

Now when i try to call this function as

inputs,_ = next(iter(data_loader))
out = torchvision.utils.make_grid(inputs)
imshow(out)

I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-6753e8965891> in <module>
     13 
     14 # Get a batch of training data
---> 15 inputs,_ = next(iter(data_loader))
     16 # Make a grid from batch

/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in __next__(self)
    817             else:
    818                 del self.task_info[idx]
--> 819                 return self._process_data(data)
    820 
    821     next = __next__  # Python 2 compatibility

/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in _process_data(self, data)
    844         self._try_put_index()
    845         if isinstance(data, ExceptionWrapper):
--> 846             data.reraise()
    847         return data
    848 

/usr/local/lib/python3.6/dist-packages/torch/_utils.py in reraise(self)
    367             # (https://bugs.python.org/issue2651), so we work around it.
    368             msg = KeyErrorMessage(msg)
--> 369         raise self.exc_type(msg)

TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/torchvision/datasets/sbd.py", line 115, in __getitem__
    img, target = self.transforms(img, target)
TypeError: __call__() takes 2 positional arguments but 3 were given

I read the sbd.py for SBDataset class which inherits from VisionDataset which clearly implements a StandardTransform class, which is only used when inputs transform and target_transform are both provided, does it assume the transforms to be an instance of StandardTransform? Is this intentional? Is there a neat way to solve this? because the StandardTransform is not present in the docs. Note the transform and transforms difference. The transform.Compose class clearly doesn't support two inputs ie inputs , targets.

I could have just worked with transform but this class(SBDataset) only has transforms as an argument.

pytorch version : 1.2.0.dev20190805 Torchvision Version: 0.4.0a0+d31eafa Python version : 3.6

$\endgroup$
  • $\begingroup$ The now-closed issue for this problem can be found here $\endgroup$ – Rorschach May 17 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.