docstr: Calculate the gradient of the cross-entropy loss w.r.t the image.
  Args:
      data(numpy.ndarray): input data with shape (size, height, width,
      channels).
      label(int): Label used to calculate the gradient.
  Return:
      numpy.ndarray: gradient of the cross-entropy loss w.r.t the image
          with the shape (height, width, channel).
docstr_tok: ["Calculate","the","gradient","of","the","cross-entropy","loss","w.r.t","the","image",".","Args",":","data","(","numpy.ndarray",")",":","input","data","with","shape","(","size",",","height",",","width",",","channels",")",".","label","(","int",")",":","Label","used","to","calculate","the","gradient",".","Return",":","numpy.ndarray",":","gradient","of","the","cross-entropy","loss","w.r.t","the","image","with","the","shape","(","height",",","width",",","channel",")","."]
code: def gradient(self, data, label):
      """
      Calculate the gradient of the cross-entropy loss w.r.t the image.
      Args:
          data(numpy.ndarray): input data with shape (size, height, width,
          channels).
          label(int): Label used to calculate the gradient.
      Return:
          numpy.ndarray: gradient of the cross-entropy loss w.r.t the image
              with the shape (height, width, channel).
      """
  
      import mxnet
      import mxnet as mx
      from mxnet import autograd, nd
  
      scaled_data = self._process_input(data)
  
      # logging.info(scaled_data)
  
      scaled_data = mx.nd.array(scaled_data)
  
      # 要求系统申请对应的空间存放梯度
      scaled_data.attach_grad()
  
      with autograd.record(train_mode=False):
          preds = self._model(scaled_data)
          class_slice = preds[:, label]
  
      class_slice.backward()
      grad = np.expand_dims(scaled_data.grad.asnumpy(), axis=1)
  
      return grad.reshape(scaled_data.shape)
  
file_path: AdvBox/adversarialbox/models/mxnet.py
imports: from __future__ import absolute_import
  import numpy
  import os
  from .base import Model
  import logging
label_desc: Use image node_id 4 for calling the MxNetModel obj's underlying member method code with example usage: obj.gradient(data, label) and returns: grad