vannynakamura commited on
Commit
7f8dcb3
·
1 Parent(s): 076780c

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +6 -2
model.py CHANGED
@@ -1,7 +1,8 @@
 
1
  import pytorch_lightning as pl
2
  import segmentation_models_pytorch as smp
3
  import torch
4
-
5
 
6
  class ModelRoiLeish(pl.LightningModule):
7
 
@@ -63,6 +64,7 @@ class ModelRoiLeish(pl.LightningModule):
63
  # first convert mask values to probabilities, then
64
  # apply thresholding
65
  prob_mask = logits_mask.sigmoid()
 
66
  pred_mask = (prob_mask > 0.5).float()
67
 
68
  # We will compute IoU metric by two ways
@@ -79,6 +81,7 @@ class ModelRoiLeish(pl.LightningModule):
79
  f"{stage}_fp": fp.to(torch.float32).mean(),
80
  f"{stage}_fn": fn.to(torch.float32).mean(),
81
  f"{stage}_tn": tn.to(torch.float32).mean(),
 
82
  }
83
 
84
  self.log_dict(loss_metrics, prog_bar=True)
@@ -135,4 +138,5 @@ class ModelRoiLeish(pl.LightningModule):
135
  return self.shared_epoch_end(outputs, "test")
136
 
137
  def configure_optimizers(self):
138
- return torch.optim.AdamW(self.parameters(), lr=self.lr)
 
 
1
+ ## MODEL.py
2
  import pytorch_lightning as pl
3
  import segmentation_models_pytorch as smp
4
  import torch
5
+ import torchmetrics
6
 
7
  class ModelRoiLeish(pl.LightningModule):
8
 
 
64
  # first convert mask values to probabilities, then
65
  # apply thresholding
66
  prob_mask = logits_mask.sigmoid()
67
+ iou_score = torchmetrics.functional.jaccard_index(prob_mask, mask.long())
68
  pred_mask = (prob_mask > 0.5).float()
69
 
70
  # We will compute IoU metric by two ways
 
81
  f"{stage}_fp": fp.to(torch.float32).mean(),
82
  f"{stage}_fn": fn.to(torch.float32).mean(),
83
  f"{stage}_tn": tn.to(torch.float32).mean(),
84
+ f"{stage}_jaccard": iou_score.to(torch.float32).mean()
85
  }
86
 
87
  self.log_dict(loss_metrics, prog_bar=True)
 
138
  return self.shared_epoch_end(outputs, "test")
139
 
140
  def configure_optimizers(self):
141
+ return torch.optim.AdamW(self.parameters(), lr=self.lr)
142
+