code: def test_generate_targeted(
      art_warning, fix_get_mnist_subset, fix_get_rcnn, framework
  ):
      try:
          (_, _, x_test_mnist, _) = fix_get_mnist_subset
  
          if framework in ["pytorch", "huggingface"]:
              x_test_mnist = np.transpose(x_test_mnist, (0, 2, 3, 1))
  
          frcnn = fix_get_rcnn
          attack = RobustDPatch(
              frcnn,
              patch_shape=(4, 4, 1),
              patch_location=(2, 2),
              crop_range=(0, 0),
              brightness_range=(1.0, 1.0),
              rotation_weights=(1, 0, 0, 0),
              sample_size=1,
              learning_rate=1.0,
              max_iter=1,
              batch_size=1,
              targeted=True,
              verbose=False,
          )
          y = frcnn.predict(x_test_mnist)
          patch = attack.generate(x=x_test_mnist, y=y)
          assert patch.shape == (4, 4, 1)
  
          with pytest.raises(ValueError):
              _ = attack.generate(x=x_test_mnist, y=None)
  
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/attacks/evasion/test_dpatch_robust.py
imports: import logging
  import numpy
  import pytest
  from art.attacks.evasion import RobustDPatch
  from art.estimators.estimator import BaseEstimator, LossGradientsMixin
  from art.estimators.object_detection.object_detector import ObjectDetectorMixin
  from tests.attacks.utils import backend_test_classifier_type_check_fail
  from tests.utils import ARTTestException
label_desc: Use image node_id 3 for calling a global function with example usage: test_generate_targeted(art_warning, fix_get_mnist_subset, fix_get_rcnn, framework) without return types