def _package_result(self,
                     strategy: "SupervisedTemplate") -> "MetricResult":
     self.steps.append(self.global_it_counter)
     task2label2count = self.labels_repartition.result()
     for task, label2count in task2label2count.items():
         for label, count in label2count.items():
             self.task2label2counts[task].setdefault(
                 label, [0] * (len(self.steps) - 2)).extend((count, count))
     for task, label2counts in self.task2label2counts.items():
         for label, counts in label2counts.items():
             counts.extend([0] * (len(self.steps) - len(counts)))
     return [
         MetricValue(
             self,
             name=f"Repartition"
             f"/{self._mode}_phase"
             f"/{stream_type(strategy.experience)}_stream"
             f"/Task_{task:03}",
             value=AlternativeValues(
                 self.image_creator(label2counts, self.steps),
                 label2counts,
             ) if self.image_creator is not None else label2counts,
             x_plot=strategy.clock.train_iterations,
         ) for task, label2counts in self.task2label2counts.items()
     ]
Esempio n. 2
0
    def _package_result(self, strategy: 'BaseStrategy') -> MetricResult:
        exp_cm = self.result()
        phase_name, _ = phase_and_task(strategy)
        stream = stream_type(strategy.experience)
        metric_name = '{}/{}_phase/{}_stream' \
            .format(str(self),
                    phase_name,
                    stream)
        plot_x_position = self.get_global_counter()

        if self._save_image:
            class_order = self._get_display_class_order(exp_cm, strategy)

            cm_image = self._image_creator(
                exp_cm[class_order][:, class_order],
                class_order
            )
            metric_representation = MetricValue(
                self, metric_name, AlternativeValues(cm_image, exp_cm),
                plot_x_position)
        else:
            metric_representation = MetricValue(
                self, metric_name, exp_cm, plot_x_position)

        return [metric_representation]
Esempio n. 3
0
    def _package_result(self, strategy: "BaseStrategy") -> "MetricResult":
        label_cat2mean_score: Dict[LabelCat, float] = self.result()

        for label_cat, m in label_cat2mean_score.items():
            self.label_cat2step2mean[label_cat][self.global_it_counter] = m

        base_metric_name = get_metric_name(
            self, strategy, add_experience=False, add_task=False
        )

        rv = [
            MetricValue(
                self,
                name=base_metric_name + f"/{label_cat}_classes",
                value=m,
                x_plot=self.global_it_counter,
            )
            for label_cat, m in label_cat2mean_score.items()
        ]
        if "old" in label_cat2mean_score and "new" in label_cat2mean_score:
            rv.append(
                MetricValue(
                    self,
                    name=base_metric_name + f"/new_old_diff",
                    value=label_cat2mean_score["new"]
                    - label_cat2mean_score["old"],
                    x_plot=self.global_it_counter,
                )
            )
        if self.image_creator is not None:
            rv.append(
                MetricValue(
                    self,
                    name=base_metric_name,
                    value=AlternativeValues(
                        self.image_creator(self.label_cat2step2mean),
                        self.label_cat2step2mean,
                    ),
                    x_plot=self.global_it_counter,
                )
            )

        return rv
Esempio n. 4
0
    def _package_result(self, strategy: 'BaseStrategy') -> MetricResult:
        exp_cm = self.result()
        phase_name, _ = phase_and_task(strategy)
        stream = stream_type(strategy.experience)
        metric_name = '{}/{}_phase/{}_stream' \
            .format(str(self),
                    phase_name,
                    stream)
        plot_x_position = self._next_x_position(metric_name)

        if self._save_image:
            cm_image = self._image_creator(exp_cm)
            metric_representation = MetricValue(
                self, metric_name, AlternativeValues(cm_image, exp_cm),
                plot_x_position)
        else:
            metric_representation = MetricValue(
                self, metric_name, exp_cm, plot_x_position)

        return [metric_representation]
Esempio n. 5
0
    def _package_result(self, strategy: 'BaseStrategy') -> MetricResult:
        outputs, targets = self.result()
        phase_name, _ = phase_and_task(strategy)
        stream = stream_type(strategy.experience)
        metric_name = '{}/{}_phase/{}_stream' \
            .format(str(self),
                    phase_name,
                    stream)
        plot_x_position = self.get_global_counter()

        # compute predicted classes
        preds = torch.argmax(outputs, dim=1).cpu().numpy()
        result = wandb.plot.confusion_matrix(preds=preds,
                                             y_true=targets.cpu().numpy(),
                                             class_names=self.class_names)

        metric_representation = MetricValue(
            self, metric_name, AlternativeValues(result),
            plot_x_position)

        return [metric_representation]