fastai / fastai

The fastai deep learning library
http://docs.fast.ai
Apache License 2.0
26.23k stars 7.56k forks source link

Image from dls needs two denorms from imagenet_stats #3398

Closed Bunoviske closed 3 years ago

Bunoviske commented 3 years ago

In fastai version 2.3.0 and 2.3.1, I need to denorm (decode) the image two times so I can get the original one from learner.dls. In version 2.2.7 works fine. I also imagine what might happen during the training and get_preds. Maybe you are normalizing the image twice.

input, probabilities, groundTruth, decoded = learner.get_preds(dl=dl,  with_input=True, with_loss=False, with_decoded=True, act=F.softmax) 

rawImage = copy(input[0])

nrm = Normalize.from_stats(*imagenet_stats)
image = nrm.decode(rawImage) #fastai version 2.3.1 needs two denorms!!!! 
image = nrm.decode(image).clamp(0,1).squeeze().permute(1,2,0) # denorm image from imagenet stats
Bunoviske commented 3 years ago

First image: no denorm Second image: one denorm Third image: two denorms

noDenorm oneDenorm twoDenorms

riven314 commented 3 years ago

@Bunoviske Would you mind creating a minimal reproducible example in, lets say, a Colab notebook? I know there are some changes brought in fastai 2.3+ wrt adding normalization in validation set, which may be a cause for that. would be great if u have a notebook for me to verify that

muellerzr commented 3 years ago

Also: Try installing the dev version of fastai and fastcore and try again too just to verify it's still an issue:

pip install git+https://github.com/fastai/fastai
pip install git+https://github.com/fastai/fastcore
muellerzr commented 3 years ago

@Bunoviske looks like this was resolved in the latest version (2.4) :) cc @jph00

Bunoviske commented 3 years ago

Nice! Sorry, i did not have time to test it. Thanks