def __call__(self, trainer): out = self._out if self._header: out.write(self._header) self._header = None log_report = self._log_report if isinstance(log_report, str): log_report = trainer.get_extension(log_report) elif isinstance(log_report, log_report_module.LogReport): log_report(trainer) # update the log report else: raise TypeError('log report has a wrong type %s' % type(log_report)) log = log_report.log log_len = self._log_len while len(log) > log_len: # delete the printed contents from the current cursor if os.name == 'nt': util.erase_console(0, 0) else: out.write('\033[J') self._print(log[log_len]) log_len += 1 self._log_len = log_len
def finalize(self): # delete the progress bar out = self._out if os.name == 'nt': util.erase_console(0, 0) else: out.write('\033[J') out.flush()
def __call__(self, trainer): # --- update entries --- log_report = self.get_log_report(trainer) log = log_report.log updated_flag = False aggregate_entries = log[self._log_len:] for obs in aggregate_entries: for entry in obs.keys(): if entry not in self._all_entries: self._all_entries.append(entry) updated_flag = True if updated_flag: if hasattr(log_report, '_trigger') and hasattr( log_report._trigger, 'unit'): unit = log_report._trigger.unit else: # Failed to infer `unit`, use epoch as default unit = 'epoch' entries = filter_and_sort_entries(self._all_entries, unit=unit) self._entries = entries header, templates = create_header_and_templates(entries) self._header = header # printed at the first call self._templates = templates out = self._out if self._header: out.write(self._header) self._header = None log_len = self._log_len while len(log) > log_len: # delete the printed contents from the current cursor if os.name == 'nt': util.erase_console(0, 0) else: out.write('\033[J') self._print(log[log_len]) log_len += 1 self._log_len = log_len
def __call__(self, trainer): if isinstance(self._out, str): self._out = open(os.path.join(trainer.out, self._out), 'w') out = self._out if self._header: out.write(self._header) out.flush() self._header = None log_report = self._log_report if isinstance(log_report, str): log_report = trainer.get_extension(log_report) elif not isinstance(log_report, log_report_module.LogReport): raise TypeError('log report has a wrong type %s' % type(log_report)) log = log_report.log log_len = self._log_len while len(log) > log_len: if out == sys.stdout: # delete the printed contents from the current cursor if os.name == 'nt': util.erase_console(0, 0) else: out.write('\033[J') self._print(log[log_len]) out.flush() log_len += 1 self._log_len = log_len
def __call__(self, trainer): training_length = self._training_length # initialize some attributes at the first call if training_length is None: t = trainer.stop_trigger training_length = t.get_training_length() stat_template = self._status_template if stat_template is None: stat_template = self._status_template = ( '{0.iteration:10} iter, {0.epoch} epoch / %s %ss\n' % training_length) length, unit = training_length out = self._out iteration = trainer.updater.iteration # print the progress bar if iteration % self._update_interval == 0: epoch = trainer.updater.epoch_detail recent_timing = self._recent_timing now = time.time() recent_timing.append((iteration, epoch, now)) if os.name == 'nt': util.erase_console(0, 0) else: out.write('\033[J') if unit == 'iteration': rate = iteration / length else: rate = epoch / length bar_length = self._bar_length marks = '#' * int(rate * bar_length) out.write(' total [{}{}] {:6.2%}\n'.format( marks, '.' * (bar_length - len(marks)), rate)) epoch_rate = epoch - int(epoch) marks = '#' * int(epoch_rate * bar_length) out.write('this epoch [{}{}] {:6.2%}\n'.format( marks, '.' * (bar_length - len(marks)), epoch_rate)) status = stat_template.format(trainer.updater) out.write(status) old_t, old_e, old_sec = recent_timing[0] span = now - old_sec if span != 0: speed_t = (iteration - old_t) / span speed_e = (epoch - old_e) / span else: speed_t = float('inf') speed_e = float('inf') if unit == 'iteration': estimated_time = (length - iteration) / speed_t else: estimated_time = (length - epoch) / speed_e out.write( '{:10.5g} iters/sec. Estimated time to finish: {}.\n'.format( speed_t, datetime.timedelta(seconds=estimated_time))) # move the cursor to the head of the progress bar if os.name == 'nt': util.set_console_cursor_position(0, -4) else: out.write('\033[4A') out.flush() if len(recent_timing) > 100: del recent_timing[0]
def __call__(self, trainer): training_length = self._training_length # initialize some attributes at the first call if training_length is None: t = trainer.stop_trigger if not isinstance(t, trigger.IntervalTrigger): raise TypeError( 'cannot retrieve the training length from %s' % type(t)) training_length = self._training_length = t.period, t.unit stat_template = self._status_template if stat_template is None: stat_template = self._status_template = ( '{0.iteration:10} iter, {0.epoch} epoch / %s %ss\n' % training_length) length, unit = training_length out = self._out iteration = trainer.updater.iteration # print the progress bar if iteration % self._update_interval == 0: epoch = trainer.updater.epoch_detail recent_timing = self._recent_timing now = time.time() recent_timing.append((iteration, epoch, now)) if os.name == 'nt': util.erase_console(0, 0) else: out.write('\033[J') if unit == 'iteration': rate = iteration / length else: rate = epoch / length bar_length = self._bar_length marks = '#' * int(rate * bar_length) out.write(' total [{}{}] {:6.2%}\n'.format( marks, '.' * (bar_length - len(marks)), rate)) epoch_rate = epoch - int(epoch) marks = '#' * int(epoch_rate * bar_length) out.write('this epoch [{}{}] {:6.2%}\n'.format( marks, '.' * (bar_length - len(marks)), epoch_rate)) status = stat_template.format(trainer.updater) out.write(status) old_t, old_e, old_sec = recent_timing[0] span = now - old_sec if span != 0: speed_t = (iteration - old_t) / span speed_e = (epoch - old_e) / span else: speed_t = float('inf') speed_e = float('inf') if unit == 'iteration': estimated_time = (length - iteration) / speed_t else: estimated_time = (length - epoch) / speed_e out.write('{:10.5g} iters/sec. Estimated time to finish: {}.\n' .format(speed_t, datetime.timedelta(seconds=estimated_time))) # move the cursor to the head of the progress bar if os.name == 'nt': util.set_console_cursor_position(0, -4) else: out.write('\033[4A') out.flush() if len(recent_timing) > 100: del recent_timing[0]