0

[The dataset class][1]The transforms applied to the imageUnable to access the pytorch dataloader values for use TypeError: default_collate: batch must contain tensors, NumPy arrays, numbers, dicts, or lists; found object

The error can be reproduced by running https://jovian.ml/pravin-bnmit/cxr/ on Kaggle enter image description here

  • I guess it would be beneficial if you share more of the code. it is really hard to guess what the problem is. My guess is that the image is not being converted to tensor (info: https://pytorch.org/docs/stable/torchvision/transforms.html) – Victor Zuanazzi Jul 15 '20 at 14:11
  • I have added the code and the notebook is available at https://jovian.ml/pravin-bnmit/cxr/ – Nemaly Praveen Jul 15 '20 at 14:22
  • the erros in the notebook and in the image you shared here are different. did ToTensor solve your problem? (dataloaders are not subscriptiable, you can do `next(dl)` to load the next batch or simply `for data in dl: do something with data`) – Victor Zuanazzi Jul 15 '20 at 14:30
  • @VictorZuanazzi The error is with the for loop when I try to access the data from dl That is giving the error shown above You can check the notebook I have updated it – Nemaly Praveen Jul 15 '20 at 14:36

1 Answers1

0

Why don't you try img = img.resize((1024, 1024)) before the transformation inside the getitem() method?

def __getitem__(self, idx):
    row = self.df.loc[idx]
    img_id, img_label = row['Image Index'], row['disease_vec']
    img_fname = row['path']
    img = Image.open(img_fname)
    img = img.resize((1024, 1024))
    if self.transform:
        img = self.transform(img)
    return img, img_label
planet_pluto
  • 742
  • 4
  • 15
  • The problem is that it returns a tuple when exiting from the dataset class. which is an object and the for loop wants to access the 2 tensors which it is not able to causing the error – Nemaly Praveen Jul 16 '20 at 06:20