code: def _sklearn_accuracy_multilabel(
      preds, target, ignore_index, multidim_average, average
  ):
      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)
      preds = preds.reshape(*preds.shape[:2], -1)
      target = target.reshape(*target.shape[:2], -1)
  
      if multidim_average == "global":
          if average == "micro":
              preds = preds.flatten()
              target = target.flatten()
              target, preds = remove_ignore_index(
                  target, preds, ignore_index
              )
              return _sklearn_accuracy(target, preds)
  
          accuracy, weights = [], []
          for i in range(preds.shape[1]):
              pred, true = preds[:, i].flatten(), target[:, i].flatten()
              true, pred = remove_ignore_index(true, pred, ignore_index)
              confmat = sk_confusion_matrix(true, pred, labels=[0, 1])
              accuracy.append(_sklearn_accuracy(true, pred))
              weights.append(confmat[1, 1] + confmat[1, 0])
          res = np.stack(accuracy, axis=0)
  
          if average == "macro":
              return res.mean(0)
          if average == "weighted":
              weights = np.stack(weights, 0).astype(float)
              weights_norm = weights.sum(-1, keepdims=True)
              weights_norm[weights_norm == 0] = 1.0
              return ((weights * res) / weights_norm).sum(-1)
          if average is None or average == "none":
              return res
          return None
  
      accuracy, weights = [], []
      for i in range(preds.shape[0]):
          if average == "micro":
              pred, true = preds[i].flatten(), target[i].flatten()
              true, pred = remove_ignore_index(true, pred, ignore_index)
              accuracy.append(_sklearn_accuracy(true, pred))
              confmat = sk_confusion_matrix(true, pred, labels=[0, 1])
              weights.append(confmat[1, 1] + confmat[1, 0])
          else:
              scores, w = [], []
              for j in range(preds.shape[1]):
                  pred, true = preds[i, j], target[i, j]
                  true, pred = remove_ignore_index(
                      true, pred, ignore_index
                  )
                  scores.append(_sklearn_accuracy(true, pred))
                  confmat = sk_confusion_matrix(
                      true, pred, labels=[0, 1]
                  )
                  w.append(confmat[1, 1] + confmat[1, 0])
              accuracy.append(np.stack(scores))
              weights.append(np.stack(w))
      if average == "micro":
          return np.array(accuracy)
      res = np.stack(accuracy, 0)
      if average == "macro":
          return res.mean(-1)
      if average == "weighted":
          weights = np.stack(weights, 0).astype(float)
          weights_norm = weights.sum(-1, keepdims=True)
          weights_norm[weights_norm == 0] = 1.0
          return ((weights * res) / weights_norm).sum(-1)
      if average is None or average == "none":
          return res
      return None
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import accuracy_score
  from sklearn.metrics import confusion_matrix
  from torchmetrics.classification.accuracy import Accuracy, BinaryAccuracy, MulticlassAccuracy, MultilabelAccuracy
  from torchmetrics.functional.classification.accuracy import accuracy, binary_accuracy, multiclass_accuracy, multilabel_accuracy
  from torchmetrics.metric import Metric
  from unittests import NUM_CLASSES, THRESHOLD
  from unittests.classification.inputs import _binary_cases, _input_binary, _multiclass_cases, _multilabel_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, inject_ignore_index, remove_ignore_index
label_desc: Use image node_id 6 for calling a global function with example usage: _sklearn_accuracy_multilabel(preds, target, ignore_index, multidim_average, average) and returns: None, None, np, res, unknown, res, _sklearn_accuracy, res, unknown, res