Exemplo n.º 1
0
    def online_accuracy(self):
        if self._get_current_predictions("train").size == 0:
            raise Exception(
                "You need to call add([prediction, label, task_id]) in order to compute an online accuracy "
                "(add([prediction, label, None]) also works here, task_id is not needed)."
            )
        predictions = self._get_current_predictions("train")
        targets = self._get_current_targets("train")

        return accuracy(predictions, targets)
Exemplo n.º 2
0
    def average_incremental_accuracy(self):
        """Computes the average of the accuracies computed after each task.

        Reference:
        * iCaRL: Incremental Classifier and Representation Learning
          Rebuffi et al. CVPR 2017
        """
        return statistics.mean([
            accuracy(self._predictions["test"][t], self._targets["test"][t])
            for t in range(len(self._predictions["test"]))
        ])
Exemplo n.º 3
0
    def online_cumulative_performance(self):
        """Computes the accuracy of last task on the train set.

        Reference:
        * Online Fast Adaptation and Knowledge Accumulation: a New Approach to Continual Learning
          Caccia et al. NeurIPS 2020
        """
        return accuracy(
            self._predictions["train"][-1],
            self._targets["train"][-1]
        )
Exemplo n.º 4
0
    def average_incremental_accuracy(self):
        """Computes the average of the accuracies computed after each task.

        Reference:
        * iCaRL: Incremental Classifier and Representation Learning
          Rebuffi et al. CVPR 2017
        """
        all_preds, all_targets, _ = self._get_best_epochs(subset="test")
        return statistics.mean([
            accuracy(all_preds[t], all_targets[t])
            for t in range(len(all_preds))
        ])
Exemplo n.º 5
0
    def online_accuracy(self):
        if len(self._batch_predictions) == 0:
            raise Exception(
                "You need to call <add_batch(preds, targets)> in order to get the online accuracy."
            )

        if len(self._batch_predictions) > 1:
            p, t = np.concatenate(self._batch_predictions), np.concatenate(self._batch_targets)
        else:
            p, t = self._batch_predictions[0], self._batch_targets[0]

        return accuracy(p, t)
Exemplo n.º 6
0
    def online_cumulative_performance(self):
        """Computes the accuracy of last task on the train set.

        Reference:
        * Online Fast Adaptation and Knowledge Accumulation: a New Approach to Continual Learning
          Caccia et al. NeurIPS 2020
        """
        preds = np.concatenate(
            [dict_epoch['predictions'] for dict_epoch in self.logger_dict["train"]["performance"][self.current_task]]
        )
        targets = np.concatenate(
            [dict_epoch['targets'] for dict_epoch in self.logger_dict["train"]["performance"][self.current_task]]
        )
        return accuracy(preds, targets)
Exemplo n.º 7
0
 def accuracy(self):
     return accuracy(self._get_current_predictions("test"),
                     self._get_current_targets("test"))
Exemplo n.º 8
0
 def accuracy(self):
     return accuracy(
         self._predictions["test"][-1],
         self._targets["test"][-1]
     )