code: def _baseline_specificity_binary(
      preds, target, ignore_index, multidim_average
  ):
      if multidim_average == "global":
          preds = preds.view(-1).numpy()
          target = target.view(-1).numpy()
      else:
          preds = preds.numpy()
          target = target.numpy()
  
      if np.issubdtype(preds.dtype, np.floating):
          if not ((preds > 0) & (preds < 1)).all():
              preds = sigmoid(preds)
          preds = (preds >= THRESHOLD).astype(np.uint8)
  
      if multidim_average == "global":
          if ignore_index is not None:
              idx = target == ignore_index
              target = target[~idx]
              preds = preds[~idx]
          tn, fp, _, _ = sk_confusion_matrix(
              y_true=target, y_pred=preds, labels=[0, 1]
          ).ravel()
          return _calc_specificity(tn, fp)
  
      res = []
      for pred, true in zip(preds, target):
          pred = pred.flatten()
          true = true.flatten()
          if ignore_index is not None:
              idx = true == ignore_index
              true = true[~idx]
              pred = pred[~idx]
          tn, fp, _, _ = sk_confusion_matrix(
              y_true=true, y_pred=pred, labels=[0, 1]
          ).ravel()
          res.append(_calc_specificity(tn, fp))
      return np.stack(res)
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import confusion_matrix
  from torch import Tensor, tensor
  from torchmetrics.classification.specificity import BinarySpecificity, MulticlassSpecificity, MultilabelSpecificity, Specificity
  from torchmetrics.functional.classification.specificity import binary_specificity, multiclass_specificity, multilabel_specificity
  from torchmetrics.metric import Metric
  from unittests import NUM_CLASSES, THRESHOLD
  from unittests.classification.inputs import _binary_cases, _multiclass_cases, _multilabel_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, inject_ignore_index
label_desc: Use image node_id 2 for calling a global function with example usage: _baseline_specificity_binary(preds, target, ignore_index, multidim_average) and returns: np, _calc_specificity