inject_dropout_before_classifier¶

inject_dropout_before_classifier(model, p=0.2)[source]¶

Insert a nn.Dropout before the model’s linear classifier head.

Pretrained TIAToolbox patch classifiers (e.g. resnet18-kather100k, alexnet-kather100k) ship with no Dropout layers, which would make Monte Carlo Dropout a no-op. This injects a single nn.Dropout between the global-average-pool features and the linear classifier, the canonical placement for MC Dropout on a ResNet/AlexNet classifier.

Idempotent: if a nn.Dropout already immediately precedes the classifier it is left untouched.

Parameters:
Return type:

Module