RSVP for your your local TensorFlow Everywhere event today!

Supported Select TensorFlow operators

TensorFlow core operators

The following is an exhaustive list of TensorFlow core operations that are supported by TensorFlow Lite runtime with the Select TensorFlow Ops feature.

TensorFlow Text and SentencePiece operators

The following TensorFlow Text and SentencePiece operators are supported if you use the Python API for conversion and import those libraries.

TF.Text operators:

  • CaseFoldUTF8
  • ConstrainedSequence
  • MaxSpanningTree
  • NormalizeUTF8
  • NormalizeUTF8WithOffsetsMap
  • RegexSplitWithOffsets
  • RougeL
  • SentenceFragments
  • SentencepieceOp
  • SentencepieceTokenizeOp
  • SentencepieceTokenizeWithOffsetsOp
  • SentencepieceDetokenizeOp
  • SentencepieceVocabSizeOp
  • SplitMergeTokenizeWithOffsets
  • UnicodeScriptTokenizeWithOffsets
  • WhitespaceTokenizeWithOffsets
  • WordpieceTokenizeWithOffsets

SentencePiece operators:

  • SentencepieceGetPieceSize
  • SentencepiecePieceToId
  • SentencepieceIdToPiece
  • SentencepieceEncodeDense
  • SentencepieceEncodeSparse
  • SentencepieceDecode

The following snippet shows how to convert models with the above operators:

import tensorflow as tf
# These imports are required to load operators' definition.
import tensorflow_text as tf_text
import sentencepiece as spm

converter = tf.lite.TFLiteConverter.from_keras_model(your_model)
converter.target_spec.supported_ops = [
  tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS
]
model_data = converter.convert()

On the runtime side, it is also required to link the TensorFlow Text or SentencePiece library into the final app or binary.

User's defined Operators

If you created your own TensorFlow operators, you can also convert models containing them to TensorFlow Lite by listing required operators in the experimental_select_user_tf_ops as following:

import tensorflow as tf

ops_module = tf.load_op_library('./your_ops_library.so')

converter = tf.lite.TFLiteConverter.from_saved_model(your_model)
converter.target_spec.supported_ops = [
  tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS
]
converter.target_spec.experimental_select_user_tf_ops = [
    'your_op_name1',
    'your_op_name2'
]
model_data = converter.convert()

On the runtime side, it is also required to link your operators library into the final app or binary.