Fix double exp() of logit_scale in create_probabilities#197
Conversation
exp() of logit_scale in create_probabilities
|
@work4cs your change seems to lead to complete mis-prediction here (the test failure is in classifying the cat as a plant rather than a cat, not in the newly introduced unit test). Any idea why this is? |
Jianyang mentioned that And theoretically it should not make the ranking different, but numerically, it scales the image features before the matrix multiplication because In conclusion, we should not change the code and the original is actually correct. I will revert my update. |
|
Closing as per @work4cs's re-investigation. |
BaseClassifier.create_probabilities()was callingself.model.logit_scale.exp(), but the BioCLIP pretrained model storeslogit_scalealready as the scale (not its log), so this appliedexp()twice — producing inflated logits and over-confident (potentially overflowing) probabilities.Changes
src/bioclip/predict.py: Remove.exp()fromlogit_scaleincreate_probabilities():Mirrors the identical fix in Imageomics/bioclip#39.
tests/test_predict.py: AddTestCreateProbabilitieswith two unit tests — one asserting the corrected direct-scale behavior, and one confirming the double-exp()path produces a meaningfully different (wrong) result.