You can do is make dataloaders of same size i.e. adjusting the batch size such that both the dataloaders have same length.
For e.g. for 25000 images, you can make batch size as 25 and for 5000 images you can make batch size as 5 , so both the dataloaders will be having same length (1000)