Repository navigation
Description
1. System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): mac os Big Sur
- TensorFlow installation (pip package or built from source): pip package
- TensorFlow library (version, if pip package or github SHA, if built from source): 2.4.1
2. Code
Option B: Paste your code here or provide a link to a custom end-to-end colab
`converter = tf.lite.TFLiteConverter.from_saved_model('edr_cust_model_new/1625736127/') # path to the SavedModel directory
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
]
tflite_model = converter.convert()
// Save the model.
with open('edr_cust_model_temp/model.tflite', 'wb') as f:
f.write(tflite_model)`
3. Short Error log
I am getting following error while conversion:
ConverterError: :0: error: loc("boosted_trees"): 'tf.BoostedTreesEnsembleResourceHandleOp' op is neither a custom op nor a flex op
:0: error: loc("boosted_trees/BoostedTreesPredict"): 'tf.BoostedTreesPredict' op is neither a custom op nor a flex op
:0: error: loc("boosted_trees/head/predictions/str_classes"): 'tf.AsString' op is neither a custom op nor a flex op
:0: error: failed while converting: 'main': Ops that need custom implementation (enabled via setting the -emit-custom-ops flag):
tf.AsString {device = "", fill = "", precision = -1 : i64, scientific = false, shortest = false, width = -1 : i64}
tf.BoostedTreesEnsembleResourceHandleOp {container = "", device = "", shared_name = "boosted_trees/"}
tf.BoostedTreesPredict {device = "", logits_dimension = 7 : i64, num_bucketized_features = 18 : i64}
Activity
MeghnaNatraj commentedon Jul 12, 2021
It looks like the ops are not supported in TensorFlow as well. You need to follow the steps as given here in
2. Unsupported in TensorFlowgoogle-ml-butler commentedon Jul 12, 2021
Are you satisfied with the resolution of your issue?
Yes
No
Koushik667 commentedon Jul 14, 2021
Hi Meghna, Thanks for the reply
i followed the link, and tried to use register_custom_opdefs : But i am getting this
AttributeError Traceback (most recent call last)
in
4
5 # Register custom opdefs before the invocation of converter API.
----> 6 tf.lite.python.convert.register_custom_opdefs([custom_opdef])
AttributeError: module 'tensorflow._api.v2.lite' has no attribute 'python'
Can you please let me know if there is anything i can do?
Thanks,
Koushik
MeghnaNatraj commentedon Jul 14, 2021
@Koushik667 can you try running the following code?
(This usually wouldn't work as your ops are not defined in TF, but let's try)
@abattery (tagging you in case you have more context) If there is an op that is unsupported in TF, how can we convert the model successfully. The API used here (
tf.lite.python.convert.register_custom_opdefs([custom_opdef])) is not available to external users. It also looks like we have deprecated the olderconverter.custom_opdefs=...usage.abattery commentedon Jul 14, 2021
Adding them into the allowlist in the Select TF op support will be the easiest way to support. I think the above Boost tree ops are not included in the allowlist but we have AsString op as Select TF ops. I think we can consider this as a feature request for adding the additions of Boost tree ops in the allowlist of the Select TF ops.
Please consider using https://www.tensorflow.org/lite/guide/ops_select
MeghnaNatraj commentedon Jul 14, 2021
Thanks a lot @abattery!
@Koushik667 In TFLite, we maintain a list of TF operators (called the allowlist) that don't have a corresponding TFLite operator implementation (eg: such as the BoostedTreesEnsembleResourceHandleOp). If a TF operator is in this allowlist, then we can convert the model by pulling in the TF op into a TFLite model by adding the constant
tf.lite.OpsSet.SELECT_TF_OPS. (Note: this will lead to an increased model size) as follows:In your model, the operators used (eg: such as the BoostedTreesEnsembleResourceHandleOp) are not in this allowlist. Hence, though you set the above flag, it didn't work. To make this work, you need to follow the instructions in Update TFLite Ops Allowlist for TF Ops to add these operators to the allowlist. Once you complete this, your initial code should work as expected:
Note: once the update is made, you still need to follow instructions here when running inference to use these TF operators
google-ml-butler commentedon Jul 14, 2021
Are you satisfied with the resolution of your issue?
Yes
No