code: def predict_using_tflite(model, batch_src):
      """Convert a keras model to tflite and infer on batch_src
  
      Attempts to convert a keras model to a tflite model, load the tflite model,
      then infer on the data in batch_src
      Args:
          model (keras model)
          batch_src (numpy array) - audio to test model
      Returns:
          pred_tflite (numpy array) - array of predictions.
      """
      ############################################################################
      # TF lite conversion
      converter = tf.lite.TFLiteConverter.from_keras_model(model)
      converter.target_spec.supported_ops = [
          tf.lite.OpsSet.SELECT_TF_OPS,
          tf.lite.OpsSet.TFLITE_BUILTINS,
      ]
      tflite_model = converter.convert()
      model_name = "test_tflite"
      path = Path("/tmp/tflite_tests/")
      # make a temporary location
      if path.exists():
          shutil.rmtree(path)
      os.makedirs(path)
      tflite_file = path / Path(model_name + ".tflite")
      open(tflite_file.as_posix(), "wb").write(tflite_model)
  
      ############################################################################
      # Make sure we can load and infer on the TFLITE model
      interpreter = tf.lite.Interpreter(tflite_file.as_posix())
      # infer on each input separately and collect the predictions
      pred_tflite = []
  
      for x in batch_src:
          # set batch size for tflite
          interpreter.allocate_tensors()
  
          # Get input and output tensors.
          input_details = interpreter.get_input_details()
          output_details = interpreter.get_output_details()
  
          # apply input tensors, expand first dimension to create batch dimension
          interpreter.set_tensor(
              input_details[0]["index"], np.expand_dims(x, 0)
          )
          # infer
          interpreter.invoke()
          tflite_results = interpreter.get_tensor(
              output_details[0]["index"]
          )
  
          pred_tflite.append(tflite_results)
  
      return np.concatenate(pred_tflite, axis=0)
  
file_path: kapre/tests/utils.py
imports: import os
  from pathlib import Path
  import shutil
  import numpy
  import tensorflow
  import tempfile
  from tensorflow.keras import backend
label_desc: Use image node_id 4 for calling a global function with example usage: predict_using_tflite(model, batch_src) and returns: np