Skip to content

Commit

Permalink
fix per-dataset timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jul 1, 2024
1 parent aed5cf8 commit 5875054
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion petric.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class MetricsWithTimeout(cbks.Callback):
def __init__(self, seconds=300, outdir=OUTDIR, transverse_slice=None, coronal_slice=None, reference_image=None,
verbose=1):
super().__init__(verbose)
self._seconds = seconds
self.callbacks = [
cbks.ProgressCallback(),
SaveIters(outdir=outdir),
Expand All @@ -106,8 +107,10 @@ def __init__(self, seconds=300, outdir=OUTDIR, transverse_slice=None, coronal_sl
reference_image, tb_cbk.tb, roi_mask_dict=roi_image_dict, metrics_dict={
'MSE': mean_squared_error, 'MAE': self.mean_absolute_error, 'PSNR': peak_signal_noise_ratio},
statistics_dict={'MEAN': np.mean, 'STDDEV': np.std, 'MAX': np.max}))
self.reset()

self.limit = time() + seconds
def reset(self, seconds=None):
self.limit = time() + (self._seconds if seconds is None else seconds)

def __call__(self, algorithm: Algorithm):
if (now := time()) > self.limit:
Expand Down Expand Up @@ -186,6 +189,7 @@ def get_data(srcdir=".", outdir=OUTDIR, sirf_verbosity=0):
from main import Submission, submission_callbacks
assert issubclass(Submission, Algorithm)
for data, metrics in data_metrics_pairs:
metrics[0].reset() # timeout from now
algo = Submission(data)
try:
algo.run(np.inf, callbacks=metrics + submission_callbacks)
Expand Down

0 comments on commit 5875054

Please sign in to comment.