|
23 | 23 | from monai.inferers import sliding_window_inference |
24 | 24 | from monai.networks.nets import DynUNet |
25 | 25 | from monai.optimizers.lr_scheduler import WarmupCosineSchedule |
| 26 | +from pytorch_lightning.utilities import rank_zero_only |
26 | 27 | from scipy.special import expit, softmax |
27 | 28 | from skimage.transform import resize |
28 | 29 | from utils.logger import DLLogger |
29 | | -from utils.utils import get_config_file, print0, rank_zero |
| 30 | +from utils.utils import get_config_file, print0 |
30 | 31 |
|
31 | 32 | from nnunet.loss import Loss, LossBraTS |
32 | 33 | from nnunet.metrics import Dice |
@@ -82,6 +83,8 @@ def training_step(self, batch, batch_idx): |
82 | 83 | return loss |
83 | 84 |
|
84 | 85 | def validation_step(self, batch, batch_idx): |
| 86 | + if self.current_epoch < self.args.skip_first_n_eval: |
| 87 | + return None |
85 | 88 | img, lbl = batch["image"], batch["label"] |
86 | 89 | pred = self._forward(img) |
87 | 90 | loss = self.loss(pred, lbl) |
@@ -205,6 +208,11 @@ def round(self, tensor): |
205 | 208 | return round(torch.mean(tensor).item(), 2) |
206 | 209 |
|
207 | 210 | def validation_epoch_end(self, outputs): |
| 211 | + if self.current_epoch < self.args.skip_first_n_eval: |
| 212 | + self.log("Dice", 0.001 * self.current_epoch) # To prevent early stopping |
| 213 | + self.dice.reset() |
| 214 | + return None |
| 215 | + |
208 | 216 | dice, loss = self.dice.compute() |
209 | 217 | self.dice.reset() |
210 | 218 |
|
@@ -233,7 +241,7 @@ def test_epoch_end(self, outputs): |
233 | 241 | if self.args.exec_mode == "evaluate": |
234 | 242 | self.eval_dice, _ = self.dice.compute() |
235 | 243 |
|
236 | | - @rank_zero |
| 244 | + @rank_zero_only |
237 | 245 | def on_fit_end(self): |
238 | 246 | if not self.args.benchmark: |
239 | 247 | metrics = {} |
|
0 commit comments