tensorflow: CTC tensorflow lite conversion problem

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Ubuntu 19.04
  • TensorFlow installed from (source or binary):binary
  • TensorFlow version (or github SHA if from source): 2.0

Provide the text output from tflite_convert

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime and are not recognized by TensorFlow. If you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: . Here is a list of operators for which you will need custom implementations: CTC_BEAM_SEARCH_DECODER.```

Also, please include a link to a GraphDef or the model if possible.
import tensorflow as tf
class BasicModel(tf.Module):
  def __init__(self):
    self.const = None
  @tf.function(input_signature=[tf.TensorSpec(shape=[None,500,28], dtype=tf.float32),tf.TensorSpec(shape=[None,], dtype=tf.int32)])
  def decoder(self, logits,seq_len):
    decoded, log_prob = tf.nn.ctc_beam_search_decoder(logits, seq_len)
    return decoded
# Create the tf.Module object.
root = BasicModel()
# Get the concrete function.
concrete_func = root.decoder.get_concrete_function()
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
converter.allow_custom_ops = False
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS,tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model =converter.convert()

open("ctc_greedy_decoder.tflite",'wb').write(tflite_model)

**Any other info / logs**

But according to this link https://github.com/tensorflow/tensorflow/tree/r2.0/tensorflow/lite/experimental/kernels ctc_beam_search_decoder is registered as tflite op.

Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Hi @jdduke With the new version of TensorFlow 2.4 my conversion of CTC Decoder is successful by enabling TFLite Ops

converter.target_spec.supported_ops = [
          tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
          tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
      ]

My issue is solved. You can check this OCR Notebook where I successfully used and converted CTC Decoder to TFLite.