jamesdolezal / slideflow

Deep learning library for digital pathology, with both Tensorflow and PyTorch support.
https://slideflow.dev
GNU General Public License v3.0
234 stars 39 forks source link

An approach to consider multiple slides per patient with weak labels. #316

Closed lysukhin closed 8 months ago

lysukhin commented 10 months ago

Discussed in https://github.com/jamesdolezal/slideflow/discussions/311

Originally posted by **lysukhin** September 13, 2023 Hello, @jamesdolezal and contributors! First of all, let me thank you for this wonderful project that you develop and support. This work is really huge and important. I have a question on possible plans to enable the following: Usually, there is more than 1 histological slide per patient, but there's only 1 weak high-level label (e.g. malignant/benign) per patient. So the challenge is that not all of the patient's slides do actually provide meaningful information and features for this single label, like only 2 of 5 slides do really contain malignancy signals while the other 3 are actually 'clean'. Nevertheless, without additional annotations of each slide, this brings us to the same problem of noisy data as classical per-tile classification with weak labels. So I wonder if there are any plans on how to deal with it, maybe in some shape of adding one more aggregating 'MIL'-level on top of features for all patients slides? So the model can choose among all feature bags, not just a set of them from a single slide. Thanks for your attention and work, and looking forward to hear from you.
jamesdolezal commented 10 months ago

Thanks again for the suggestion - we can continue high-level discussion in #311. I've created the branch 316-mil-slide-aggregate, and I'll update this issue when a first-pass implementation is ready.

jamesdolezal commented 9 months ago

This feature has been implemented on the dev branch. You can now aggregate bags of features at the patient level, rather than the slide level, by setting the MIL parameter aggregation_level to "patient" (defaults to "slide"):

from slideflow.mil import mil_config

config = mil_config(..., aggregation_level='patient')

You can then train as usual. The saved predictions, slide manifest, and reported metrics will all reflect patient-level predictions rather than slide-level predictions.

Thanks again for the suggestion! And thanks to @matte-esse for the implementation. Let us know if you encounter any issues with this new feature or have other suggestions.

jamesdolezal commented 9 months ago

Actually going to reopen this for now until we can do more testing - looks like evaluation might not be working correctly.

lysukhin commented 9 months ago

Wonderful news, will certainly check this out in a few days. Thanks for the responsiveness and pace!

jamesdolezal commented 9 months ago

Ok - latest update on dev (c601f85) should have this patched. Training and evaluating an MIL model with aggregation_level="patient" should work as intended. Let me know if you encounter any issues! Otherwise, we'll fold this into the next 2.2 release.

lysukhin commented 9 months ago

Going to try this on custom data in a day or two, can post feedback here as an early access tester :)

jamesdolezal commented 8 months ago

This has now been released in version 2.2.0, going to close the issue out for now.

Thanks again for the suggestion! Let me know if there are any issues.