Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[one-optimize] shape changed <-1x...> to <0x...> after pad op #13573

Open
zetwhite opened this issue Aug 1, 2024 · 10 comments
Open

[one-optimize] shape changed <-1x...> to <0x...> after pad op #13573

zetwhite opened this issue Aug 1, 2024 · 10 comments

Comments

@zetwhite
Copy link
Contributor

zetwhite commented Aug 1, 2024

What?

While converting mobileNetV2 tflite to circle file, ? 0 appeared in the shape of Pad's output.

  • I found this issue while trying : tflite -> circle -> optimized circle

  • tflite

  • circle

  • optimized circle

    • suddenly ? appeared in output of pad shape

How to reproduce

  • (+) Here is tflite file and cfg for onecc

  • get mobile-net-v2 tflite file

     import tensorflow as tf 
     
     mv2 = tf.keras.applications.MobileNetV2(
         input_shape=(224, 224, 3),
     )
     
     converter= tf.lite.TFLiteConverter.from_keras_model(mv2)
     tflite_model = converter.convert()
     
     with open('mv2.tflite', 'wb') as f: 
       f.write(tflite_model)
  • convert to circle

    • save as mv.cfg and run onecc -C mv.cfg
    • I tested with onecc version 1.28.0.
     [onecc]
     one-import-tflite=True
     one-optimize=True
     
     [one-import-tflite]
     model_format=tflite
     input_path=mv2.tflite
     output_path=mv2.circle
     input_arrays=input
     input_shapes=1,224,224,3
     output_arrays=predictions
     converter_version=v2
     
     [one-optimize]
     input_path=mv2.circle
     output_path=mv2.opt.circle
    
@seanshpark
Copy link
Contributor

suddenly ? appeared in output of pad shape

Have you recently updated Netron?
Or, do you have circle model without ? ?

@zetwhite
Copy link
Contributor Author

zetwhite commented Aug 1, 2024

I also checked circledump log, and the output of pad is <0X113x113x96> in the log.
It looks like 0 is expressed as ? in netron.

➜ circledump mv2.opt.circle | grep -A 5 PAD 

O(0:4) PAD 
    I T(0:12) mobilenetv2_1.00_224/block_1_expand_relu/Relu6;mobilenetv2_1.00_224/block_1_expand_BN/FusedBatchNormV3;mobilenetv2_1.00_224/block_12_project/Conv2D;mobilenetv2_1.00_224/block_1_expand/Conv2D
    I T(0:13) mobilenetv2_1.00_224/block_13_pad/Pad/paddings
    O T(0:14) mobilenetv2_1.00_224/block_1_pad/Pad
➜ circledump mv2.opt.circle | grep 'T(0:14) FLOAT32'
T(0:14) FLOAT32 (0, 113, 113, 96) B(15) mobilenetv2_1.00_224/block_1_pad/Pad

@zetwhite
Copy link
Contributor Author

zetwhite commented Aug 1, 2024

Have you recently updated Netron?

No, I didn't update Netron, recently.

Or, do you have circle model without ?

Before running one-optimize, the circle model does not have ?.

@seanshpark
Copy link
Contributor

seanshpark commented Aug 1, 2024

you could download and reproduce it
mobile_net.zip

from attached tflite file, I see it begins with unknown

image

I am using Netron 7.8.1, Windows version.

with circle file from tflite2cicle,

circledump gave me

Operands: T(subgraph index : tensor index) TYPE (shape) (shape_signature) B(buffer index) (variable) OperandName
T(0:0) FLOAT32 (1, 224, 224, 3) (-1, 224, 224, 3) B(1) serving_default_input_1:0

where -1 in (-1, 224, 224, 3) is for unknown.

@zetwhite
Copy link
Contributor Author

zetwhite commented Aug 1, 2024

Thank you for checking.
If you don't mind could you check the shape of mv2.opt.circle (optimized circle)?

I figured out my netron version is old ( I used netron 7.4... ).
And when I checked with https://netron.app (netron 7.8.1), -1 changed to 0 after pad op.

(+) I changed this issue's title, because I figured out that the problem is that the shape changed -1 to 0 after pad node. ? or 1 .. is just from netron version. sorry for confusion.

@zetwhite zetwhite changed the title [one-optimize] shape starts with ? appeared after one-optimize [one-optimize] shape changed to <1x...> to <0x...> after pad op Aug 1, 2024
@seanshpark
Copy link
Contributor

-1 changed to 0 after pad op.

Yes, reproduced. I'll analysis the cause...

@zetwhite zetwhite changed the title [one-optimize] shape changed to <1x...> to <0x...> after pad op [one-optimize] shape changed to <-1x...> to <0x...> after pad op Aug 1, 2024
@seanshpark
Copy link
Contributor

Current implementation has a bug with unknown shape. it doesn't check it's status(unknown/known).
Main cause is that circle we are (only) interested with known shapes (for our NPU backend).

I assume there will be other Ops that will have this same error.

Are you urgent with this issue? If not, fix will go with low urgency.

@zetwhite
Copy link
Contributor Author

zetwhite commented Aug 1, 2024

Are you urgent with this issue? If not, fix will go with low urgency.

It is NOT urgent. Fixing it slowly doesn't problem at all.

@zetwhite zetwhite changed the title [one-optimize] shape changed to <-1x...> to <0x...> after pad op [one-optimize] shape changed <-1x...> to <0x...> after pad op Aug 1, 2024
@zetwhite
Copy link
Contributor Author

This issue might be related - #5683

@shs-park
Copy link
Contributor

This issue might be related to #13697

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants