class_docstr: Supervised Contrastive Replay from https://arxiv.org/pdf/2103.13885.pdf.
  This strategy trains an encoder network in a self-supervised manner to
  cluster together examples of the same class while pushing away examples
  of different classes. It uses the Nearest Class Mean classifier on the
  embeddings produced by the encoder.
  
  Accuracy cannot be monitored during training (no NCM classifier).
  During training, NCRLoss is monitored, while during eval
  CrossEntropyLoss is monitored.
  
  The original paper uses an additional fine-tuning phase on the buffer
  at the end of each experience (called review trick, but not mentioned
  in the paper). This implementation does not implement the review trick.
class_docstr_tok: ["Supervised","Contrastive","Replay","from","https",":","\/\/arxiv.org\/pdf\/2103.13885.pdf",".","This","strategy","trains","an","encoder","network","in","a","self-supervised","manner","to","cluster","together","examples","of","the","same","class","while","pushing","away","examples","of","different","classes",".","It","uses","the","Nearest","Class","Mean","classifier","on","the","embeddings","produced","by","the","encoder",".","Accuracy","can","not","be","monitored","during","training","(","no","NCM","classifier",")",".","During","training",",","NCRLoss","is","monitored",",","while","during","eval","CrossEntropyLoss","is","monitored",".","The","original","paper","uses","an","additional","fine-tuning","phase","on","the","buffer","at","the","end","of","each","experience","(","called","review","trick",",","but","not","mentioned","in","the","paper",")",".","This","implementation","does","not","implement","the","review","trick","."]
docstr: :param model: an Avalanche model like the avalanche.models.SCRModel,
      where the train classifier uses a projection network (e.g., MLP)
      while the test classifier uses a NCM Classifier.
      Normalization should be applied between feature extractor
      and classifier.
  :param optimizer: PyTorch optimizer.
  :param augmentations: TorchVision Compose Transformations to augment
      the input minibatch. The augmented mini-batch will be concatenated
      to the original one (which includes the memory buffer).
      Note: only augmentations that can be applied to Tensors
      are supported.
  :param mem_size: replay memory size, used also at test time to
      compute class means.
  :param temperature: SCR Loss temperature.
  :param train_mb_size: mini-batch size for training. The default
      dataloader is a task-balanced dataloader that divides each
      mini-batch evenly between samples from all existing tasks in
      the dataset.
  :param batch_size_mem: number of examples drawn from the buffer.
  :param train_epochs: number of training epochs.
  :param eval_mb_size: mini-batch size for eval.
  :param device: PyTorch device where the model will be allocated.
  :param plugins: (optional) list of StrategyPlugins.
  :param evaluator: (optional) instance of EvaluationPlugin for logging
      and metric computations. None to remove logging.
  :param eval_every: the frequency of the calls to `eval` inside the
      training loop. -1 disables the evaluation. 0 means `eval` is called
      only at the end of the learning experience. Values >0 mean that
      `eval` is called every `eval_every` epochs and at the end of the
      learning experience.
  :param peval_mode: one of {'epoch', 'iteration'}. Decides whether the
      periodic evaluation during training should execute every
      `eval_every` epochs or iterations (Default='epoch').
