Thanks @ptrblck  it solves the problem.Any suggestions for optimizing the data flow since i am using the imagefolder first which already takes time followed by this reduction procedure of the dataset according to the threshold?