One: [onert] get a tensor index by a tensor name

Created on 21 Jul 2020  路  8Comments  路  Source: Samsung/ONE

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.

  • Method 1

    • Add a name member to the nnfw_tensorinfo structure.

    • Then, we can specify the tensor using nnfw_output_tensorinfo() and nnfw_input_tensorinfo().

  • Method 2

    • Implement a function to get the tensor index by tensor name.

    • For example, NNFW_STATUS nnfw_tensorindex(nnfw_session *session, const char *tensorname, uint32_t *index);

Thank you.

typsuggestion

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.

All 8 comments

Thank you for raising an issue and the suggestions. There are some points to think about:

  • Do we really need it?

    • As tensor names are just for debugging, it may be enough to introduce a function in nnfw_dev.h, not nnfw.h (Maybe we could move it to nnfw.h later)

  • If we introduce something like 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
  • Method 1 and Method 2 look different

    • Method 1 is to get a tensor name of a model input/output tensor

    • Method 2 is to get a tensor index with a tensor name

    • I guess you'd like to get tensor names of model inputs and outputs only?

@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.

  • Method 2 can provide this functionality directly.
  • If Method 1 is supported, I can implement Method 2 myself.
  • I don't know which method is better, but tflite provides Method 1.

@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.

  • Index in the subgraph (In circle/tflite, index of tensors in table Subgraph )
  • Index of the subgraph's I/O tensors (In circle/tflite, index of 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.

3391 is created for API design.

% 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanshpark picture seanshpark  路  3Comments

KimDongEon picture KimDongEon  路  4Comments

ragmani picture ragmani  路  4Comments

periannath picture periannath  路  3Comments

underflow101 picture underflow101  路  4Comments