<p dir="auto">Could you please make it a little bit clear for me</p>
<p dir="auto">I am using pyhon generated code to read and get node attributes from the model graph.</p>
<p dir="auto">I generated it this way (output is <code class="notranslate">tflite/</code> folder with autogenerated *.py files):<br>
<code class="notranslate">flatc -python tensorflow/tensorflow/lite/schema/schema.fbs</code></p>
<p dir="auto">Than I read the model:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    from tflite.Model import Model
    def read_tflite_model(file):
        buf = open(file, &quot;rb&quot;).read()
        buf = bytearray(buf)
        model = Model.GetRootAsModel(buf, 0)
        return model
"><pre class="notranslate"><code class="notranslate">    from tflite.Model import Model
    def read_tflite_model(file):
        buf = open(file, "rb").read()
        buf = bytearray(buf)
        model = Model.GetRootAsModel(buf, 0)
        return model

</code></pre></div>
<p dir="auto">Getting model parameters:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    def print_model_info(model):
        version = model.Version()
        print(&quot;Model version:&quot;, version)
        description = model.Description().decode('utf-8')
        print(&quot;Description:&quot;, description)
        subgraph_len = model.SubgraphsLength()
        print(&quot;Subgraph length:&quot;, subgraph_len)
"><pre class="notranslate"><code class="notranslate">    def print_model_info(model):
        version = model.Version()
        print("Model version:", version)
        description = model.Description().decode('utf-8')
        print("Description:", description)
        subgraph_len = model.SubgraphsLength()
        print("Subgraph length:", subgraph_len)

