bgraysea
(Brent)
March 29, 2021, 10:04am
1
I’m exploring the code around the progress updates that are displayed whilst running learn.fit
Does ProgressCallback
also generate the table which I highlighted in the screen shot?
I can’t track down the code which is appending a new row to the table after each epoch; could someone point me in the right direction?
When I add metrics=accuracy
to the learner; a new column appears in the table - could someone point me to the code that is looking for available metrics and then displaying it as the table is being generated?
Thanks
I was able to dig through the code and I think this is what you are looking for:
def _launch_pbar(self): self.pbar = progress_bar(self.dl, parent=getattr(self, 'mbar', None), leave=False) self.pbar.update(0) def after_fit(self): if getattr(self, 'mbar', False): self.mbar.on_iter_end() delattr(self, 'mbar') if hasattr(self, 'old_logger'): self.learn.logger = self.old_logger def _write_stats(self, log): if getattr(self, 'mbar', False): self.mbar.write([f'{l:.6f}' if isinstance(l, float) else str(l) for l in log], table=True) _docs = dict(before_fit="Setup the master bar over the epochs", before_epoch="Update the master bar", before_train="Launch a progress bar over the training dataloader", before_validate="Launch a progress bar over the validation dataloader", after_train="Close the progress bar over the training dataloader", after_validate="Close the progress bar over the validation dataloader", after_batch="Update the current progress bar", after_fit="Close the master bar")
The metrics are added here:
def before_epoch(self): "Set timer if `self.add_time=True`" self.cancel_train,self.cancel_valid = False,False if self.add_time: self.start_epoch = time.time() self.log = L(getattr(self, 'epoch', 0)) def before_train (self): self._train_mets[1:].map(Self.reset()) def before_validate(self): self._valid_mets.map(Self.reset()) def after_train (self): self.log += self._train_mets.map(_maybe_item) def after_validate(self): self.log += self._valid_mets.map(_maybe_item) def after_cancel_train(self): self.cancel_train = True def after_cancel_validate(self): self.cancel_valid = True def after_epoch(self): "Store and log the loss/metric values" self.learn.final_record = self.log[1:].copy() self.values.append(self.learn.final_record) if self.add_time: self.log.append(format_time(time.time() - self.start_epoch)) self.logger(self.log) self.iters.append(self.smooth_loss.count)
1 Like
bgraysea
(Brent)
April 1, 2021, 9:42am
3
Thank you; I miiight have to post some follow up q’z around getting into the details of how these Callbacks interact; but definitely very helpful pointers in the right direction; much appreciated.
1 Like