Hello.
Sometimes, a tflite converter changes the tensor index, when using a model with multiple inputs and outputs.
In this case, the tensor index should be hard-coded or specified by the tensor shape.
So, it will be very useful to get the tensor index as the tensor name.
For example, using tflite python API, we can get a tensor info by interpreter.get_input_details() as below.
{'name': 'in_feature', 'index': 0, 'shape': array([ 1, 5, 22], dtype=int32), 'shape_signature': array([ 1, 5, 22], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}
But, nnfw_tensorinfo struct has only dtype, rank and dims.
name member to the nnfw_tensorinfo structure.nnfw_output_tensorinfo() and nnfw_input_tensorinfo().NNFW_STATUS nnfw_tensorindex(nnfw_session *session, const char *tensorname,
uint32_t *index);Thank you.
Thank you for raising an issue and the suggestions. There are some points to think about:
nnfw_dev.h, not nnfw.h (Maybe we could move it to nnfw.h later)nnfw_tensorindex, it should be only valid when the session state is MODEL_LOADED since after nnfw_prepare is called, the graph could have transformed@wateret Thank you for summary. Actually, I want to get the tensor index by each tensor name, because I can determine the tensor name, but not tensor index. But, nnfw_set_input and nnfw_set_output need the tensor index.
Method 1 and Method 2 might be different approaches.
@wateret
I think it would be better to provide a way to get input and output index from input and output name because it is convenient and flexible for app developer.
Tensorflow lite python API provides interpreter.get_input_details() and interpreter.get_output_details().
I've make use of the returned details to identify the input/output index from name when I developed gen_golden.py.
I guess you'd like to get tensor names of model inputs and outputs only?
I also think input and output of model is enough (by Method 1).
From the opinions from @sj0-park and @glistening , I will try to create an API for that. Designing API should be careful for Method 1, I think. I will create an issue for that.
@sj0-park What I wanted to clarify was that Method 1 is just for model I/O tensors but Method 2 is for all the tensors in the model. Please note that there are two types of tensor indices.
tensors in table Subgraph )tensors in table Subgraph)% For single subgraph models, "model I/O tensors" == "subgraph I/O tensors"
Anyway, from your comments, it looks like getting just model I/O tensor names is enough.
@glistening @wateret Sorry for confusing you. Right. I need the index of the I/O tensor, not intermediate tensor, to use it when calling nnfw_input_tensorinfo, nnfw_output_tensorinfo.
% For single subgraph models, "model I/O tensors" == "subgraph I/O tensors"
A just additional information
% For multiple subgraphs models with controlflow operations, "model I/O tensors" == "primary(main) subgraph I/O tensors"
@sj0-park #3748 is landed. It will be included as an experimental API in Release 1.9.0.
Most helpful comment
@glistening @wateret Sorry for confusing you. Right. I need the index of the I/O tensor, not intermediate tensor, to use it when calling
nnfw_input_tensorinfo,nnfw_output_tensorinfo.