def _log(self, state, prefix, predictions, targets): score, num, denom = cohen_kappa_score(predictions, targets, weights='quadratic') if self.class_names is None: class_names = [str(i) for i in range(num.shape[1])] else: class_names = self.class_names num_classes = len(class_names) num_fig = plot_matrix(num / np.sum(num), figsize=(6 + num_classes // 3, 6 + num_classes // 3), class_names=class_names, noshow=True) denom_fig = plot_matrix(denom / np.sum(denom), figsize=(6 + num_classes // 3, 6 + num_classes // 3), class_names=class_names, noshow=True) num_fig = render_figure_to_tensor(num_fig) denom_fig = render_figure_to_tensor(denom_fig) logger = get_tensorboard_logger(state) logger.add_image(f'{prefix}/epoch/num', num_fig, global_step=state.step) logger.add_image(f'{prefix}/epoch/denom', denom_fig, global_step=state.step) state.metrics.epoch_values[state.loader_name][prefix] = score
def on_loader_end(self, state): if self.class_names is None: class_names = [str(i) for i in range(self.num_classes)] else: class_names = self.class_names num_classes = len(class_names) cm = self.confusion_matrix.value() fig = plot_confusion_matrix( cm, figsize=(6 + num_classes // 3, 6 + num_classes // 3), class_names=class_names, normalize=True, noshow=True, ) fig = render_figure_to_tensor(fig) logger = get_tensorboard_logger(state) logger.add_image(f"{self.prefix}/epoch", fig, global_step=state.step)
def on_loader_end(self, state): targets = self.targets outputs = self.outputs if self.class_names is None: class_names = [str(i) for i in range(targets.shape[1])] else: class_names = self.class_names num_classes = len(class_names) cm = confusion_matrix(outputs, targets, labels=range(num_classes)) fig = plot_confusion_matrix(cm, class_names=class_names, normalize=True, noshow=True) fig = render_figure_to_tensor(fig) logger = _get_tensorboard_logger(state) logger.add_image(f'{self.prefix}/epoch', fig, global_step=state.step)