Hi all,
the latest weights for efficientnet are advprop trained and thus require a new normalization scheme for images.
Specifically (per luke melas impl):
ap_normalize = lambda img: img * 2.0 - 1.0
or:
if advprop: # for models using advprop pretrained weights
normalize = transforms.Lambda(lambda img: img * 2.0 - 1.0)
else:
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
Besides just hacking into data.py and adding a new normalize function…is there a better way to do this within fastai?
You can use no normalization and make it a transformation. Just make sure you set proper order for it to run either first or last, not sure what order should normalization be.
@muellerzr - if you can show how to do this with code, I’ll start moving my production work to v2 (I’m already close but will need this before I can make the jump). Either way, much appreciated!
for v1 I ended up just rewriting the main normalize functions in data.py (made an ap_normalize, etc) and it all appears to be working now.
I’ll take a look at the v2 code, thanks for posting the link!
For those who are interested, I managed to normalize for advprop for EfficientNet, following @muellerzr advice. I changed the Normalize transform a bit and created a NormalizeEf transform:
I’m not sure if I understood the reason to create a transforms.Lambda(). Also, you’re not broadcasting a tensor in this case, so no need of static method. Could you tell me what’s wrong in writing it this way?
@LessW2020 how to invoke this
data = (
src.transform(tfms,size=(sz,sz),resize_method=ResizeMethod.NO,padding_mode=‘zeros’)
.databunch(bs=bs)
.normalize1#(imagenet_stats)
)