1

To use pre-trained models it is a preferred practice to normalize the input images with imagenet standards.

mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225].

How are these parameters derived?

Ethan
  • 1,657
  • 9
  • 25
  • 39
Wickkiey
  • 309
  • 3
  • 10

2 Answers2

1

These are calculated based on millions of images of ImageNet.

Ref - SO
Ref - MachinelearningMastery

10xAI
  • 5,929
  • 2
  • 9
  • 25
0

According to the Pytorch's docs, you can calculate mean and std using this:

import torch
from torchvision import datasets, transforms as T

transform = T.Compose([T.Resize(256), T.CenterCrop(224), T.ToTensor()]) dataset = datasets.ImageNet(".", split="train", transform=transform)

means = [] stds = [] for img in subset(dataset): means.append(torch.mean(img)) stds.append(torch.std(img))

mean = torch.mean(torch.tensor(means)) std = torch.mean(torch.tensor(stds))

David Le
  • 1
  • 1