0

Reproduction Steps

  1. Setup environment
python3.10 -m venv venv
source activate venv/bin/activate
pip install -U pip
pip install tensorflow==2.8.0 tf2onnx==1.13.0 packaging==23.0
  1. Create a model with TextVectorizer
import tensorflow as tf

text_dataset = tf.data.Dataset.from_tensor_slices(["foo", "bar", "baz"])
vectorize_layer = tf.keras.layers.TextVectorization(max_tokens=100, output_mode='int', output_sequence_length=4)
vectorize_layer.adapt(text_dataset)

model = tf.keras.models.Sequential([
    tf.keras.Input(shape=(1,), dtype=tf.string),
    vectorize_layer
])

model.save("text_vectorizer")
  1. Try to convert the model to ONNX
python -m tf2onnx.convert --saved-model text_vectorizer --output text_vectorizer.onnx

Result:

<...>
/tf2onnx/lib/python3.10/site-packages/tf2onnx/tf_utils.py:58: FutureWarning: In the future `np.str` will be defined as the corresponding NumPy scalar.
  np_data = np_data.astype(np.str).astype(object)
Traceback (most recent call last):
  File "/tf2onnx/lib/python3.10/site-packages/tf2onnx/tf_utils.py", line 58, in tf_to_onnx_tensor
    np_data = np_data.astype(np.str).astype(object)
  File "/tf2onnx/lib/python3.10/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'str'.
`np.str` was a deprecated alias for the builtin `str`. To avoid this error in existing code, use `str` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.str_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'std'?

During handling of the above exception, another exception occurred:
<...>
  File "/tf2onnx/lib/python3.10/site-packages/tf2onnx/tf_utils.py", line 63, in tf_to_onnx_tensor
    raise RuntimeError("Not support type: {}".format(type(np_data.flat[0])))
RuntimeError: Not support type: <class 'bytes'>

How to fix the problem? Is there a way to make this conversion?

Maxim Blumental
  • 763
  • 5
  • 26

0 Answers0