Closed quark412 closed 1 year ago
Hi quark412,
sf.Heatmap
only works with tile-based models (models trained with Project.train()
). It does not work with MIL models.
MIL heatmaps are bit tricker for two reasons:
1) MIL models use feature bags (where features are generated from images using a feature generator / encoder). When generating a heatmap, should we require the user to pass in the calculated bags of features? Or should the user provide a feature generator / encoder, and the heatmap function would auto-generate features for each tile? There are advantages and disadvantages for each approach. 2) What is actually being displayed by the heatmap? For attention-based MIL models, it makes sense to display attention as the heatmap (which is what we do by default when training and validating MIL models). But, as you mention, what about MIL models that don't use attention? Should the interface support allowing the user to generate heatmaps using layer activations instead of attention, as you suggest?
These nuances are part of the reason why we don't yet have a unified interface for generating heatmaps from trained MIL models, although it is a high priority. We probably won't use the sf.Heatmap
interface that tile-based models use, since it's a fundamentally different technical approach that would utilize different configuration parameters.
When you are training/validating an MIL model with attention_heatmaps=True
, it uses a lower-level function sf.util.location_heatmap()
for rendering the attention heatmaps on a slide. If you need to create a custom heatmap for your applications before we have a chance to build the unified MIL heatmap interface, I would recommend building something from that function. This is the function that we will likely use under the hood for heatmap rendering regardless.
Sorry about the lack of clarity regarding the use of sf.Heatmap
and its restriction to tile-based models. I'll work on clarifying this in the documentation. I'm hoping MIL heatmaps will be available in the upcoming 2.1
release (ETA 1-2 months), although it may get pushed to 2.2
.
It seems like sf.Heatmap does not work with the clam_sb model, because it assumes the existence of a file called params.json, whereas in the case of MIL models the model directory contains a file called mil_params.json instead.
My stack trace is as follows:
This isn't too bad an issue, though, because I am able to successfully generate heatmaps by setting attention_heatmaps=True when training clam_sb.
As a separate question, how feasible would it be to make it possible for non-attention-based models such as mil_fc to generate heatmaps (based on their activations at a given layer, say)?