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

Add --builtins_only Flag to CLI for generating TFLITE_BUILTINS-Only TensorFlow Lite Models #707

Open
JihwanEom opened this issue Oct 11, 2024 · 3 comments
Labels
discussion Specification Discussion

Comments

@JihwanEom
Copy link

Issue Type

Feature Request

OS

Linux

onnx2tf version number

1.26.0

onnx version number

1.16.1

onnxruntime version number

1.18.1

onnxsim (onnx_simplifier) version number

0.4.33

tensorflow version number

2.17.0

Download URL for ONNX

N/A

Parameter Replacement JSON

N/A

Description

Hello!

I have been using onnx2tf very effectively it's extremely useful.

After converting a model from ONNX to TensorFlow Lite, I use TensorFlow Lite via GMS(Google Mobile Services) to minimize the required additional size of the app. Specifically, I use:

  • com.google.android.gms:play-services-tflite-java:16.1.0
  • com.google.android.gms:play-services-tflite-support:16.1.0

However, GMS only supports models built with tf.lite.OpsSet.TFLITE_BUILTINS. To work around this, I manually comment out the parts that include tf.lite.OpsSet.SELECT_TF_OPS (including other code that selects TensorFlow ops) in the following lines: https://github.com/PINTO0309/onnx2tf/blob/main/onnx2tf/onnx2tf.py#L1425-L1428

It would be very useful if a flag like --builtins_only could be supported in the CLI to enable this functionality easily.

Have a great weekend!

@PINTO0309 PINTO0309 added TODO TODO Lack of reproduction methods Lack of information or resources on how to reproduce labels Oct 11, 2024
@PINTO0309
Copy link
Owner

Any untrained model will do, just provide us with an ONNX file whose structure we can understand.

@PINTO0309 PINTO0309 removed the TODO TODO label Oct 11, 2024
@JihwanEom
Copy link
Author

Apologies for not providing a clear explanation earlier.
I would like to propose adding an option to onnx2tf that allows conversion to TensorFlow Lite using a --builtins-only flag.
This would enable users to convert models without selecting specific operations.
This is not a bug report, but rather a feature suggestion to offer more granular options for users.

In my case, to prevent an increase in app size, I intended to use the TensorFlow Lite built into Android (GMS). This requires converting the model using only built-in operations, which is why I am suggesting this feature.

Thank you for considering this proposal!

@PINTO0309
Copy link
Owner

PINTO0309 commented Oct 16, 2024

Is it your intention that a model will be generated whether you specify tf.lite.OpsSet.SELECT_TF_OPS or not, but that it's okay if a conversion error occurs if you don't specify it? Or do you mean combining multiple conversion options is too tedious?

I'm not rejecting your suggestion, just that I don't really understand the benefit of adding this new conversion option. This might make sense if you want to abort on an error if your model contains non-built-in operations.

I don't know the specifications of TensorFlow Lite via GMS(Google Mobile Services), so please tell me in detail what kind of difference in behavior occurs between models generated with and without tf.lite.OpsSet.SELECT_TF_OPS. This will be useful information for other onnx2tf users.

I'm currently out and about, so I can't check what difference there is in the definition information of the .tflite file depending on whether or not the options are specified.

@PINTO0309 PINTO0309 added discussion Specification Discussion and removed Lack of reproduction methods Lack of information or resources on how to reproduce labels Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Specification Discussion
Projects
None yet
Development

No branches or pull requests

2 participants