class_docstr: The Stream Confusion Matrix metric.
  This plugin metric only works on the eval phase.
  
  Confusion Matrix computation can be slow if you compute it for a large
  number of classes. We recommend to set `save_image=False` if the runtime
  is too large.
  
  At the end of the eval phase, this metric logs the confusion matrix
  relative to all the patterns seen during eval.
  
  The metric can log either a Tensor or a PIL Image representing the
  confusion matrix.
class_docstr_tok: ["The","Stream","Confusion","Matrix","metric",".","This","plugin","metric","only","works","on","the","eval","phase",".","Confusion","Matrix","computation","can","be","slow","if","you","compute","it","for","a","large","number","of","classes",".","We","recommend","to","set","`","save_image=False","`","if","the","runtime","is","too","large",".","At","the","end","of","the","eval","phase",",","this","metric","logs","the","confusion","matrix","relative","to","all","the","patterns","seen","during","eval",".","The","metric","can","log","either","a","Tensor","or","a","PIL","Image","representing","the","confusion","matrix","."]
docstr: Creates an instance of the Stream Confusion Matrix metric.
  
  We recommend to set `save_image=False` if the runtime is too large.
  In fact, a large number of classes may increase the computation time
  of this metric.
  
  :param num_classes: The number of classes. Defaults to None,
      which means that the number of classes will be inferred from
      ground truth and prediction Tensors (see class description for more
      details). If not None, the confusion matrix will always be of size
      `num_classes, num_classes` and only the first `num_classes` values
      of output logits or target logits will be considered in the update.
      If the output or targets are provided as numerical labels,
      there can be no label greater than `num_classes`.
  :param normalize: Normalizes confusion matrix over the true (rows),
      predicted (columns) conditions or all the population. If None,
      confusion matrix will not be normalized. Valid values are: 'true',
      'pred' and 'all' or None.
  :param save_image: If True, a graphical representation of the confusion
      matrix will be logged, too. If False, only the Tensor representation
      will be logged. Defaults to True.
  :param image_creator: A callable that, given the tensor representation
      of the confusion matrix and the corresponding labels, returns a
      graphical representation of the matrix as a PIL Image. Defaults to
      `default_cm_image_creator`.
  :param absolute_class_order: If true, the labels in the created image
      will be sorted by id, otherwise they will be sorted by order of
      encounter at training time. This parameter is ignored if
      `save_image` is False, or the scenario is not a NCScenario.
docstr_tok: ["Creates","an","instance","of","the","Stream","Confusion","Matrix","metric",".","We","recommend","to","set","`","save_image=False","`","if","the","runtime","is","too","large",".","In","fact",",","a","large","number","of","classes","may","increase","the","computation","time","of","this","metric",".",":","param","num_classes",":","The","number","of","classes",".","Defaults","to","None",",","which","means","that","the","number","of","classes","will","be","inferred","from","ground","truth","and","prediction","Tensors","(","see","class","description","for","more","details",")",".","If","not","None",",","the","confusion","matrix","will","always","be","of","size","`","num_classes",",","num_classes","`","and","only","the","first","`","num_classes","`","values","of","output","logits","or","target","logits","will","be","considered","in","the","update",".","If","the","output","or","targets","are","provided","as","numerical","labels",",","there","can","be","no","label","greater","than","`","num_classes","`",".",":","param","normalize",":","Normalizes","confusion","matrix","over","the","true","(","rows",")",",","predicted","(","columns",")","conditions","or","all","the","population",".","If","None",",","confusion","matrix","will","not","be","normalized",".","Valid","values","are",":","'true","'",",","'pred","'","and","'all","'","or","None",".",":","param","save_image",":","If","True",",","a","graphical","representation","of","the","confusion","matrix","will","be","logged",",","too",".","If","False",",","only","the","Tensor","representation","will","be","logged",".","Defaults","to","True",".",":","param","image_creator",":","A","callable","that",",","given","the","tensor","representation","of","the","confusion","matrix","and","the","corresponding","labels",",","returns","a","graphical","representation","of","the","matrix","as","a","PIL","Image",".","Defaults","to","`","default_cm_image_creator","`",".",":","param","absolute_class_order",":","If","true",",","the","labels","in","the","created","image","will","be","sorted","by","id",",","otherwise","they","will","be","sorted","by","order","of","encounter","at","training","time",".","This","parameter","is","ignored","if","`","save_image","`","is","False",",","or","the","scenario","is","not","a","NCScenario","."]
code: def __init__(
      self,
      num_classes: Optional[int] = None,
      normalize: Optional[Literal["true", "pred", "all"]] = None,
      save_image: bool = True,
      image_creator: Callable[
          [Tensor, Optional[Iterable[Any]]], Union[Figure, Image]
      ] = default_cm_image_creator,
      absolute_class_order: bool = False,
  ):
      """
      Creates an instance of the Stream Confusion Matrix metric.
  
      We recommend to set `save_image=False` if the runtime is too large.
      In fact, a large number of classes may increase the computation time
      of this metric.
  
      :param num_classes: The number of classes. Defaults to None,
          which means that the number of classes will be inferred from
          ground truth and prediction Tensors (see class description for more
          details). If not None, the confusion matrix will always be of size
          `num_classes, num_classes` and only the first `num_classes` values
          of output logits or target logits will be considered in the update.
          If the output or targets are provided as numerical labels,
          there can be no label greater than `num_classes`.
      :param normalize: Normalizes confusion matrix over the true (rows),
          predicted (columns) conditions or all the population. If None,
          confusion matrix will not be normalized. Valid values are: 'true',
          'pred' and 'all' or None.
      :param save_image: If True, a graphical representation of the confusion
          matrix will be logged, too. If False, only the Tensor representation
          will be logged. Defaults to True.
      :param image_creator: A callable that, given the tensor representation
          of the confusion matrix and the corresponding labels, returns a
          graphical representation of the matrix as a PIL Image. Defaults to
          `default_cm_image_creator`.
      :param absolute_class_order: If true, the labels in the created image
          will be sorted by id, otherwise they will be sorted by order of
          encounter at training time. This parameter is ignored if
          `save_image` is False, or the scenario is not a NCScenario.
      """
      super().__init__()
  
      self._save_image: bool = save_image
      self.num_classes = num_classes
      self.normalize = normalize
      self.absolute_class_order = absolute_class_order
      self._matrix: ConfusionMatrix = ConfusionMatrix(
          num_classes=num_classes, normalize=normalize
      )
      self._image_creator = image_creator
  
imports: from matplotlib.figure import Figure
  from numpy import arange
  from typing_extensions import Literal
  from typing import Any, Callable, Iterable, Union, Optional, TYPE_CHECKING, List
  import wandb
  import numpy
  import torch
  from PIL.Image import Image
  from torch import Tensor
  from torch.nn.functional import pad
  from avalanche.benchmarks import NCScenario
  from avalanche.evaluation import PluginMetric, Metric
  from avalanche.evaluation.metric_results import AlternativeValues, MetricValue, MetricResult
  from avalanche.evaluation.metric_utils import default_cm_image_creator, phase_and_task, stream_type
label_desc: Use image node_id 1 to create a new StreamConfusionMatrix object from inherited base classes: PluginMetric with example: obj = StreamConfusionMatrix(num_classes, normalize, save_image, image_creator, absolute_class_order)