code: def test_binary_input_detector(
      art_warning,
      get_default_mnist_subset,
      image_dl_estimator,
      get_classifier,
  ):
      (x_train, _), (x_test, _) = get_default_mnist_subset
  
      # Generate adversarial samples:
      classifier, _ = image_dl_estimator(from_logits=True)
      attacker = FastGradientMethod(classifier, eps=0.1)
      x_train_adv = attacker.generate(x_train)
      x_test_adv = attacker.generate(x_test)
  
      # Compile training data for detector:
      x_train_detector = np.concatenate((x_train, x_train_adv), axis=0)
      y_train_detector = np.concatenate(
          (
              np.array([[1, 0]] * len(x_train)),
              np.array([[0, 1]] * len(x_train)),
          ),
          axis=0,
      )
  
      # Create a simple CNN for the detector
      detector_classifier = get_classifier()
  
      try:
          detector = BinaryInputDetector(detector_classifier)
          detector.fit(
              x_train_detector,
              y_train_detector,
              nb_epochs=2,
              batch_size=128,
          )
  
          # Apply detector on clean and adversarial test data:
          _, test_detection = detector.detect(x_test)
          _, test_adv_detection = detector.detect(x_test_adv)
  
          # Assert there is at least one true positive and negative:
          nb_true_positives = np.sum(test_adv_detection)
          nb_true_negatives = len(test_detection) - np.sum(
              test_detection
          )
          assert nb_true_positives > 0
          assert nb_true_negatives > 0
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/defences/detector/evasion/test_binary_input_detector.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import pytest
  import numpy
  from art.attacks.evasion import FastGradientMethod
  from art.estimators.classification import KerasClassifier, TensorFlowV2Classifier, PyTorchClassifier
  from art.defences.detector.evasion import BinaryInputDetector
  from tests.utils import ARTTestException
label_desc: Use image node_id 2 for calling a global function with example usage: test_binary_input_detector(art_warning, get_default_mnist_subset, image_dl_estimator, get_classifier) without return types