Issue 1:
Could you please make it a little bit clear for me

I am using pyhon generated code to read and get node attributes from the model graph.

I generated it this way (output is tflite/ folder with autogenerated *.py files):

flatc -python tensorflow/tensorflow/lite/schema/schema.fbs

Than I read the model:

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

Getting model parameters:

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)

Than I realized that graph nodes could be interpreted as Tensor object or Operator object.

Tensor object stores quantization params, shape, tensor type (I don't understand the meaning of it yet)

Operator object has BuiltinOptions and CustomOptions methods that seems to me should give me access to node parameters (such as paddings, dilations and all layer specific info)

I tried to iterate over them since there are Inputs and Outputs methods. But failed. I don't understand w

This is my scratch:

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 <= 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)

Please help me to get access the node attributes.

Thank you in advance for your help.

Issue 2:
Could you please make it a little bit clear for me

I am using pyhon generated code to read and get node attributes from the model graph.

I generated it this way (output is tflite/ folder with autogenerated *.py files):

flatc -python tensorflow/tensorflow/lite/schema/schema.fbs

Than I read the model:

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

Getting model parameters:

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)

Than I realized that graph nodes could be interpreted as Tensor object or Operator object.

Tensor object stores quantization params, shape, tensor type (I don't understand the meaning of it yet)

Operator object has BuiltinOptions and CustomOptions methods that seems to me should give me access to node parameters (such as paddings, dilations and all layer specific info)

I tried to iterate over them since there are Inputs and Outputs methods. But failed. I don't understand w

This is my scratch:

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 <= 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)

Please help me to get access the node attributes.

Thank you in advance for your help.