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"),
        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('.',
means = train_data.data.mean(axis = (0, 1, 2))/255
stds = train_data.data.std(axis=(0, 1, 2))/255

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

Any help input will be appreciated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.