How do we retrieve the mean and std vectors for normalization associated with pre-trained models?
I realize that fastai applies the normalization for training and inference automatically, but if I export the model (eg, to iOS), I need to apply the normalization manually to the data prior to feeding it to the model for inference. Do all pre-trained models use the imagenet normalization vectors? How about pre-trained models provided by
Most use imagenet stats, but not all. You’ll find
learner.normalization contains the callback object, and the stats will be in there.
Thank you. I must be doing something wrong. I get this:
AttributeError: 'XResNet' object has no attribute 'normalization'
from fastai.vision.all import *
path = untar_data(URLs.IMAGENETTE)
dblock = DataBlock(blocks=(ImageBlock(), CategoryBlock()),
dls = dblock.dataloaders(path, bs=64)
learn = Learner(dls, model, loss_func=CrossEntropyLossFlat(), metrics=accuracy)
Ah that’s because you didn’t use
vision_learner, so you didn’t get normalization added automatically.