One: Compiler FE: support Shape op in luci-interpreter

Created on 16 Dec 2020  路  4Comments  路  Source: Samsung/ONE

What

We need to support Shape op in luci-interpreter.

Why

When we test release binary, one of those model we run is inception_v3. You can get it with below command.

wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz
tar zxvf inception_v3_2018_04_27.tgz

There is no problem with tensorflow 1.x version but with tensorflow 2.x it's got different result.

./one-import-tf -i inception_v3.pb -o inception_v3.circle \
-I input -S 1,299,299,3 -O InceptionV3/Predictions/Reshape_1 \
--v2

image

Since the network has Shape operator, it throws NYI error when I run record-minmax with it.

I'd appreciate if you could support this feature.

help wanted

All 4 comments

The problem stems from the dynamic shape API in TFLite.

TF 2.X automatically generates those weird operators (Squeeze, Reshape, Shape) to support dynamic shape in TFLite. This is somewhat strange because we've given the static input shape to one-import-tf (-S 1,299,299,3 in the above example).

I've found out that currently tf2tfliteV2.py ignores input_shape option if it is called with --v2. I guess this is because there is no option to specify input shape in TF 2.0. Preferred workaround is to directly set shape in the graph.
https://github.com/tensorflow/tensorflow/issues/30180#issuecomment-505959220

I've checked that the shape-changing operators (squeeze, reshape, shape) are not generated if the workaround is used. So, how about adding the workaround to tf2tfliteV2.py ? Maybe I can make a change for that.

@mhs4670go #5394 may have solved the problem of this issue. Do you still want to implement SHAPE Op in luci-interpreter?

5394 may have solved the problem of this issue.

For TF models, it will work. What about tflite files that wasn't converted by our tool?

What about tflite files that wasn't converted by our tool?

The official inception v3 tflite model does not have SHAPE Op, so it may not fail.

For other models with SHAPE Op, circle-quantizer may fail. I'll support it. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jinevening picture jinevening  路  3Comments

mhs4670go picture mhs4670go  路  3Comments

underflow101 picture underflow101  路  4Comments

hasw7569 picture hasw7569  路  4Comments

periannath picture periannath  路  3Comments