SBU-BMI / wsinfer

🔥 🚀 Blazingly fast pipeline for patch-based classification in whole slide images
https://wsinfer.readthedocs.io
Apache License 2.0
60 stars 10 forks source link

[ENH] consider adding test time augmentation #163

Open kaczmarj opened 1 year ago

kaczmarj commented 1 year ago

test time augmentation has the potential to improve model performance without any changes to the model parameters.

before implementing this, let's consider how best to implement it. i imagine the run_inference function can take a boolean argument tta or test_time_augmentation to enable this feature. if it is enabled, we would run the model on each patch multiple times (once for each transformation). the transformations must be rigid and must not rotate the images in non-90 degree increments.

transformations might include:

kaczmarj commented 1 year ago

@swaradgat19 - feel free to look into this as well.

kaczmarj commented 1 year ago

@swaradgat19 - i suggest starting small and trying to get tta (test time aug) working on a single patch. we can work on incorporating this into the codebase later on.

the pytorch dataset class we use to read patches is defined here: https://github.com/SBU-BMI/wsinfer/blob/8bdcaa45e6d25e1b6dd394d1cf9328dcc0863b85/wsinfer/modellib/data.py#L52

i don't think that class will work for tta as it is written currently. you can create a new one for your needs. we can work on incorporating it into the codebase later on.

here's how tta would work:

  1. read the patch
  2. create augmented views of this patch (right-angle rotations, flips, color augs)
  3. run all of the views (including original) through the model
  4. average the model outputs across all of the views
swaradgat19 commented 9 months ago

@kaczmarj Should I work on this feature? I am considering writing a separate script for transformations and then calling the function on each patch. What would you suggest?

kaczmarj commented 9 months ago

hi @swaradgat19 - sorry this fell through the cracks of my email! yes, it would be great if you could work on this feature. for debugging and developing, writing a separate script to run transformations makes sense.