SurvPath icon indicating copy to clipboard operation
SurvPath copied to clipboard

Different forward outputs in different model

Open wuys13 opened this issue 1 year ago • 1 comments

Thank you for sharing this outstanding work! I notice in your code there are different outputs in different models (https://github.com/mahmoodlab/SurvPath/tree/3f73ddd6705ec67d643020c5bb04fb13f9f382cc/models):

  1. some are risks (e.g., in files of model_SurvPath.py and model_ABMIL.py):

     logits = self.to_logits(embedding)
    
     hazards = torch.sigmoid(logits)
     survival = torch.cumprod(1 - hazards, dim=1)
     risk = -torch.sum(survival, dim=1)
    
     return risk
    
  2. some are logits (e.g., in files of model_MLPWSI.py and model_TMIL.py):

     #---> get logits
     logits = self.to_logits(embedding)
    
     return logits
    
  3. even in some cases you comment out these codes (e.g., model_DeepMISL.py):

     logits  = self.classifier(h).unsqueeze(0) # logits needs to be a [1 x 4] vector 
     # Y_hat = torch.topk(logits, 1, dim = 1)[1]
     # hazards = torch.sigmoid(logits)
     # S = torch.cumprod(1 - hazards, dim=1)
    
     # return hazards, S, Y_hat, None, None
     return logits
    

I wonder this is a modified version for some tests, or you have included some data-processing codes elsewhere (however, I have checked Dataset and collate_fn part and do not find these processings). So is it true to directly use your bash scripts for the models using "logits" as output of forward ?

wuys13 avatar Jan 15 '25 10:01 wuys13

Apologies for the late reply. Short answer is: it depends. What are you trying to achieve? If you want risk scores, you need to transform the logits "S", using the code you copy-pasted:

 logits  = self.classifier(h).unsqueeze(0) # logits needs to be a [1 x 4] vector 
 Y_hat = torch.topk(logits, 1, dim = 1)[1]
 hazards = torch.sigmoid(logits)
 S = torch.cumprod(1 - hazards, dim=1)

Hope this helps

guillaumejaume avatar Feb 20 '25 21:02 guillaumejaume