binli123 / dsmil-wsi

DSMIL: Dual-stream multiple instance learning networks for tumor detection in Whole Slide Image
MIT License
332 stars 84 forks source link

How to set num_classes? #52

Closed ricardomokhtari closed 3 months ago

ricardomokhtari commented 1 year ago

Hi, thank you very much for sharing this code - I wanted to ask for some guidance on how to set the num_classes parameter.

I have a case where each bag has a label class X or class Y. When I set num_classes=2 some bags are predicted as [1, 1] or [0, 0] - these labels do not exist in my dataset (a bag cannot be both class X and Y or neither). So I think num_classes should be set to 1 such that predictions are either 0 or 1 - is that correct?

I am confused because the TCGA dataset is the same task - a bag is either LUAD or LUSC (it cannot be both or neither), yet in the code num_classes is set to 2? Why is this?

Thank you!

binli123 commented 1 year ago

https://github.com/binli123/dsmil-wsi#feature-vector-csv-files-explanation If you have a binary classification (true and false), it is regarded as 1 class. If you have two classes, and an optional negative class, it is regarded as 2 classes. TCGA has two classes + a negative class (benign region) that might exist in slides of both classes (although there is no slide that is completely benign). In this case, if the prediction is [0, 0], it is counted as a benign sample and you potentially have a false negative for both classes.

ricardomokhtari commented 1 year ago

Thank you very much for this answer :) I think I understand your explanation - so in the TCGA example is your thinking that, while there are no benign samples in the dataset, when presented with external data the model will be able to predict benign, whereas if 1 class is used the model will only ever be able to predict LUAD or LUSC? I guess this would still allow the model to predict 3 classes even though we don't have labels for 3 classes?

Also, since there are no [0,0] [1,1] labels in the dataset does this have a negative effect on reported performance?

yyyzzzhao commented 1 year ago

I think there is a viewpoint to help understand. The critical instances are class-specific, so that each class has a corresponding critical instance. In dsmil.py, the author applys 'torch.sort' operator along dimension 0, which sort the output score for each class. Then the MIL aggregator of DSMIL (Figure 3 in paper) is done for each class by matrix multiplication without loop.

Rainydu184 commented 1 year ago

So now I have a classification task with 4 instances, should I set num_class to 4?

Rainydu184 commented 1 year ago

So now I have a classification task with 4 instances, should I set num_class to 4?

it did.