# Pytorch torchvision: Efficient way of calculating the mean and stds for images in the train set from datasets.ImageFolder

Let us say I have the loading images from my local files using the pytorch torchvision datasets.ImageFolder as follows:

train_data = datasets.ImageFolder(
os.path.join(out_dir, "Training"),
transform=transforms.Compose([
transforms.Resize([224, 224]), # alenet image size
transforms.ToTensor() # so that we will be able to calculate mean and std
])
)


How can I efficiently calculate the means and stds for each color channel I know when loading dataset from torchvision.dataset I can do it as follows:

train_data = datasets.CIFAR10('.',
train=True,

My question is how can I calculate the means from the datasets.ImageFolder.