docstr_tok: [":","param","model",":","an","Avalanche","model","like","the","avalanche.models.SCRModel",",","where","the","train","classifier","uses","a","projection","network","(","e.g.",",","MLP",")","while","the","test","classifier","uses","a","NCM","Classifier",".","Normalization","should","be","applied","between","feature","extractor","and","classifier",".",":","param","optimizer",":","PyTorch","optimizer",".",":","param","augmentations",":","TorchVision","Compose","Transformations","to","augment","the","input","minibatch",".","The","augmented","mini-batch","will","be","concatenated","to","the","original","one","(","which","includes","the","memory","buffer",")",".","Note",":","only","augmentations","that","can","be","applied","to","Tensors","are","supported",".",":","param","mem_size",":","replay","memory","size",",","used","also","at","test","time","to","compute","class","means",".",":","param","temperature",":","SCR","Loss","temperature",".",":","param","train_mb_size",":","mini-batch","size","for","training",".","The","default","dataloader","is","a","task-balanced","dataloader","that","divides","each","mini-batch","evenly","between","samples","from","all","existing","tasks","in","the","dataset",".",":","param","batch_size_mem",":","number","of","examples","drawn","from","the","buffer",".",":","param","train_epochs",":","number","of","training","epochs",".",":","param","eval_mb_size",":","mini-batch","size","for","eval",".",":","param","device",":","PyTorch","device","where","the","model","will","be","allocated",".",":","param","plugins",":","(","optional",")","list","of","StrategyPlugins",".",":","param","evaluator",":","(","optional",")","instance","of","EvaluationPlugin","for","logging","and","metric","computations",".","None","to","remove","logging",".",":","param","eval_every",":","the","frequency","of","the","calls","to","`","eval","`","inside","the","training","loop",".","-1","disables","the","evaluation",".","0","means","`","eval","`","is","called","only","at","the","end","of","the","learning","experience",".","Values",">","0","mean","that","`","eval","`","is","called","every","`","eval_every","`","epochs","and","at","the","end","of","the","learning","experience",".",":","param","peval_mode",":","one","of","{","'epoch","'",",","'iteration","'","}",".","Decides","whether","the","periodic","evaluation","during","training","should","execute","every","`","eval_every","`","epochs","or","iterations","(","Default='epoch","'",")","."]
code: def __init__(
      self,
      model: SCRModel,
      optimizer: Optimizer,
      augmentations=Compose([Lambda(lambda el: el)]),
      mem_size: int = 100,
      temperature: int = 0.1,
      train_mb_size: int = 1,
      batch_size_mem: int = 100,
      train_epochs: int = 1,
      eval_mb_size: Optional[int] = 1,
      device="cpu",
      plugins: Optional[Sequence["BaseSGDPlugin"]] = None,
      evaluator=default_evaluator,
      eval_every=-1,
      peval_mode="epoch",
  ):
      """
      :param model: an Avalanche model like the avalanche.models.SCRModel,
          where the train classifier uses a projection network (e.g., MLP)
          while the test classifier uses a NCM Classifier.
          Normalization should be applied between feature extractor
          and classifier.
      :param optimizer: PyTorch optimizer.
      :param augmentations: TorchVision Compose Transformations to augment
          the input minibatch. The augmented mini-batch will be concatenated
          to the original one (which includes the memory buffer).
          Note: only augmentations that can be applied to Tensors
          are supported.
      :param mem_size: replay memory size, used also at test time to
          compute class means.
      :param temperature: SCR Loss temperature.
      :param train_mb_size: mini-batch size for training. The default
          dataloader is a task-balanced dataloader that divides each
          mini-batch evenly between samples from all existing tasks in
          the dataset.
      :param batch_size_mem: number of examples drawn from the buffer.
      :param train_epochs: number of training epochs.
      :param eval_mb_size: mini-batch size for eval.
      :param device: PyTorch device where the model will be allocated.
      :param plugins: (optional) list of StrategyPlugins.
      :param evaluator: (optional) instance of EvaluationPlugin for logging
          and metric computations. None to remove logging.
      :param eval_every: the frequency of the calls to `eval` inside the
          training loop. -1 disables the evaluation. 0 means `eval` is called
          only at the end of the learning experience. Values >0 mean that
          `eval` is called every `eval_every` epochs and at the end of the
          learning experience.
      :param peval_mode: one of {'epoch', 'iteration'}. Decides whether the
          periodic evaluation during training should execute every
          `eval_every` epochs or iterations (Default='epoch').
      """
  
      if not isinstance(model, SCRModel):
          raise ValueError(
              "Supervised Contrastive Replay model "
              "needs to be an instance of avalanche.models.SCRModel."
          )
  
      self.replay_plugin = ReplayPlugin(
          mem_size,
          batch_size=train_mb_size,
          batch_size_mem=batch_size_mem,
          storage_policy=ClassBalancedBuffer(max_size=mem_size),
      )
  
      self.augmentations = augmentations
      self.temperature = temperature
  
      self.train_loss = SCRLoss(temperature=self.temperature)
      self.eval_loss = torch.nn.CrossEntropyLoss()
  
      if plugins is None:
          plugins = [self.replay_plugin]
      elif isinstance(plugins, list):
          plugins = [self.replay_plugin] + plugins
      else:
          raise ValueError("`plugins` parameter needs to be a list.")
      super().__init__(
          model,
          optimizer,
          SCRLoss(temperature=self.temperature),
          train_mb_size,
          train_epochs,
          eval_mb_size,
          device,
          plugins,
          evaluator,
          eval_every,
          peval_mode,
      )
  
imports: from typing import Optional, Sequence
  import torch
  from torch.nn import Module
  from torch.optim import Optimizer
  from torch.utils.data import DataLoader
  from torchvision.transforms import Compose, Lambda
  from avalanche.core import BaseSGDPlugin
  from avalanche.models import SCRModel
  from avalanche.training.losses import SCRLoss
  from avalanche.training.plugins import ReplayPlugin
  from avalanche.training.plugins.evaluation import default_evaluator
  from avalanche.training.storage_policy import ClassBalancedBuffer
  from avalanche.training.templates import SupervisedTemplate
label_desc: Use image node_id 1 to create a new SCR object from inherited base classes: SupervisedTemplate with example: obj = SCR(model, optimizer, augmentations, mem_size, temperature, train_mb_size, batch_size_mem, train_epochs, eval_mb_size, device, plugins, evaluator, eval_every, peval_mode)