There are some minor issues in your code:
- The error is thrown, since you are returning
self.lenin__len__, without defining it. You should rather return something likelen(self.image_list)(, which won’t currently work, but that’s the next point). - You are loading all images in
__init__without storingimage_list. Your__getitem__won’t be able to callself.image_listto open an image. However, even if you properly storedimage_listusingself.image_list = [], you are trying to open the image again. I would recommend to just store image paths in__init__and load the images in__getitem__. - Currently you are not using any target. It seems just the data is loaded without the segmentation masks.
-
Dataset.random_splitis not defined by default. You could split the image/mask paths and create two separateDatasets, one for training and another for validation.
Here is a small example I’ve written some time ago.
Let me know, if you can use it as a starter code and adapt it to your use case.