Python TFLite—我可以直接通过TF2.0 API获取图形层序列信息吗?

Python TFLite—我可以直接通过TF2.0 API获取图形层序列信息吗?,python,tensorflow,tensorflow2.0,tensorflow-lite,Python,Tensorflow,Tensorflow2.0,Tensorflow Lite,我想知道是否有可能以及如何从.tflite文件中提取图形层的顺序,我目前正试图通过Tensorflow2 API直接提取这些信息 import tensorflow as tf interpreter = tf.lite.Interpreter(model_path=model_path) layer_details = interpreter.get_tensor_details() interpreter.allocate_tensors() for layer in layer_de

我想知道是否有可能以及如何从.tflite文件中提取图形层的顺序,我目前正试图通过Tensorflow2 API直接提取这些信息

import tensorflow as tf

interpreter = tf.lite.Interpreter(model_path=model_path)

layer_details = interpreter.get_tensor_details()
interpreter.allocate_tensors()

for layer in layer_details:
      print("\nLayer Name: {}".format(layer['name']))
      print("\tIndex: {}".format(layer['index']))
      print("\n\tShape: {}".format(layer['shape']))
      print("\tTensor: {}".format(interpreter.get_tensor(layer['index']).shape))
      print("\tTensor Type: {}".format(interpreter.get_tensor(layer['index']).dtype))
      print("\tQuantisation Parameters")
      print("\t\tScales: {}".format(layer['quantization_parameters']['scales'].shape))
      print("\t\tScales Type: {}".format(layer['quantization_parameters']['scales'].dtype))
      print("\t\tZero Points: {}".format(layer['quantization_parameters']['zero_points']))
      print("\t\tQuantized Dimension: {}".format(layer['quantization_parameters']['quantized_dimension']))
输出结果:

Layer Name: Identity_int8
        Index: 0

        Shape: [ 1 15]
        Tensor: (1, 15)
        Tensor Type: int8
        Quantisation Parameters
                Scales: (1,)
                Scales Type: float32
                Zero Points: [-128]
                Quantized Dimension: 0

Layer Name: reshape_input_int8
        Index: 1

        Shape: [  1   2 256]
        Tensor: (1, 2, 256)
        Tensor Type: int8
        Quantisation Parameters
                Scales: (1,)
                Scales Type: float32
                Zero Points: [-2]
                Quantized Dimension: 0
。。。等

然而,这些层的执行顺序与它们在图中的执行顺序不同,我不确定索引与实际图顺序的关系

当检查“get_input_details”和“get_output_details”时,我发现输入和输出分别对应于索引20和21

我还使用flatc编译器将tflite文件转换为json,如下所示:

flatc -t schema.fbs model.tflite
转换后的json模型中有额外的信息,例如缓冲区编号,但这似乎也与层顺序无关


有没有人对我应该从这里搬到哪里有什么建议?干杯

您似乎知道自己在做什么,因为您已经打印了输入和输出详细信息。您是否尝试在培训后使用Tensorboard将图形可视化,并将其与输入和输出详细信息进行比较?似乎您知道自己在做什么,因为您已经打印了输入和输出详细信息。您是否尝试过在培训后使用Tensorboard可视化图形,并将其与您的输入和输出详细信息进行比较?