class_docstr: Test case class implementing extra test functionalities.
class_docstr_tok: ["Test","case","class","implementing","extra","test","functionalities","."]
docstr: Runs the tf-lite converter to make sure the function can be exported.
  
  Args:
    func: A function to execute with tf-lite.
    shapes: A tuple or list of input shapes.
    dtypes: A list of input types.
    test_inputs: A tuple or list of inputs. If not provided the test inputs
      will be randomly generated.
docstr_tok: ["Runs","the","tf-lite","converter","to","make","sure","the","function","can","be","exported",".","Args",":","func",":","A","function","to","execute","with","tf-lite",".","shapes",":","A","tuple","or","list","of","input","shapes",".","dtypes",":","A","list","of","input","types",".","test_inputs",":","A","tuple","or","list","of","inputs",".","If","not","provided","the","test","inputs","will","be","randomly","generated","."]
code: def assert_tf_lite_convertible(
      self, func, shapes, dtypes=None, test_inputs=None
  ):
      """Runs the tf-lite converter to make sure the function can be exported.
  
      Args:
        func: A function to execute with tf-lite.
        shapes: A tuple or list of input shapes.
        dtypes: A list of input types.
        test_inputs: A tuple or list of inputs. If not provided the test inputs
          will be randomly generated.
      """
      if tf.executing_eagerly():
          # Currently TFLite conversion is not supported in eager mode.
          self.skipTest(reason="Graph mode only test")
      # Generate graph with the function given as input.
      in_tensors = self._create_placeholders_from_shapes(shapes, dtypes)
      out_tensors = func(*in_tensors)
      if not isinstance(out_tensors, (list, tuple)):
          out_tensors = [out_tensors]
      with tf.compat.v1.Session() as sess:
          try:
              sess.run(tf.compat.v1.global_variables_initializer())
              # Convert to a TFLite model.
              converter = (
                  tf.compat.v1.lite.TFLiteConverter.from_session(
                      sess, in_tensors, out_tensors
                  )
              )
              tflite_model = converter.convert()
              # Load TFLite model and allocate tensors.
              interpreter = tf.lite.Interpreter(
                  model_content=tflite_model
              )
              interpreter.allocate_tensors()
              # If no test inputs provided then randomly generate inputs.
              if test_inputs is None:
                  test_inputs = [
                      np.array(
                          np.random.sample(shape), dtype=np.float32
                      )
                      for shape in shapes
                  ]
              else:
                  test_inputs = [
                      np.array(test, dtype=np.float32)
                      for test in test_inputs
                  ]
              # Evaluate function using TensorFlow.
              feed_dict = dict(list(zip(in_tensors, test_inputs)))
              test_outputs = sess.run(out_tensors, feed_dict)
              # Set tensors for the TFLite model.
              input_details = interpreter.get_input_details()
              for i, test_input in enumerate(test_inputs):
                  index = input_details[i]["index"]
                  interpreter.set_tensor(index, test_input)
              # Run TFLite model.
              interpreter.invoke()
              # Get tensors from the TFLite model and compare with TensorFlow.
              output_details = interpreter.get_output_details()
              for o, test_output in enumerate(test_outputs):
                  index = output_details[o]["index"]
                  self.assertAllClose(
                      test_output, interpreter.get_tensor(index)
                  )
          except Exception as e:  # pylint: disable=broad-except
              self.fail("Exception raised: %s" % str(e))
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import warnings
  from absl import flags
  from absl.testing import parameterized
  import numpy
  from six.moves import zip
  import tensorflow
  from tensorflow_graphics.util import tfg_flags
label_desc: Use image node_id 13 for calling the TestCase obj's underlying member method code with example usage: obj.assert_tf_lite_convertible(func, shapes, dtypes, test_inputs) without return types