</code></pre></div>
<p dir="auto">Than I realized that graph nodes could be interpreted as <code class="notranslate">Tensor</code> object or <code class="notranslate">Operator</code> object.</p>
<p dir="auto"><code class="notranslate">Tensor</code> object stores quantization params, shape, tensor type (I don't understand the meaning of it yet)</p>
<p dir="auto"><code class="notranslate">Operator</code> object has <code class="notranslate">BuiltinOptions</code> and <code class="notranslate">CustomOptions</code> methods that seems to me should give me access to node parameters (such as paddings, dilations and all layer specific info)</p>
<p dir="auto">I tried to iterate over them since there are Inputs and Outputs methods. But failed. I don't understand w</p>
<p dir="auto">This is my scratch:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def print_nodes_info(model):
    # what does this 0 mean? should it always be zero?
    subgraph = model.Subgraphs(0)
    operators_len = subgraph.OperatorsLength()
    print('Operators length:', operators_len)

    from collections import deque
    nodes = deque(subgraph.InputsAsNumpy())

    STEP_N = 0
    MAX_STEPS = operators_len
    print(&quot;Nodes info:&quot;)
    while len(nodes) != 0 and STEP_N &lt;= MAX_STEPS:
        print(&quot;MAX_STEPS={} STEP_N={}&quot;.format(MAX_STEPS, STEP_N))
        print(&quot;-&quot; * 60)

        node_id = nodes.pop()
        print(&quot;Node id:&quot;, node_id)

        tensor = subgraph.Tensors(node_id)
        print(&quot;Node name:&quot;, tensor.Name().decode('utf-8'))
        print(&quot;Node shape:&quot;, tensor.ShapeAsNumpy())

        # which type is it? what does it mean?
        type_of_tensor = tensor.Type()
        print(&quot;Tensor type:&quot;, type_of_tensor)

        quantization = tensor.Quantization()
        min = quantization.MinAsNumpy()
        max = quantization.MaxAsNumpy()
        scale = quantization.ScaleAsNumpy()
        zero_point = quantization.ZeroPointAsNumpy()
        print(&quot;Quantization: ({}, {}), s={}, z={}&quot;.format(min, max, scale, zero_point))

        # I do not understand it again. what is j, that I set to 0 here?
        operator = subgraph.Operators(0)
        for i in operator.OutputsAsNumpy():
            nodes.appendleft(i)

        STEP_N += 1

    print(&quot;-&quot;*60)
"><pre class="notranslate"><code class="notranslate">def print_nodes_info(model):
    # what does this 0 mean? should it always be zero?
    subgraph = model.Subgraphs(0)
    operators_len = subgraph.OperatorsLength()
    print('Operators length:', operators_len)

    from collections import deque
    nodes = deque(subgraph.InputsAsNumpy())

    STEP_N = 0
    MAX_STEPS = operators_len
    print("Nodes info:")
    while len(nodes) != 0 and STEP_N &lt;= MAX_STEPS:
        print("MAX_STEPS={} STEP_N={}".format(MAX_STEPS, STEP_N))
        print("-" * 60)

        node_id = nodes.pop()
        print("Node id:", node_id)

        tensor = subgraph.Tensors(node_id)
        print("Node name:", tensor.Name().decode('utf-8'))
        print("Node shape:", tensor.ShapeAsNumpy())

        # which type is it? what does it mean?
        type_of_tensor = tensor.Type()
        print("Tensor type:", type_of_tensor)

        quantization = tensor.Quantization()
        min = quantization.MinAsNumpy()
        max = quantization.MaxAsNumpy()
        scale = quantization.ScaleAsNumpy()
        zero_point = quantization.ZeroPointAsNumpy()
        print("Quantization: ({}, {}), s={}, z={}".format(min, max, scale, zero_point))

        # I do not understand it again. what is j, that I set to 0 here?
        operator = subgraph.Operators(0)
        for i in operator.OutputsAsNumpy():
            nodes.appendleft(i)

        STEP_N += 1

    print("-"*60)

</code></pre></div>
<p dir="auto">Please help me to get access the node attributes.<br>
Thank you in advance for your help.</p>
<p dir="auto">Could you please make it a little bit clear for me</p>
<p dir="auto">I am using pyhon generated code to read and get node attributes from the model graph.</p>
<p dir="auto">I generated it this way (output is <code class="notranslate">tflite/</code> folder with autogenerated *.py files):<br>
<code class="notranslate">flatc -python tensorflow/tensorflow/lite/schema/schema.fbs</code></p>
<p dir="auto">Than I read the model:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    from tflite.Model import Model
    def read_tflite_model(file):
        buf = open(file, &quot;rb&quot;).read()
        buf = bytearray(buf)
        model = Model.GetRootAsModel(buf, 0)
        return model
"><pre class="notranslate"><code class="notranslate">    from tflite.Model import Model
    def read_tflite_model(file):
        buf = open(file, "rb").read()
        buf = bytearray(buf)
        model = Model.GetRootAsModel(buf, 0)
        return model

</code></pre></div>
<p dir="auto">Getting model parameters:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    def print_model_info(model):
        version = model.Version()
        print(&quot;Model version:&quot;, version)
        description = model.Description().decode('utf-8')
        print(&quot;Description:&quot;, description)
        subgraph_len = model.SubgraphsLength()
        print(&quot;Subgraph length:&quot;, subgraph_len)
"><pre class="notranslate"><code class="notranslate">    def print_model_info(model):
        version = model.Version()
        print("Model version:", version)
        description = model.Description().decode('utf-8')
        print("Description:", description)
        subgraph_len = model.SubgraphsLength()
        print("Subgraph length:", subgraph_len)

</code></pre></div>
<p dir="auto">Than I realized that graph nodes could be interpreted as <code class="notranslate">Tensor</code> object or <code class="notranslate">Operator</code> object.</p>
<p dir="auto"><code class="notranslate">Tensor</code> object stores quantization params, shape, tensor type (I don't understand the meaning of it yet)</p>
<p dir="auto"><code class="notranslate">Operator</code> object has <code class="notranslate">BuiltinOptions</code> and <code class="notranslate">CustomOptions</code> methods that seems to me should give me access to node parameters (such as paddings, dilations and all layer specific info)</p>
<p dir="auto">I tried to iterate over them since there are Inputs and Outputs methods. But failed. I don't understand w</p>
<p dir="auto">This is my scratch:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def print_nodes_info(model):
    # what does this 0 mean? should it always be zero?
    subgraph = model.Subgraphs(0)
    operators_len = subgraph.OperatorsLength()
    print('Operators length:', operators_len)

    from collections import deque
    nodes = deque(subgraph.InputsAsNumpy())

    STEP_N = 0
    MAX_STEPS = operators_len
    print(&quot;Nodes info:&quot;)
    while len(nodes) != 0 and STEP_N &lt;= MAX_STEPS:
        print(&quot;MAX_STEPS={} STEP_N={}&quot;.format(MAX_STEPS, STEP_N))
        print(&quot;-&quot; * 60)

        node_id = nodes.pop()
        print(&quot;Node id:&quot;, node_id)

        tensor = subgraph.Tensors(node_id)
        print(&quot;Node name:&quot;, tensor.Name().decode('utf-8'))
        print(&quot;Node shape:&quot;, tensor.ShapeAsNumpy())

        # which type is it? what does it mean?
        type_of_tensor = tensor.Type()
        print(&quot;Tensor type:&quot;, type_of_tensor)

        quantization = tensor.Quantization()
        min = quantization.MinAsNumpy()
        max = quantization.MaxAsNumpy()
        scale = quantization.ScaleAsNumpy()
        zero_point = quantization.ZeroPointAsNumpy()
        print(&quot;Quantization: ({}, {}), s={}, z={}&quot;.format(min, max, scale, zero_point))

        # I do not understand it again. what is j, that I set to 0 here?
        operator = subgraph.Operators(0)
        for i in operator.OutputsAsNumpy():
            nodes.appendleft(i)

        STEP_N += 1

    print(&quot;-&quot;*60)
"><pre class="notranslate"><code class="notranslate">def print_nodes_info(model):
    # what does this 0 mean? should it always be zero?
    subgraph = model.Subgraphs(0)
    operators_len = subgraph.OperatorsLength()
    print('Operators length:', operators_len)

    from collections import deque
    nodes = deque(subgraph.InputsAsNumpy())

    STEP_N = 0
    MAX_STEPS = operators_len
    print("Nodes info:")
    while len(nodes) != 0 and STEP_N &lt;= MAX_STEPS:
        print("MAX_STEPS={} STEP_N={}".format(MAX_STEPS, STEP_N))
        print("-" * 60)

        node_id = nodes.pop()
        print("Node id:", node_id)

        tensor = subgraph.Tensors(node_id)
        print("Node name:", tensor.Name().decode('utf-8'))
        print("Node shape:", tensor.ShapeAsNumpy())

        # which type is it? what does it mean?
        type_of_tensor = tensor.Type()
        print("Tensor type:", type_of_tensor)

        quantization = tensor.Quantization()
        min = quantization.MinAsNumpy()
        max = quantization.MaxAsNumpy()
        scale = quantization.ScaleAsNumpy()
        zero_point = quantization.ZeroPointAsNumpy()
        print("Quantization: ({}, {}), s={}, z={}".format(min, max, scale, zero_point))

        # I do not understand it again. what is j, that I set to 0 here?
        operator = subgraph.Operators(0)
        for i in operator.OutputsAsNumpy():
            nodes.appendleft(i)

        STEP_N += 1

    print("-"*60)

</code></pre></div>
<p dir="auto">Please help me to get access the node attributes.<br>
Thank you in advance for your help.</p>