From e754d1075d8d0a5949e71f426ab07ce73be6099e Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 18 Jun 2017 08:28:12 +0200 Subject: [PATCH] Added a logger with ETA for the sample generation. --- cnn-svrt.py | 18 +++++++++++++++++- svrtset.py | 6 ++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cnn-svrt.py b/cnn-svrt.py index 58035d2..26e7de8 100755 --- a/cnn-svrt.py +++ b/cnn-svrt.py @@ -247,6 +247,21 @@ def int_to_suffix(n): else: return str(n) +class vignette_logger(): + def __init__(self, delay_min = 60): + self.start_t = time.time() + self.delay_min = delay_min + + def __call__(self, n, m): + t = time.time() + if t > self.start_t + self.delay_min: + dt = (t - self.start_t) / m + log_string('sample_generation {:d} / {:d}'.format( + m, + n), ' [ETA ' + time.ctime(time.time() + dt * (n - m)) + ']' + ) + self.start_t = t + ###################################################################### if args.nb_train_samples%args.batch_size > 0 or args.nb_test_samples%args.batch_size > 0: @@ -300,7 +315,8 @@ for problem_number in range(1, 24): train_set = VignetteSet(problem_number, args.nb_train_samples, args.batch_size, - cuda = torch.cuda.is_available()) + cuda = torch.cuda.is_available(), + logger = vignette_logger()) log_string('data_generation {:0.2f} samples / s'.format( train_set.nb_samples / (time.time() - t)) diff --git a/svrtset.py b/svrtset.py index cbc71a3..49f3279 100755 --- a/svrtset.py +++ b/svrtset.py @@ -41,7 +41,7 @@ def generate_one_batch(s): class VignetteSet: - def __init__(self, problem_number, nb_samples, batch_size, cuda = False): + def __init__(self, problem_number, nb_samples, batch_size, cuda = False, logger = None): if nb_samples%batch_size > 0: print('nb_samples must be a multiple of batch_size') @@ -61,6 +61,7 @@ class VignetteSet: self.data = [] for b in range(0, self.nb_batches): self.data.append(generate_one_batch(mp_args[b])) + if logger is not None: logger(self.nb_batches * self.batch_size, b * self.batch_size) # Weird thing going on with the multi-processing, waiting for more info @@ -88,7 +89,7 @@ class VignetteSet: ###################################################################### class CompressedVignetteSet: - def __init__(self, problem_number, nb_samples, batch_size, cuda = False): + def __init__(self, problem_number, nb_samples, batch_size, cuda = False, logger = None): if nb_samples%batch_size > 0: print('nb_samples must be a multiple of batch_size') @@ -111,6 +112,7 @@ class CompressedVignetteSet: acc_sq += input.float().pow(2).sum() / input.numel() self.targets.append(target) self.input_storages.append(svrt.compress(input.storage())) + if logger is not None: logger(self.nb_batches * self.batch_size, b * self.batch_size) self.mean = acc / self.nb_batches self.std = sqrt(acc_sq / self.nb_batches - self.mean * self.mean) -- 2.39.5