class_docstr: This class implements a classifier with the TensorFlow framework.
class_docstr_tok: ["This","class","implements","a","classifier","with","the","TensorFlow","framework","."]
docstr: Compute the gradient of the loss function w.r.t. `x`.
  
  :param x: Sample input with shape as expected by the model.
  :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices of shape
            `(nb_samples,)`.
  :param training_mode: `True` for model set to training mode and `'False` for model set to evaluation mode.
  :return: Array of gradients of the same shape as `x`.
docstr_tok: ["Compute","the","gradient","of","the","loss","function","w.r.t",".","`","x","`",".",":","param","x",":","Sample","input","with","shape","as","expected","by","the","model",".",":","param","y",":","Target","values","(","class","labels",")","one-hot-encoded","of","shape","`","(","nb_samples",",","nb_classes",")","`","or","indices","of","shape","`","(","nb_samples",",",")","`",".",":","param","training_mode",":","`","True","`","for","model","set","to","training","mode","and","`","'False","`","for","model","set","to","evaluation","mode",".",":","return",":","Array","of","gradients","of","the","same","shape","as","`","x","`","."]
code: def loss_gradient(  # pylint: disable=W0221
      self,
      x: np.ndarray,
      y: np.ndarray,
      training_mode: bool = False,
      **kwargs,
  ) -> np.ndarray:
      """
      Compute the gradient of the loss function w.r.t. `x`.
  
      :param x: Sample input with shape as expected by the model.
      :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices of shape
                `(nb_samples,)`.
      :param training_mode: `True` for model set to training mode and `'False` for model set to evaluation mode.
      :return: Array of gradients of the same shape as `x`.
      """
      if self.learning is not None:
          self.feed_dict[self.learning] = training_mode
  
      # Apply preprocessing
      x_preprocessed, y_preprocessed = self._apply_preprocessing(
          x, y, fit=False
      )
  
      # Check if loss available
      if (
          not hasattr(self, "_loss_grads")
          or self._loss_grads is None
          or self.labels_ph is None
      ):  # pragma: no cover
          raise ValueError(
              "Need the loss function and the labels placeholder to compute the loss gradient."
          )
  
      # Check label shape
      if self._reduce_labels:
          y_preprocessed = np.argmax(y_preprocessed, axis=1)
  
      # Create feed_dict
      feed_dict = {
          self.input_ph: x_preprocessed,
          self.labels_ph: y_preprocessed,
      }
      feed_dict.update(self.feed_dict)
  
      # Compute gradients
      grads = self._sess.run(self._loss_grads, feed_dict=feed_dict)
      grads = self._apply_preprocessing_gradient(x, grads)
      assert grads.shape == x_preprocessed.shape
  
      return grads
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  import random
  import shutil
  import time
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union, TYPE_CHECKING
  from tqdm.auto import tqdm
  import numpy
  import six
  from art import config
  from art.estimators.classification.classifier import ClassGradientsMixin, ClassifierMixin
  from art.estimators.tensorflow import TensorFlowEstimator, TensorFlowV2Estimator
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 14 for calling the TensorFlowClassifier obj's underlying member method code with example usage: obj.loss_gradient(x, y, training_mode) and returns: grads