I had a similar problem.
This video will definitely help you understand how to write your own custom dataset class
How to build custom Datasets in Pytorch

Feel free to ask if you still don’t get it.
Regards!