Fahad_Jahangir:

The code works just fine if I change the dataset.


What did you change regarding the dataset?
If the samples are smaller or you can preload the other dataset completely, it points to a data loading bottleneck using your current dataset.