Data loading error

Hi all!

Could anybody help me with this error?

obj = super().__new__(cls, *args, **kwds)

TypeError: object.new() takes exactly one argument (the type to instantiate)

This is the called class:

class DamageAndUndamageDataset(Dataset):
def init(self, csv_file, root_dir, transform=None):
self.annotations = pd.read_csv(csv_file)
self.root_dir = root_dir
self.transform = transform

def __len__(self):
    return len(self.annotations) #160

def __getitem__(self,index):
    img_path = os.path.join(self.root_dir, self.annotations.iloc[index,0])
    image = pd.read_csv(img_path)
    y_label = torch.tensor(int(self.annotations.iloc[index,1]))

    if self.transform:
        image = self.transform(image)
        
    return (image, y_label)

And here is where I call the class:

Load data

dataset = DamageAndUndamageDataset(csv_file= ‘labelsnormal’, root_dir = ‘datasetnormal’,
transform = transforms.ToTensor())

I can’t find any obvious issue in your code. Could you try to use some random tensors and post an executable code snippet, which would reproduce this issue, please?
Also, which PyTorch version are you using?

Hi! Yesterday night I restarted my laptop and then it worked. I don’t know what caused the issue. Sometimes IT techniques “turn it off then on again” really works :smiley: