From 7878f94f43fb761c5da2d4733c9c9d2526fc1287 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 16 Sep 2017 17:30:02 +0000 Subject: [PATCH] auto-increment loss filenames to stop clobbering --- onn_mnist.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/onn_mnist.py b/onn_mnist.py index 0815720..fa5712a 100755 --- a/onn_mnist.py +++ b/onn_mnist.py @@ -70,7 +70,7 @@ else: load_fn = None save_fn = 'mnist.h5' - log_fn = 'mnist_losses.npz' + log_fn = 'floss{}.npz' fn = 'mnist.npz' mnist_dim = 28 @@ -253,9 +253,16 @@ if save_fn is not None: model.save_weights(save_fn, overwrite=True) if log_fn: - log('saving losses', log_fn) kwargs = dict() for k, v in logs.items(): if len(v) > 0: kwargs[k] = np.array(v, dtype=_f) + if '{}' in log_fn: + from os.path import exists + for i in range(10000): + candidate = log_fn.format(i) + if not exists(candidate): + log_fn = candidate + break + log('saving losses', log_fn) np.savez_compressed(log_fn, **kwargs)