pyronear / pyro-vision

Computer vision library for wildfire detection 🌲 Deep learning models in PyTorch & ONNX for inference on edge devices (e.g. Raspberry Pi)

Home Page:https://pyronear.org/pyro-vision/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider changing the image color normalization

KevinJMcEntee opened this issue · comments

Bug description

I wrote a short python script to try out the pyro-vision model. It can be found at https://github.com/KevinJMcEntee/WildfireDetector. It contains this image color normalization transform:

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])

These values were copied from the pyro-vision/README.md file. Further internet searches showed me these values are the mean and standard deviation values of the ImageNet image database.

Here is an image I ran through my script. It shows a wildfire I photographed with my iPhone a few summers ago.
Santa5FireResized

Here is that same image, transformed using the ImageNet values shown above. Notice the transform has left the smoke with a color closely matching the surrounding sky. The pyro-vision model predicted this image is negative for wildfire.
Santa5Fire_withImageNetNormalization

My manual visual inspection led to this insight. So, just for a baseline, I changed the transform to:
normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
This resulted in this normalized image:
Santa5Fire_withPoint5Normalization

Using this last image transform, pyro-vision predicted this image is positive for wildfire.

This investigation leads me to recommend developing a color transform that is specific to the wildfire smoke training set rather than using the general purpose ImageNet as the source of those values.

Code snippet to reproduce the bug

No Errors

Error traceback

No Errors

Environment

python3 on Macbook Air running MacOS 12.6. Using values from pyro-vision as of November 14, 2022. Script found at https://github.com/KevinJMcEntee/WildfireDetector/blob/main/cliWildFireDetect.py

Hi Kevin :)

Thanks a lot for reporting that here! I'll run some experiments with different normalization stats to see whether it helps!