Different forward outputs in different model
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):
-
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 -
some are logits (e.g., in files of model_MLPWSI.py and model_TMIL.py):
#---> get logits logits = self.to_logits(embedding) return logits -
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 ?
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