Ooof. There are a dozen different files there called “export_*.py”.

  
      

      github.com
  

  
    

tensorflow/models 8

  master/research/object_detection

  Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub.

  

  
    
    
  

  


My first guess here is that the provided saved_models are tf1 format and you’re saving in tf2 format. And something in your conversion script isn’t quite translating.
Throwing out all the nodes sounds like something it would do if the inputs/outputs weren’t properly registered in the saved model signature.
Have you tried inspecting the saved_model? can you reload and run it correctly from python?
There’s a similar bug here where it breaks in a while-loop but IIRC lite has fixed their control-flow support since them:

  

      github.com/tensorflow/tensorflow
  

  
    
  
	  
  

  
    
      Conversion error when trying to convert model using BeamSearchDecoder from tensorflow-addons [RNN] 4
    

    
      
        opened 
        
          
        
        Jun 16, 2020
      
      

        
          closed 
        
          
        
        Jul 9, 2020
      
        

      
        
          
          gcuder
        
      
    

    
        TF 2.2
        TFLiteConverter
        type:bug
    
  


  
    **System information**
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04…): MAC OS 10.15.5
- TensorFlow installed from (source or binary): binary
- TensorFlow version (or github SHA if from source): 2.2


**Command used to run the converter or code if you’re using the Python API**

```
converter = tf.lite.TFLiteConverter.from_keras_model(inference_model)
converter.experimental_new_converter = True
converter.target_spec.supported_ops = [
        tf.lite.OpsSet.TFLITE_BUILTINS,
        tf.lite.OpsSet.SELECT_TF_OPS
    ]
tflite_quantized_model = converter.convert()
```

**The output from the converter invocation**

```
2020-06-16 12:24:25.843841: I tensorflow/core/grappler/devices.cc:55] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2020-06-16 12:24:25.843958: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2020-06-16 12:24:25.913996: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: graph_to_optimize
2020-06-16 12:24:25.914107: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: Graph size after: 460 nodes (66), 546 edges (111), time = 11.364ms.
2020-06-16 12:24:25.914119: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: Graph size after: 460 nodes (0), 546 edges (0), time = 9.66ms.
2020-06-16 12:24:25.914126: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: while_body_5784
2020-06-16 12:24:25.914133: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.002ms.
2020-06-16 12:24:25.914140: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914151: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: TensorArrayV2Write_1_cond_true_6956
2020-06-16 12:24:25.914160: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914166: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914171: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: TensorArrayV2Write_2_cond_true_6974
2020-06-16 12:24:25.914177: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914183: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914193: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: while_cond_5783
2020-06-16 12:24:25.914199: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914205: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914210: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: TensorArrayV2Write_cond_true_6938
2020-06-16 12:24:25.914215: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914228: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914235: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: model_predictive_typing_addons_beam_search_decoder_decoder_while_body_6435
2020-06-16 12:24:25.914240: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: Graph size after: 521 nodes (0), 597 edges (0), time = 4.097ms.
2020-06-16 12:24:25.914244: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: Graph size after: 521 nodes (0), 597 edges (0), time = 4.171ms.
2020-06-16 12:24:25.914248: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: BeamSearchDecoderStep_cond_true_6915
2020-06-16 12:24:25.914253: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914258: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914264: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: BeamSearchDecoderStep_cond_false_6916
2020-06-16 12:24:25.914270: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914276: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914279: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: TensorArrayV2Write_2_cond_false_6975
2020-06-16 12:24:25.914283: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914289: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914294: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: TensorArrayV2Write_1_cond_false_6957
2020-06-16 12:24:25.914298: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914302: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914307: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: model_predictive_typing_addons_beam_search_decoder_decoder_while_cond_6434
2020-06-16 12:24:25.914313: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914319: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0ms.
2020-06-16 12:24:25.914323: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: TensorArrayV2Write_cond_false_6939
2020-06-16 12:24:25.914328: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
2020-06-16 12:24:25.914333: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 0.001ms.
Traceback (most recent call last):
  File "lite_conversion.py", line 60, in <module>
    main()
  File "lite_conversion.py", line 53, in main
    tflite_quantized_model = converter.convert()
  File "/home/gc/miniconda3/envs/grammatica_tf2-gpu/lib/python3.7/site-packages/tensorflow/lite/python/lite.py", line 459, in convert
    self._funcs[0], lower_control_flow=False))
  File "/home/gc/miniconda3/envs/grammatica_tf2-gpu/lib/python3.7/site-packages/tensorflow/python/framework/convert_to_constants.py", line 706, in convert_variables_to_constants_v2_as_graph
    func, lower_control_flow, aggressive_inlining)
  File "/home/gc/miniconda3/envs/grammatica_tf2-gpu/lib/python3.7/site-packages/tensorflow/python/framework/convert_to_constants.py", line 461, in _convert_variables_to_constants_v2_impl
    node_defs, tensor_data, name_to_node)
  File "/home/gc/miniconda3/envs/grammatica_tf2-gpu/lib/python3.7/site-packages/tensorflow/python/framework/convert_to_constants.py", line 286, in _get_control_flow_function_data
    arg_types[idx] = get_resource_type(node.input[idx + 1])
  File "/home/gc/miniconda3/envs/grammatica_tf2-gpu/lib/python3.7/site-packages/tensorflow/python/framework/convert_to_constants.py", line 259, in get_resource_type
    node_name = get_source_node_name_through_identities(node_name)
  File "/home/gc/miniconda3/envs/grammatica_tf2-gpu/lib/python3.7/site-packages/tensorflow/python/framework/convert_to_constants.py", line 254, in get_source_node_name_through_identities
    while name_to_node[node_name].op == "Identity":
KeyError: 'beamsearchdecoderstep_cond_input_1_0'
```

