class_docstr: Bias Correction (BiC) plugin.
  
  Technique introduced in:
  "Wu, Yue, et al. "Large scale incremental learning." Proceedings
  of the IEEE/CVF Conference on Computer Vision and Pattern
  Recognition. 2019"
  
  Implementation based on FACIL, as in:
  https://github.com/mmasana/FACIL/blob/master/src/approach/bic.py
docstr: :param mem_size: replay buffer size.
  :param batch_size: the size of the data batch. If set to `None`, it
      will be set equal to the strategy's batch size.
  :param batch_size_mem: the size of the memory batch. If
      `task_balanced_dataloader` is set to True, it must be greater than
      or equal to the number of tasks. If its value is set to `None`
      (the default value), it will be automatically set equal to the
      data batch size.
  :param task_balanced_dataloader: if True, buffer data loaders will be
          task-balanced, otherwise it will create a single dataloader for
          the buffer samples.
  :param storage_policy: The policy that controls how to add new exemplars
                      in memory
  :param val_percentage: hyperparameter used to set the
          percentage of exemplars in the val set.
  :param T: hyperparameter used to set the temperature
          used in stage 1.
  :param stage_2_epochs: hyperparameter used to set the
          amount of epochs of stage 2.
  :param lamb: hyperparameter used to balance the distilling
          loss and the classification loss.
  :param lr: hyperparameter used as a learning rate for
          the second phase of training.
docstr_tok: [":","param","mem_size",":","replay","buffer","size",".",":","param","batch_size",":","the","size","of","the","data","batch",".","If","set","to","`","None","`",",","it","will","be","set","equal","to","the","strategy","'s","batch","size",".",":","param","batch_size_mem",":","the","size","of","the","memory","batch",".","If","`","task_balanced_dataloader","`","is","set","to","True",",","it","must","be","greater","than","or","equal","to","the","number","of","tasks",".","If","its","value","is","set","to","`","None","`","(","the","default","value",")",",","it","will","be","automatically","set","equal","to","the","data","batch","size",".",":","param","task_balanced_dataloader",":","if","True",",","buffer","data","loaders","will","be","task-balanced",",","otherwise","it","will","create","a","single","dataloader","for","the","buffer","samples",".",":","param","storage_policy",":","The","policy","that","controls","how","to","add","new","exemplars","in","memory",":","param","val_percentage",":","hyperparameter","used","to","set","the","percentage","of","exemplars","in","the","val","set",".",":","param","T",":","hyperparameter","used","to","set","the","temperature","used","in","stage","1.",":","param","stage_2_epochs",":","hyperparameter","used","to","set","the","amount","of","epochs","of","stage","2.",":","param","lamb",":","hyperparameter","used","to","balance","the","distilling","loss","and","the","classification","loss",".",":","param","lr",":","hyperparameter","used","as","a","learning","rate","for","the","second","phase","of","training","."]
code: def __init__(
      self,
      mem_size: int = 2000,
      batch_size: Optional[int] = None,
      batch_size_mem: Optional[int] = None,
      task_balanced_dataloader: bool = False,
      storage_policy: Optional["ExemplarsBuffer"] = None,
      val_percentage: float = 0.1,
      T: int = 2,
      stage_2_epochs: int = 200,
      lamb: float = -1,
      lr: float = 0.1,
  ):
      """
      :param mem_size: replay buffer size.
      :param batch_size: the size of the data batch. If set to `None`, it
          will be set equal to the strategy's batch size.
      :param batch_size_mem: the size of the memory batch. If
          `task_balanced_dataloader` is set to True, it must be greater than
          or equal to the number of tasks. If its value is set to `None`
          (the default value), it will be automatically set equal to the
          data batch size.
      :param task_balanced_dataloader: if True, buffer data loaders will be
              task-balanced, otherwise it will create a single dataloader for
              the buffer samples.
      :param storage_policy: The policy that controls how to add new exemplars
                          in memory
      :param val_percentage: hyperparameter used to set the
              percentage of exemplars in the val set.
      :param T: hyperparameter used to set the temperature
              used in stage 1.
      :param stage_2_epochs: hyperparameter used to set the
              amount of epochs of stage 2.
      :param lamb: hyperparameter used to balance the distilling
              loss and the classification loss.
      :param lr: hyperparameter used as a learning rate for
              the second phase of training.
      """
  
      # Replay (Phase 1)
      super().__init__()
      self.mem_size = mem_size
      self.batch_size = batch_size
      self.batch_size_mem = batch_size_mem
      self.task_balanced_dataloader = task_balanced_dataloader
  
      if storage_policy is not None:  # Use other storage policy
          self.storage_policy = storage_policy
          assert storage_policy.max_size == self.mem_size
      else:  # Default
          self.storage_policy = ExperienceBalancedBuffer(
              max_size=self.mem_size, adaptive_size=True
          )
  
      # Train Bias (Phase 2)
      self.val_percentage = val_percentage
      self.stage_2_epochs = stage_2_epochs
      self.T = T
      self.lamb = lamb
      self.mem_size = mem_size
      self.lr = lr
  
      self.seen_classes: Set[int] = set()
      self.class_to_tasks: Dict[int, int] = {}
      self.bias_layer: Dict[int, BiasLayer] = {}
      self.model_old = None
      self.val_buffer: Dict[int, ReservoirSamplingBuffer] = {}
  
imports: from collections import defaultdict
  from typing import Dict, List, Optional, TYPE_CHECKING, Sequence, Set, SupportsInt
  from copy import deepcopy
  import torch
  from torch.utils.data import DataLoader
  from torch.optim.lr_scheduler import MultiStepLR
  from avalanche.benchmarks.utils import _taskaware_classification_subset, _concat_taskaware_classification_datasets
  from avalanche.benchmarks.utils.data import AvalancheDataset
  from avalanche.benchmarks.utils.data_loader import ReplayDataLoader
  from avalanche.training.plugins.strategy_plugin import SupervisedPlugin
  from avalanche.training.storage_policy import ExemplarsBuffer, ExperienceBalancedBuffer, ReservoirSamplingBuffer
  from avalanche.models.dynamic_modules import MultiTaskModule
  from avalanche.models.bic_model import BiasLayer
label_desc: Use image node_id 1 to create a new BiCPlugin object from inherited base classes: SupervisedPlugin with example: obj = BiCPlugin(mem_size, batch_size, batch_size_mem, task_balanced_dataloader, storage_policy, val_percentage, T, stage_2_epochs, lamb, lr)