code: def test_loss_gradient_mask(
      art_warning, get_pytorch_object_detector_mask
  ):
      try:
          (
              object_detector,
              x_test,
              y_test,
          ) = get_pytorch_object_detector_mask
  
          # Compute gradients
          grads = object_detector.loss_gradient(x_test, y_test)
          assert grads.shape == (2, 28, 28, 3)
  
          expected_gradients1 = np.asarray(
              [
                  [1.2062087e-03, 6.7400718e-03, 9.5682510e-04],
                  [-3.6111937e-03, -5.3175041e-03, -3.2421902e-03],
                  [1.4717830e-03, 1.0347518e-03, 1.7675158e-04],
                  [2.9278828e-03, 5.0933827e-03, 3.5095078e-04],
                  [-3.1896026e-04, 3.6363016e-04, -6.6032895e-04],
                  [-3.8130947e-03, -5.5106943e-03, -2.3003859e-03],
                  [-4.1348115e-03, -6.5722968e-03, -1.5899740e-03],
                  [-2.4562061e-03, -4.1960045e-03, -1.7881666e-03],
                  [2.2911791e-04, -6.4335053e-04, -1.6564501e-03],
                  [-1.2582233e-03, -1.5607923e-03, -2.2904854e-03],
                  [-1.8436739e-03, -2.7200577e-03, -2.9125123e-03],
                  [-1.5151387e-03, -4.4148900e-03, -1.7429549e-03],
                  [5.4955669e-03, 8.1859864e-03, 1.6560742e-03],
                  [3.1721895e-03, 2.4013112e-03, -1.9453048e-04],
                  [5.1122587e-03, 7.4281446e-03, 2.4133435e-04],
                  [2.7988979e-03, 4.4798232e-03, -1.2488490e-03],
                  [3.1651880e-03, 4.5040119e-03, -1.6507130e-03],
                  [8.5774017e-04, 9.9022139e-04, -3.1324981e-03],
                  [3.8568545e-04, 4.7918499e-04, -2.4925626e-03],
                  [-1.8368122e-03, -3.9491002e-03, -3.9275796e-03],
                  [1.6731160e-03, 1.5304115e-03, -1.4627117e-03],
                  [1.4445755e-03, 1.4263670e-03, -2.0084691e-03],
                  [2.0193408e-04, 7.2605687e-04, -1.8740210e-03],
                  [-1.3681910e-03, 1.7499415e-05, -2.4952039e-03],
                  [1.3475126e-04, 3.0096075e-03, -2.4493274e-04],
                  [-6.2653446e-03, -9.5283017e-03, -2.9458744e-03],
                  [-2.6554640e-03, -1.4588287e-03, -3.2393888e-03],
                  [-6.4712246e-03, -7.2136321e-03, -5.4933843e-03],
              ]
          )
          np.testing.assert_array_almost_equal(
              grads[0, 0, :, :], expected_gradients1, decimal=2
          )
  
          expected_gradients2 = np.asarray(
              [
                  [-2.0123991e-04, -9.0955076e-04, -2.2947363e-04],
                  [3.0414842e-04, 3.4150464e-04, 2.1101040e-04],
                  [6.6070761e-06, -1.8034373e-04, 1.3608378e-05],
                  [-1.3393547e-05, -3.2230929e-04, -5.5581659e-05],
                  [-1.0353983e-04, -2.7751207e-04, -2.3205159e-04],
                  [-5.3371373e-04, -1.1550108e-03, -2.6975147e-04],
                  [-2.6593581e-04, -7.3971582e-04, -7.4292002e-05],
                  [-9.3046663e-05, -4.0410538e-04, -1.4271366e-04],
                  [-1.3833238e-04, -5.6283473e-04, -8.4650565e-05],
                  [-8.0315210e-04, -1.4300735e-03, -9.3330207e-05],
                  [2.7694018e-04, 6.8307301e-04, 5.5274006e-04],
                  [3.1839000e-04, 9.7277382e-04, 4.6252453e-04],
                  [2.8279822e-04, 6.2632316e-04, 3.3778447e-04],
                  [4.0508871e-04, 1.2438387e-03, 3.6151547e-04],
                  [-7.5090391e-04, -2.6640363e-04, -2.6418429e-04],
                  [-2.3455340e-03, -4.9932003e-03, -8.0432917e-04],
                  [4.1711782e-03, 5.3390805e-03, 2.4412808e-03],
                  [5.1162727e-03, 5.2886135e-03, 3.6190096e-03],
                  [6.9976337e-03, 9.7018024e-03, 3.8526775e-03],
                  [4.5005931e-03, 4.3762275e-03, 1.7228650e-03],
                  [6.3695023e-03, 8.4943371e-03, 1.7638379e-03],
                  [3.0587378e-03, 3.9485283e-03, 4.9000646e-05],
                  [-3.2190280e-04, -6.6311209e-04, -9.8086358e-04],
                  [8.3606638e-04, 2.0184387e-03, -3.5464868e-04],
                  [-1.8979331e-04, 3.1042210e-04, -4.2471994e-04],
                  [-8.8790455e-04, -1.4127755e-03, -4.4270226e-04],
                  [4.1172301e-04, 2.9453568e-04, 2.1122720e-04],
                  [1.6500468e-04, 3.7142841e-04, -4.5339554e-04],
              ]
          )
          np.testing.assert_array_almost_equal(
              grads[1, 0, :, :], expected_gradients2, decimal=2
          )
  
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/estimators/object_detection/test_pytorch_object_detector.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import numpy
  import pytest
  from tests.utils import ARTTestException
label_desc: Use image node_id 6 for calling a global function with example usage: test_loss_gradient_mask(art_warning, get_pytorch_object_detector_mask) without return types