tensorflowtensorflow-lite

List operations of a TFLite model


I'm having trouble trying to list the operations of a TFLite model. I know operations can be listed given a frozen graph, but what about a TFLite .tflite model? Can operations be listed?


Solution

  • As mentioned in the TensorFlow Lite docs, you need to use a tf.lite.Interpreter to parse a .tflite model.

    # Load TFLite model and allocate tensors.
    interpreter = tf.lite.Interpreter(model_path="converted_model.tflite")
    interpreter.allocate_tensors()
    

    Then use the get_tensor_details method to get the list of Tensors.

    interpreter.get_tensor_details()
    

    As per the docs,

    Gets tensor details for every tensor with valid tensor details. Tensors where required information about the tensor is not found are not added to the list. This includes temporary tensors without a name.

    Returns: A list of dictionaries containing tensor information.