airctic / mantisshrimp_streamlit

Streamlit demo for mantisshrimp object detection framework
Apache License 2.0
5 stars 1 forks source link

Image should be first transformed and only then used for the prediction #3

Open tugot17 opened 4 years ago

tugot17 commented 4 years ago

Describe the bug Before conducting the prediction the image should be Resized to the original training size and then Normalized the data comes from the same distribution as training data

To Reproduce In app.py go to the line 223

eval_ds = Dataset.from_images([image])
batch, samples = faster_rcnn.build_infer_batch(eval_ds)
preds = faster_rcnn.predict(
        model=model, batch=batch, detection_threshold=confidence_threshold)

How to fix

Add the transformation while creating the dataset

transformations = tfms.A.Adapter([tfms.A.Resize(384, 384), tfms.A.Normalize()])
eval_ds = Dataset.from_images([image], transformations)
batch, samples = faster_rcnn.build_infer_batch(eval_ds)
preds = faster_rcnn.predict(
model=model, batch=batch, detection_threshold=confidence_threshold)
oke-aditya commented 4 years ago

Yes, we can add these Test Time Transforms too. Thought it should work fine without these. Since Faster RCNN uses Generalized RCNN transforms that works for image of any size.

Can you open a PR as well @tugot17 ? If not possible, don't worry I will fix it up.

tugot17 commented 4 years ago

I think the "domain" for not Normalized images is different and it may cause the predictor to not work properly. I opened the PR #4

oke-aditya commented 4 years ago

Can cause error, though it hasn't caused yet. But defensive programming is better.