code: def testFlexResourceVariables(self):
      class Model(tf.Module):
          def __init__(self):
              self.v = tf.Variable([[0.0, 0.0, 0.0, 0.0]])
  
          @tf.function(
              input_signature=[
                  tf.TensorSpec(shape=[1, 4], dtype=tf.float32)
              ]
          )
          def eval(self, x):
              # Control flow is needed to generate "FlexReadVariableOp".
              if tf.reduce_mean(x) > 1.0:
                  self.v.assign_add([[1.0, 1.0, 1.0, 1.0]])
              return self.v + x
  
      m = Model()
      to_save = m.eval.get_concrete_function()
      save_dir = os.path.join(self.get_temp_dir(), "saved_model")
      tf.saved_model.save(m, save_dir, to_save)
      converter = tf.lite.TFLiteConverter.from_saved_model(save_dir)
  
      converter.target_spec.supported_ops = [
          tf.lite.OpsSet.TFLITE_BUILTINS,
          tf.lite.OpsSet.SELECT_TF_OPS,
      ]
      converter.experimental_enable_resource_variables = True
      tflite_model = converter.convert()
  
      # Check the model works with TensorFlow ops.
      interpreter = Interpreter(model_content=tflite_model)
      signature_runner = interpreter.get_signature_runner()
      outputs = signature_runner(
          x=np.array([[1.0, 2.0, 3.0, 4.0]], dtype=np.float32)
      )
      expected_output = np.array(
          [[2.0, 3.0, 4.0, 5.0]], dtype=np.float32
      )
      self.assertTrue(
          (expected_output == list(outputs.values())[0]).all
      )
  
      # Second run.
      outputs = signature_runner(
          x=np.array([[1.0, 2.0, 3.0, 4.0]], dtype=np.float32)
      )
      expected_output = np.array(
          [[3.0, 4.0, 5.0, 6.0]], dtype=np.float32
      )
      self.assertTrue(
          (expected_output == list(outputs.values())[0]).all
      )
  
imports: import os
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow.core.framework import graph_pb2
  from tensorflow.lite.python import lite
  from tensorflow.lite.python import test_util
  from tensorflow.lite.python.convert import register_custom_opdefs
  from tensorflow.lite.python.interpreter import Interpreter
  from tensorflow.lite.python.testdata import double_op
  from tensorflow.python.client import session
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.framework.importer import import_graph_def
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import list_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
  from tensorflow.python.saved_model import saved_model
  from tensorflow.python.trackable import autotrackable
label_desc: Use image node_id 1 for calling the FromSavedModelTest obj's underlying member method code with example usage: obj.testFlexResourceVariables() and returns: unknown