-1

I am attempting to run inference on my .onnx model converted from a keras' multi-label text classification model using https://keras.io/examples/nlp/multi_label_classification/. This is a text classification model that takes in text and provides a predicted category.

I am following this tutorial here: https://github.com/onnx/keras-onnx/blob/master/tutorial/TensorFlow_Keras_MNIST.ipynb BUT I am not sure what I am missing with regards to finding the format for 'feed'.

enter image description here

The keras model looks like this:

def make_model():
shallow_mlp_model = keras.Sequential(
    [
        layers.Dense(512, activation="relu"),
        layers.Dense(256, activation="relu"),
        layers.Dense(lookup.vocabulary_size(), activation="sigmoid"),
    ]  
)
return shallow_mlp_model
lm231
  • 29
  • 6

1 Answers1

1

The feed is a dictionary of input name to data. In the original tutorial the data for the input named 'dense_input' was created with this:

data = [digit_image.astype(np.float32)]

The data needs to be a numpy array as ONNX Runtime knows nothing about BatchDataset (based on the output in your question that's the type returned by make_dataset).

Scott McKay
  • 190
  • 1
  • 8
  • would you have any idea of how to run inference using an onnx model created using the https://keras.io/examples/nlp/multi_label_classification/ tutorial, seeing that it uses BatchDataset that can't be converted to numpy arrays – lm231 Sep 12 '22 at 19:59
  • I am not familiar with BatchDataset, but some basic searching reveals the Dataset type has a way to iterate it as numpy arrays, and there is an 'unbatch' method. https://www.tensorflow.org/api_docs/python/tf/data/Dataset#as_numpy_iterator https://www.tensorflow.org/guide/data#batching_dataset_elements – Scott McKay Sep 13 '22 at 21:49