Skip to content

Commit

Permalink
Merge pull request ContinualAI#1458 from AlbinSou/fix_ncm
Browse files Browse the repository at this point in the history
turn ncm to dynamic module that adapts with 0 vectors at evaluation
  • Loading branch information
AntonioCarta authored Jul 14, 2023
2 parents 2b7fa26 + 3fdf464 commit 435b40d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion avalanche/models/ncm_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import torch
from torch import Tensor, nn

from avalanche.models import DynamicModule

class NCMClassifier(nn.Module):

class NCMClassifier(DynamicModule):
"""
NCM Classifier.
NCMClassifier performs nearest class mean classification
Expand Down Expand Up @@ -122,5 +124,15 @@ def replace_class_means_dict(self, class_means_dict: Dict[int, Tensor]):

self._vectorize_means_dict()

def eval_adaptation(self, experience):
if self.class_means is None:
return
for k in experience.classes_in_this_experience:
if k not in self.class_means_dict:
self.class_means_dict[k] = torch.zeros(self.class_means.shape[1]).to(
self.class_means.device
)
self._vectorize_means_dict()


__all__ = ["NCMClassifier"]

0 comments on commit 435b40d

Please sign in to comment.