Databunch concept

In the databunch class below we pass in the standard dataloader object.
My question is from where does the dataloader gets the dataset

class DataBunch():
    def __init__(self, train_dl, valid_dl, c=None):
        self.train_dl,self.valid_dl,self.c = train_dl,valid_dl,c

    def train_ds(self): return self.train_dl.dataset # it contains dataset class combining dataloader and dataset

    def valid_ds(self): return self.valid_dl.dataset
  1. I defined a new method into the Dataset call x_size,y_size to directly get the size using class object
    I can get the size out from this
    class Dataset():
    def init(self, x, y): self.x,self.y = x,y
    def len(self):
    return len(self.x)

     def size_x(self):
       return self.x.size()
     def size_y(self):
       return self.y.size()
     def __getitem__(self, i): 
       return self.x[i],self.y[i]

but when i invoke it using dataloader object i get an error saying dataset has not attribute size_x
x_train_dl.dataset.x_size # this gives an error saying dataset has no attribute size_X

  1. The dataloader gets the self.train_dl.dataset through the init from the train_dl:
  1. My guess would be that self.x is a list and does not have size attribute. You can check the type of self.x (type(self.x)) or if len(self.x) does work in this case?

i checked the type for train_ds which _main.dataset
and x_train_dl.dataset which is also same…
I dont understand why the second one is not able to access property of Dataset class.

This object has no size attribute, see the 03_minibatch_training.ipynb notebook:

 class Dataset():
     def __init__(self, x, y): self.x,self.y = x,y
     def __len__(self): return len(self.x)
     def __getitem__(self, i): return self.x[i],self.y[i]

I’m not sure if a size attribute makes sense?

i defined my own inside it for building some understanding .
It is very well accessible from my own custom Dataset class inside which i defined it as property , when I invoke directly through the train_Ds
but when i use Dl.ds. it dsnt finds the method…
even though in both the case class type is same only.