Hi, I am working on omniglot images and I am struggling with this error. I believe the problem is with my dataset generation. Please help me figure it out. Here is the dataset code:
import os
from PIL import Image
import numpy as np
from torch.utils.data import Dataset
import torch
from torchvision import datasets, transforms
class Dataset(Dataset):
def __init__(self,data_txt,transformm):
location_file = open(data_txt, 'r')
locations = location_file.read().split()
self.filenames = locations
self.labels = []
self.images = []
self.transform = transformm
self.path = os.getcwd()
for address in locations:
#label creation
label = address.split('/')[0]
self.labels.append(label)
def __len__(self):
return len(self.filenames)
def __getitem__(self, idx):
image = Image.open(os.path.join(self.path,'images_background', self.filenames[idx]))
image = self.transform(image)
return image, self.labels[idx]
Here is the full traceback
Traceback (most recent call last):
File “-/Documents/Code/AI/AI_Learning/Omniglot2/omniglot.py”, line 79, in
loss = crtieria(outputs, labels)
File “-AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py”, line 541, in call
result = self.forward(*input, **kwargs)
File “-\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\loss.py”, line 916, in forward
ignore_index=self.ignore_index, reduction=self.reduction)
File “-\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\functional.py”, line 2009, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File “-\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\functional.py”, line 1834, in nll_loss
if input.size(0) != target.size(0):
AttributeError: ‘tuple’ object has no attribute ‘size’