detecto icon indicating copy to clipboard operation
detecto copied to clipboard

To normalize or not to normalize

Open alankbi opened this issue 5 years ago • 3 comments

On the pre-trained model (without any finetuning or custom training), the accuracy is terrible if images passed into the model are normalized. This will probably require some investigation as to how to properly apply normalization to images, if you're supposed to at all.

The temporary workaround right now is to disable normalizing when just using the default weights.

alankbi avatar Jan 28 '20 20:01 alankbi

I think the torchvision FasterRCNN model already has normalization built in, unrelated to this, but my image Tensor was in the wrong format and I was getting errors in the following code while calling model.fit with detecto. It seems the model has normalization built in.

https://github.com/pytorch/vision/blob/883f1fb01a8ba0e1b1cdc16c16f2e6e0ef87e3bd/torchvision/models/detection/faster_rcnn.py#L227

https://github.com/pytorch/vision/blob/883f1fb01a8ba0e1b1cdc16c16f2e6e0ef87e3bd/torchvision/models/detection/transform.py#L120

Could this be causing this issue? Although wouldn't normalizing twice to the same values cause nothing to happen?

dereklukacs avatar Jun 10 '20 20:06 dereklukacs

Would you be able to provide more specifics about what your error is? As for the normalization, it does seem like there's some built-in normalization going on. With the default model, normalizing twice causes very poor results (which is why I have it disabled), but it looks about the same when using a custom-trained model.

alankbi avatar Jun 11 '20 02:06 alankbi

I don't have an error anymore, was just explaining how I stumbled on that code. Saw this open issue and wanted to make sure you were aware that the model has normalization built in.

dereklukacs avatar Jun 11 '20 02:06 dereklukacs