tensorflow-onnx icon indicating copy to clipboard operation
tensorflow-onnx copied to clipboard

Cannot convert saved model that uses keras Preprocessing layer

Open tuanavu opened this issue 1 year ago • 5 comments

Conversion failed from saved model to onnx if the model use tf.keras.layers.IntegerLookup and tf.keras.layers.Discretization.

System information

  • Docker container: nvcr.io/nvidia/tensorflow:22.12-tf2-py3
  • OS Platform and Distribution (e.g., Linux Ubuntu 20.04)
  • Tensorflow Version: 2.10.1
  • Python version: 3.8.10
  • tf2onnx: Successfully installed tf2onnx-1.14.0

Details

There was some issue with Bucketize ops supported in ONNX, so I am using tf.keras.layers.IntegerLookup and tf.keras.layers.Discretization to replace tf.nn.embedding_lookup_sparse() and bucketize(). However, when I tried to convert the model

!python -m tf2onnx.convert --saved-model ./models/tf/ --output ./models/onnx/1/model.onnx \
--extra_opset ai.onnx.contrib:1 \
--verbose

I got this error

2023-08-18 00:23:04,200 - WARNING - tf2onnx.shape_inference: Cannot infer shape for StatefulPartitionedCall/model/preprocessing/emb_layer_33/integer_lookup_33/None_Lookup/LookupTableFindV2: StatefulPartitionedCall/model/preprocessing/emb_layer_33/integer_lookup_33/None_Lookup/LookupTableFindV2:0
2023-08-18 00:23:04,200 - WARNING - tf2onnx.shape_inference: Cannot infer shape for StatefulPartitionedCall/model/preprocessing/emb_layer_34/integer_lookup_34/None_Lookup/LookupTableFindV2: StatefulPartitionedCall/model/preprocessing/emb_layer_34/integer_lookup_34/None_Lookup/LookupTableFindV2:0
2023-08-18 00:23:04,201 - WARNING - tf2onnx.shape_inference: Cannot infer shape for StatefulPartitionedCall/model/preprocessing/emb_layer_46/SparseReduceSum: StatefulPartitionedCall/model/preprocessing/emb_layer_46/SparseReduceSum:0
2023-08-18 00:23:04,357 - INFO - tf2onnx.tf_utils: Computed 2 values for constant folding
2023-08-18 00:23:05,030 - INFO - tf2onnx.tfonnx: folding node using tf type=StridedSlice, name=StatefulPartitionedCall/model/prediction_head/layer_normalization_3/strided_slice_1
2023-08-18 00:23:05,030 - INFO - tf2onnx.tfonnx: folding node using tf type=StridedSlice, name=StatefulPartitionedCall/model/prediction_head/layer_normalization_4/strided_slice_1
2023-08-18 00:23:07,430 - VERBOSE - tf2onnx.tfonnx: Mapping TF node to ONNX node(s)
2023-08-18 00:23:07,449 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/discretization_99/Bucketize: Bucketize] is not supported
2023-08-18 00:23:07,450 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/discretization_98/Bucketize: Bucketize] is not supported
2023-08-18 00:23:07,465 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/discretization/Bucketize: Bucketize] is not supported
2023-08-18 00:23:07,476 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer/integer_lookup/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer/integer_lookup/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_137:0=HashTableV2, [], 7\n\targs_0_222=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_501:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer/integer_lookup/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:07,477 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer/integer_lookup/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:07,495 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:07,496 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_1/integer_lookup_1/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_1/integer_lookup_1/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_134:0=HashTableV2, [], 7\n\targs_0_225=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_498:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_1/integer_lookup_1/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:07,496 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_1/integer_lookup_1/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:07,515 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_1/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:07,516 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_2/integer_lookup_2/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_2/integer_lookup_2/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_131:0=HashTableV2, [], 7\n\targs_0_228=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_495:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_2/integer_lookup_2/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:07,516 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_2/integer_lookup_2/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:07,536 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_2/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:07,537 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_3/integer_lookup_3/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_3/integer_lookup_3/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_128:0=HashTableV2, [], 7\n\targs_0_231=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_492:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_3/integer_lookup_3/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:07,537 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_3/integer_lookup_3/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:07,991 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_25/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:07,991 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_26/integer_lookup_26/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_26/integer_lookup_26/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_59:0=HashTableV2, [], 7\n\targs_0_300=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_423:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_26/integer_lookup_26/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:07,992 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_26/integer_lookup_26/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:08,009 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_26/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,010 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_27/integer_lookup_27/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_27/integer_lookup_27/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_56:0=HashTableV2, [], 7\n\targs_0_303=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_420:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_27/integer_lookup_27/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:08,010 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_27/integer_lookup_27/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:08,029 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_27/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,030 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_28/integer_lookup_28/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_28/integer_lookup_28/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_53:0=HashTableV2, [], 7\n\targs_0_306=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_417:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_28/integer_lookup_28/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:08,030 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_28/integer_lookup_28/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:08,047 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_28/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,048 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_29/integer_lookup_29/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_29/integer_lookup_29/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_50:0=HashTableV2, [], 7\n\targs_0_309=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_414:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_29/integer_lookup_29/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:08,232 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_38/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,232 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_39/integer_lookup_39/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_39/integer_lookup_39/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_20:0=HashTableV2, [], 7\n\targs_0_339=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_384:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_39/integer_lookup_39/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:08,233 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_39/integer_lookup_39/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:08,250 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_39/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,250 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_40/integer_lookup_40/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_40/integer_lookup_40/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_17:0=HashTableV2, [], 7\n\targs_0_342=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_381:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_40/integer_lookup_40/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:08,251 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_40/integer_lookup_40/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:08,268 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_40/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,269 - ERROR - tf2onnx.tfonnx: Failed to convert node 'StatefulPartitionedCall/model/preprocessing/emb_layer_41/integer_lookup_41/None_Lookup/LookupTableFindV2' (fct=<bound method LookupTableFind.version_8 of <class 'tf2onnx.custom_opsets.onnx_ml.LookupTableFind'>>)
'OP=LookupTableFindV2\nName=StatefulPartitionedCall/model/preprocessing/emb_layer_41/integer_lookup_41/None_Lookup/LookupTableFindV2\nInputs:\n\tunknown_14:0=HashTableV2, [], 7\n\targs_0_345=Placeholder, [-1], 7\n\tFunc/StatefulPartitionedCall/input/_378:0=Const, [], 7\nOutpus:\n\tStatefulPartitionedCall/model/preprocessing/emb_layer_41/integer_lookup_41/None_Lookup/LookupTableFindV2:0=None, 7'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.
2023-08-18 00:23:08,269 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_41/integer_lookup_41/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:08,287 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_41/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,360 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_46/integer_lookup_46/count/SparseCountSparseOutput: SparseCountSparseOutput] is not supported
2023-08-18 00:23:08,378 - ERROR - tf2onnx.tfonnx: Tensorflow op [StatefulPartitionedCall/model/preprocessing/emb_layer_46/SparseReduceSum: SparseReduceSum] is not supported
2023-08-18 00:23:08,393 - ERROR - tf2onnx.tfonnx: Unsupported ops: Counter({'Bucketize': 221, 'SparseCountSparseOutput': 47, 'SparseReduceSum': 47})
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/convert.py", line 710, in <module>
    main()
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/convert.py", line 273, in main
    model_proto, _ = _convert_common(
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/convert.py", line 168, in _convert_common
    g = process_tf_graph(tf_graph, const_node_values=const_node_values,
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 464, in process_tf_graph
    g = process_graphs(main_g, subgraphs, custom_op_handlers, inputs_as_nchw, outputs_as_nchw, continue_on_error,
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 516, in process_graphs
    g = process_parsed_graph(main_g, custom_op_handlers, inputs_as_nchw, outputs_as_nchw, continue_on_error,
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 627, in process_parsed_graph
    raise exceptions[0]
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/custom_opsets/onnx_ml.py", line 45, in version_8
    utils.make_sure((dtype == TensorProto.INT64 and in_dtype == TensorProto.STRING) or
  File "/usr/local/lib/python3.8/dist-packages/tf2onnx/utils.py", line 264, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: Only lookup tables of type string<->int64 are currently supported.

tuanavu avatar Aug 18 '23 00:08 tuanavu

I have the same problem

witeko avatar Nov 04 '23 23:11 witeko

I am facing the same issue, any updates

kerocode avatar Feb 22 '24 18:02 kerocode

I also need this ONNX preprocess Discretization --> IntegerLookup

As far as I've looked around, ONNx has only enabled string lookup not integer look up If we have a way to change the Discretization --> IntegerLookup to StringLookup, that may work

jalola avatar Mar 14 '24 09:03 jalola

@jalola @tuanavu Any idea if this was fixed somethow?

eyalhir74 avatar Jul 03 '24 06:07 eyalhir74

Hi I did try cast_int_to_str + StringLookup to replace IntegerLookup and I was able to convert the model to ONNX

However, when I check the performance, the TF model is faster than ONNX model

This depends on model I think, my model has very a small backbone but it has a lot of preprocessing layers, that's why I think TF model can be faster than ONNX model as a whole. Of course, if only benchmarking the backbone, ONNX is faster.

If your model has big backbone, I think it can be beneficial to use ONNX.

Another option you can try is splitting the model into 2 part, 1 runs TF model, another runs ONNX model

jalola avatar Jul 03 '24 12:07 jalola