| 12 | |
| 13 | |
| 14 | class HTMLVisualizer(BaseHTMLHelper): |
| 15 | def __init__(self, opt): |
| 16 | |
| 17 | self.vis = HTMLTableVisualizer(visdir=os.path.join(opt.checkpoints_dir, opt.name, 'web'), |
| 18 | title=f"{opt.name}_{datetime.datetime.now().strftime('%Y_%m%d_%H%M_%S')}", |
| 19 | persist_row_counter=False) # rewritten each time so not persisting row counts |
| 20 | |
| 21 | # create a logging file to store training losses |
| 22 | os.makedirs(os.path.join(opt.checkpoints_dir, opt.name), exist_ok=True) |
| 23 | self.log_name = os.path.join(opt.checkpoints_dir, opt.name, 'loss_log.txt') |
| 24 | # with open(self.log_name, "a") as log_file: |
| 25 | # now = time.strftime("%c") |
| 26 | # log_file.write('================ Training Loss (%s) ================\n' % now) |
| 27 | |
| 28 | def reset(self): |
| 29 | """Reset the self.saved status""" |
| 30 | pass |
| 31 | |
| 32 | def display_current_results(self, layout: List[List[Dict[str, Any]]], epoch, iter): |
| 33 | """ |
| 34 | |
| 35 | Args: |
| 36 | layout: a *2D* list, each element is a dictionary with keys 'info' and 'image' |
| 37 | epoch: |
| 38 | iter: |
| 39 | |
| 40 | Returns: |
| 41 | |
| 42 | """ |
| 43 | with self.vis.html(): |
| 44 | # rewrite html page |
| 45 | # hard-code col_type for now |
| 46 | self.dump_table(self.vis, layout=layout, table_name=f"ep_{epoch}_it_{iter}", col_type='image') |
| 47 | self.print_url(self.vis) |
| 48 | |
| 49 | def plot_current_losses(self, epoch, counter_ratio, losses): |
| 50 | """display the current losses on visdom display: dictionary of error labels and values |
| 51 | |
| 52 | Parameters: |
| 53 | epoch (int) -- current epoch |
| 54 | counter_ratio (float) -- progress (percentage) in the current epoch, between 0 to 1 |
| 55 | losses (OrderedDict) -- training losses stored in the format of (name, float) pairs |
| 56 | """ |
| 57 | if not hasattr(self, 'plot_data'): |
| 58 | self.plot_data = {'X': [], 'Y': [], 'legend': list(losses.keys())} |
| 59 | self.plot_data['X'].append(epoch + counter_ratio) |
| 60 | self.plot_data['Y'].append([losses[k] for k in self.plot_data['legend']]) |
| 61 | try: |
| 62 | self.vis.line( |
| 63 | X=np.stack([np.array(self.plot_data['X'])] * len(self.plot_data['legend']), 1), |
| 64 | Y=np.array(self.plot_data['Y']), |
| 65 | opts={ |
| 66 | 'title': self.name + ' loss over time', |
| 67 | 'legend': self.plot_data['legend'], |
| 68 | 'xlabel': 'epoch', |
| 69 | 'ylabel': 'loss'}, |
| 70 | win=self.display_id) |
| 71 | except VisdomExceptionBase: |
nothing calls this directly
no outgoing calls
no test coverage detected