During using select_operator.py, I've met the empty input,
$ cat in
0
$ tools/tflitefile_tool/select_operator.py c.tflite in out.tflite
Input tensor(s): []
Output tensor(s): [2]
Append subgraphs, old index : 0 , new index : 0
By adding the following print:
diff --git a/tools/tflitefile_tool/select_operator.py b/tools/tflitefile_tool/select_operator.py
index dccb3454f..9fd01e8d7 100755
--- a/tools/tflitefile_tool/select_operator.py
+++ b/tools/tflitefile_tool/select_operator.py
@@ -1357,7 +1357,9 @@ def main(args):
if input_tensor_idx in new_output_tensors:
new_output_tensors.remove(input_tensor_idx)
if input_tensor_idx in new_input_tensors:
+ print(f'input_tensor_idx = {input_tensor_idx}')
matched_buffer_idx = sample_subgraph.Tensors(input_tensor_idx).Buffer()
+ print(f'matched_buffer_idx = {matched_buffer_idx}')
matched_buffer = sample_model.Buffers(matched_buffer_idx)
if matched_buffer_idx == 0 or matched_buffer.DataLength() != 0:
new_input_tensors.remove(input_tensor_idx)
I've find why.
input_tensor_idx = 0
matched_buffer_idx = 0
input_tensor_idx = 7
matched_buffer_idx = 7
Input tensor(s): []
Output tensor(s): [2]
Append subgraphs, old index : 0 , new index : 0
By removing matched_buffer_idx == 0 in the following:
diff --git a/tools/tflitefile_tool/select_operator.py b/tools/tflitefile_tool/select_operator.py
index dccb3454f..ab7953a46 100755
--- a/tools/tflitefile_tool/select_operator.py
+++ b/tools/tflitefile_tool/select_operator.py
@@ -1359,7 +1359,7 @@ def main(args):
if input_tensor_idx in new_input_tensors:
matched_buffer_idx = sample_subgraph.Tensors(input_tensor_idx).Buffer()
matched_buffer = sample_model.Buffers(matched_buffer_idx)
- if matched_buffer_idx == 0 or matched_buffer.DataLength() != 0:
+ if matched_buffer.DataLength() != 0:
new_input_tensors.remove(input_tensor_idx)
for output_idx in range(operator.OutputsLength()):
I succeed to select the operator.
$ tools/tflitefile_tool/select_operator.py cpn_1221.real.channel.q16.circle in out.tflite
Input tensor(s): [0]
Output tensor(s): [2]
Append subgraphs, old index : 0 , new index : 0
Does anyone let me know why matched_buffer_idx == 0 condition is here? (cc @hseok-oh)
I know that buffer index of zero means no data buffer from schema.fbs.
table Tensor {
...
// if there is no data buffer associated (i.e. intermediate results), then
// this is 0 (which refers to an always existent empty buffer).
...
buffer:uint;
I tried to find side effect by removing zero buffer index condition. However, I cannot find the case.
That code comes from https://github.com/Samsung/ONE/pull/4610
@hseok-oh Thank you for reference. I should have look the modification author before guessing you're the author of this line. : )
Hmm, #4610 says _"Fix a bug when buffer index is 0"_ , however it does not provide more information about the bug. In addition, #4610 has several changes in one PR. It is hard to the reason. Furthermore, @ragmani is not working with us at least this year.
I will push a PR to correct the bug so that someone who met same error in this issue can use the solution.
@glistening I reported #7256 about buffer index zero and #7257 will fix. #4610 looks valid implementation.
I've met this problem with some internal models. They have tensors whose buffer index is zero.
T(0:42) UINT8 (1, 48, 80, 128) B(0) conv_dw_2_7relu/Relu // B(idx) -> B == buffer
Quantization: scale(0.034545) zeropt(0) quantized_dimension(0)
Actually, this issue was from circle2circle(fixed in #7257). Our internal models were optimized by circle2circle that exported zero idx buffer. So, we should change the models to right one that is optimized by fixed circle2circle.
Most helpful comment
@glistening I reported #7256 about buffer index zero and #7257 will fix. #4610 looks valid implementation.