1+ import statistics
2+
13import numpy as np
24
35from continuum .metrics .base_logger import _BaseLogger
@@ -37,7 +39,7 @@ def _get_best_epochs_perf(self, subset):
3739 last_epoch_pred = []
3840 last_epoch_targets = []
3941 last_epoch_task_ids = []
40- for task_id in range (self .current_task ):
42+ for task_id in range (len ( self .logger_dict [ subset ][ "performance" ]) ):
4143 predictions = self .logger_dict [subset ]["performance" ][task_id ][- 1 ]["predictions" ]
4244 targets = self .logger_dict [subset ]["performance" ][task_id ][- 1 ]["targets" ]
4345 task_id = self .logger_dict [subset ]["performance" ][task_id ][- 1 ]["task_ids" ]
@@ -48,20 +50,15 @@ def _get_best_epochs_perf(self, subset):
4850
4951 return last_epoch_pred , last_epoch_targets , last_epoch_task_ids
5052
51-
5253 def _get_best_epochs_data (self , keyword , subset ):
53-
5454 assert keyword != "performance" , f"this method is not mode for performance keyword use _get_best_epochs_perf"
5555 list_values = []
5656 for task_id in range (self .current_task ):
5757 list_values .append (self .logger_dict [subset ][keyword ][task_id ][- 1 ])
5858 return list_values
5959
60-
61-
6260 def _get_best_epochs (self , keyword = "performance" , subset = "train" ):
63-
64- if keyword == "performance" :
61+ if keyword == "performance" :
6562 values = self ._get_best_epochs_perf (subset )
6663 else :
6764 values = self ._get_best_epochs_data (keyword , subset )
@@ -84,7 +81,6 @@ def online_accuracy(self):
8481 return accuracy (predictions , targets )
8582
8683 @property
87- @cache
8884 @require_subset ("test" )
8985 def accuracy (self ):
9086 return accuracy (
@@ -93,7 +89,6 @@ def accuracy(self):
9389 )
9490
9591 @property
96- @cache
9792 @require_subset ("test" )
9893 def accuracy_per_task (self ):
9994 """Returns all task accuracy individually."""
@@ -104,7 +99,6 @@ def accuracy_per_task(self):
10499 ]
105100
106101 @property
107- @cache
108102 @require_subset ("train" )
109103 def online_cumulative_performance (self ):
110104 """Computes the accuracy of last task on the train set.
@@ -122,7 +116,6 @@ def online_cumulative_performance(self):
122116 return accuracy (preds , targets )
123117
124118 @property
125- @cache
126119 @require_subset ("test" )
127120 def average_incremental_accuracy (self ):
128121 """Computes the average of the accuracies computed after each task.
@@ -132,56 +125,48 @@ def average_incremental_accuracy(self):
132125 Rebuffi et al. CVPR 2017
133126 """
134127 all_preds , all_targets , _ = self ._get_best_epochs (subset = "test" )
135-
136128 return statistics .mean ([
137129 accuracy (all_preds [t ], all_targets [t ])
138130 for t in range (len (all_preds ))
139131 ])
140132
141133 @property
142- @cache
143134 @require_subset ("test" )
144135 def backward_transfer (self ):
145136 all_preds , all_targets , task_ids = self ._get_best_epochs (subset = "test" )
146137 return backward_transfer (all_preds , all_targets , task_ids )
147138
148139 @property
149- @cache
150140 @require_subset ("test" )
151141 def forward_transfer (self ):
152142 all_preds , all_targets , task_ids = self ._get_best_epochs (subset = "test" )
153143 return forward_transfer (all_preds , all_targets , task_ids )
154144
155145 @property
156- @cache
157146 @require_subset ("test" )
158147 def positive_backward_transfer (self ):
159148 all_preds , all_targets , task_ids = self ._get_best_epochs (subset = "test" )
160149 return positive_backward_transfer (all_preds , all_targets , task_ids )
161150
162151 @property
163- @cache
164152 @require_subset ("test" )
165153 def remembering (self ):
166154 all_preds , all_targets , task_ids = self ._get_best_epochs (subset = "test" )
167155 return remembering (all_preds , all_targets , task_ids )
168156
169157 @property
170- @cache
171158 @require_subset ("test" )
172159 def accuracy_A (self ):
173160 all_preds , all_targets , task_ids = self ._get_best_epochs (subset = "test" )
174161 return accuracy_A (all_preds , all_targets , task_ids )
175162
176163 @property
177- @cache
178164 @require_subset ("test" )
179165 def forgetting (self ):
180166 all_preds , all_targets , task_ids = self ._get_best_epochs (subset = "test" )
181167 return forgetting (all_preds , all_targets , task_ids )
182168
183169 @property
184- @cache
185170 def model_size_growth (self ):
186171 assert "model_size" in self .list_keywords
187172 sizes = self ._get_best_epochs ("model_size" )
0 commit comments