**Any other info / logs**

I am trying to convert a Seq2Seq model to TF-Lite, however I am facing some issues with the BeamSearchDecoder from tensorflow-addons. My model works fine in Python and the source code looks like this: 

```
class MySeq2SeqModel(tf.keras.models.Model):
    def __init__(self, vocab_size: int, input_len: int, output_len: int,
                 batch_size,
                 rnn_units: int = 64, dense_units: int = 64, embedding_dim: int = 256, **kwargs):
        super(MySeq2SeqModel, self).__init__(**kwargs)

        # Base Attributes
        self.vocab_size = vocab_size
        self.input_len = input_len
        self.output_len = output_len
        self.rnn_units = rnn_units
        self.dense_units = dense_units
        self.embedding_dim = embedding_dim
        self.batch_size = batch_size

        # Beam search attributes
        self.beam_width = 3

        # Encoder
        self.encoder_embedding = layers.Embedding(vocab_size, embedding_dim, input_length=input_len)
        self.encoder_rnn = layers.LSTM(rnn_units, return_sequences=True, return_state=True)

        # Decoder
        self.decoder_embedding = layers.Embedding(vocab_size, embedding_dim, input_length=output_len)
        self.decoder_rnncell = tf.keras.layers.LSTMCell(rnn_units)

        # Attention
        self.attention_mechanism = tfa.seq2seq.LuongAttention(dense_units)
        self.rnn_cell = self.build_rnn_cell(batch_size=batch_size)

        # Output
        self.dense_layer = tf.keras.layers.Dense(vocab_size)

        self.inference_decoder = BeamSearchDecoder(cell=self.rnn_cell,
                                                   beam_width=self.beam_width,
                                                   output_layer=self.dense_layer,
                                                   # As tf.nn.embedding_lookup is not supported by tflite
                                                   embedding_fn=lambda ids: tf.gather(tf.identity(
                                                       self.decoder_embedding.variables[0]), ids),
                                                   coverage_penalty_weight=0.0, dynamic=False, parallel_iterations=1,
                                                   maximum_iterations=output_len
                                                   )

    def call(self, inputs, training=None, mask=None):
        # Encoder
        encoder = self.encoder_embedding(inputs[0])
        encoder_outputs, state_h, state_c = self.encoder_rnn(encoder)
        decoder_emb = self.decoder_embedding(inputs[1])

        tiled_a = tfa.seq2seq.tile_batch(encoder_outputs, multiplier=self.beam_width)
        tiled_a_tx = tfa.seq2seq.tile_batch(state_h, multiplier=self.beam_width)
        tiled_c_tx = tfa.seq2seq.tile_batch(state_c, multiplier=self.beam_width)
        start_tokens = tf.fill([1], START_ID)

        self.attention_mechanism.setup_memory(tiled_a)

        final_output, final_state, _ = self.inference_decoder(embedding=None,
                                                              start_tokens=start_tokens,
                                                              end_token=EOS_ID,
                                                              initial_state=self.build_decoder_initial_state(
                                                                  size=1 * self.beam_width,
                                                                  encoder_state=[tiled_a_tx, tiled_c_tx],
                                                                  Dtype=tf.float32))

        return final_output.predicted_ids

```