The use case in the original question was that instead of images in subfolders, .npy files were located in these subfolders.
Since ImageFolder only looks for image files, I suggested to use DatasetFolder with a custom loader.
However, your use case is different, since you have a single .npy file with apparently all images stored inside of it.
In that case, you should stick to @albanD’s solution and use TensorDataset(torch.from_numpy(np.load(path))).