code: def write_to_tensorboard(
      model_metrics: dict[str, str | float],
  ):
      """Write model_metrics to tensorboard.
  
      Args:
          model_metrics (dict[str, str | float]): Dictionary containing collected results.
      """
      scalar_metrics = {}
      scalar_prefixes: list[str] = []
      string_metrics = {}
      for key, metric in model_metrics.items():
          if isinstance(metric, (int, float, bool)):
              scalar_metrics[key] = metric
          else:
              string_metrics[key] = metric
              scalar_prefixes.append(metric)
      writer = SummaryWriter(
          f"runs/{model_metrics['model_name']}_{model_metrics['device']}"
      )
      for key, metric in model_metrics.items():
          if isinstance(metric, (int, float, bool)):
              scalar_metrics[
                  key.replace(".", "/")
              ] = metric  # need to join by / for tensorboard grouping
              writer.add_scalar(key, metric)
          else:
              if key == "model_name":
                  continue
              scalar_prefixes.append(metric)
      scalar_prefix: str = "/".join(scalar_prefixes)
      for key, metric in scalar_metrics.items():
          writer.add_scalar(scalar_prefix + "/" + str(key), metric)
      writer.close()
  
file_path: anomalib/tools/benchmarking/utils/metrics.py
imports: from __future__ import annotations
  import random
  import string
  from glob import glob
  from pathlib import Path
  import pandas
  import wandb
  from comet_ml import Experiment
  from torch.utils.tensorboard.writer import SummaryWriter
label_desc: Use image node_id 2 for calling a global function with example usage: write_to_tensorboard(model_metrics) without return types