AttributeError: dataset object has no attribute 'c' FastAI
I am trying to train a ResNet based UNet for image segmentation. I have the location of images and mask images in a csv file, that's why I have created my own dataloader, which is as follows:

X = list(df['input_img'])
y = list(df['mask_img'])

X_train, X_valid, y_train, y_valid = train_test_split(
     X, y, test_size=0.33, random_state=42)

class NumbersDataset():
    def __init__(self, inputs, labels):
        self.X = inputs
        self.y = labels

    def __len__(self):
        return len(self.X)

    def __getitem__(self, idx):
        img_train = cv2.imread(self.X[idx])
        img_mask = cv2.imread(self.y[idx])
        img_train = cv2.resize(img_train, (427,240), interpolation = cv2.INTER_LANCZOS4) 
        img_mask = cv2.resize(img_mask, (427,240), interpolation = cv2.INTER_LANCZOS4) 
        return img_train, img_mask


I then call this datagenerator in the __main__ function:

if __name__ == '__main__':
    dataset_train = NumbersDataset(X_train, y_train)
    dataloader_train = DataLoader(dataset_train, batch_size=4, shuffle=True, num_workers=2)

    dataset_valid = NumbersDataset(X_valid, y_valid)
    dataloader_valid = DataLoader(dataset_valid, batch_size=4, shuffle=True, num_workers=2)

    datas = DataBunch(train_dl = dataloader_train, valid_dl = dataloader_valid)
    leaner = unet_learner(data = datas, arch = models.resnet34)


But I end up getting the following error:

Traceback (most recent call last):
  File "dataset_test.py", line 70, in &lt;module&gt;
    leaner = unet_learner(data = datas, arch = models.resnet34)
  File "/home/sarvagya/miniconda3/envs/gr/lib/python3.6/site-packages/fastai/vision/learner.py", line 118, in unet_learner
    model = to_device(models.unet.DynamicUnet(body, n_classes=data.c, img_size=size, blur=blur, blur_final=blur_final,
  File "/home/sarvagya/miniconda3/envs/gr/lib/python3.6/site-packages/fastai/basic_data.py", line 122, in __getattr__
    def __getattr__(self,k:int)-&gt;Any: return getattr(self.train_dl, k)
  File "/home/sarvagya/miniconda3/envs/gr/lib/python3.6/site-packages/fastai/basic_data.py", line 38, in __getattr__
    def __getattr__(self,k:str)-&gt;Any: return getattr(self.dl, k)
  File "/home/sarvagya/miniconda3/envs/gr/lib/python3.6/site-packages/fastai/basic_data.py", line 20, in DataLoader___getattr__
    def DataLoader___getattr__(dl, k:str)-&gt;Any: return getattr(dl.dataset, k)



  AttributeError: 'NumbersDataset' object has no attribute 'c'


I tried searching and even tried using SegmentationItemList.from_df but nothing helped. What am I getting wrong here?

You should add the attribute c into your NumbersDataset, like this:

def __init__(self, inputs, labels, c):
  self.inputs = inputs
  self.labels = labels
  self.c = c

