run the len(self) func. after creating an instance of the class. The problem is that it is unable to get the size of your sample dataset. Calling it before the dataloader() provide it with that. There are many ways to initiate the len() function of the class, you can also use indexing or simply call len()