code: def _gather_means_and_cov(
      model, dataset, batch_size, device, **kwargs
  ):
      num_workers = (
          kwargs["num_workers"] if "num_workers" in kwargs else 0
      )
      loader = torch.utils.data.DataLoader(
          dataset.eval(),
          batch_size=batch_size,
          shuffle=False,
          num_workers=num_workers,
      )
  
      features = []
      labels = []
  
      was_training = model.training
      model.eval()
  
      for x, y, t in loader:
          x = x.to(device)
          y = y.to(device)
  
          with torch.no_grad():
              out = model.feature_extractor(x)
  
          features.append(out)
          labels.append(y)
  
      if was_training:
          model.train()
  
      features = torch.cat(features)
      labels = torch.cat(labels)
  
      # Transform
      features = model.eval_classifier.apply_transforms(features)
      class_means = compute_means(features, labels)
      class_cov = compute_covariance(features, labels)
      class_cov = model.eval_classifier.apply_cov_transforms(class_cov)
  
      return class_means, class_cov
  
imports: import copy
  from typing import Dict
  import numpy
  import torch
  import torch.nn.functional
  from torch import Tensor, nn
  from avalanche.benchmarks.utils import concat_datasets
  from avalanche.models import FeCAMClassifier
  from avalanche.models.fecam import compute_covariance, compute_means
  from avalanche.training.plugins import SupervisedPlugin
  from avalanche.training.storage_policy import ClassBalancedBuffer
  from avalanche.training.templates import SupervisedTemplate
label_desc: Use image node_id 1 for calling a global function with example usage: _gather_means_and_cov(model, dataset, batch_size, device) and returns: class_means,  class_cov