class_docstr: MobileNet model trained on ImageNet dataset.
class_docstr_tok: ["MobileNet","model","trained","on","ImageNet","dataset","."]
code: def predict_minibatch(
      self, input_batch: list[lit_types.JsonDict]
  ) -> list[lit_types.JsonDict]:
      output = []
      for example in input_batch:
          # Convert input to the model acceptable format.
          img_data = example["image"]
          if isinstance(img_data, str):
              img_data = image_utils.convert_image_str_to_array(
                  img_data, IMAGE_SHAPE
              )
          # Get predictions.
          x = img_data[np.newaxis, ...]
          x = tf.convert_to_tensor(x)
          preds = self.model(x).numpy()[0]
          # Determine the gradient target.
          if (grad_target := example.get("label")) is None:
              grad_target_idx = np.argmax(preds)
          else:
              grad_target_idx = self.label_to_idx[grad_target]
          # Calculate gradients.
          with tf.GradientTape() as tape:
              tape.watch(x)
              y = self.model(x)[0, grad_target_idx]
              grads = tape.gradient(y, x).numpy()[0]
          # Add results to the output.
          output.append(
              {
                  "preds": preds,
                  "grads": grads,
              }
          )
  
      return output
  
file_path: lit/lit_nlp/examples/models/mobilenet.py
imports: from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.examples.models import imagenet_labels
  from lit_nlp.lib import image_utils
  import numpy
  import tensorflow
label_desc: Use image node_id 2 for calling the MobileNet obj's underlying member method code with example usage: obj.predict_minibatch(input_batch) and returns: output