How generare a tflite from a keras model


i created my model with tensorflow and i tryed it with this

txt = ["I love a cat]
seq = tokenizer.texts_to_sequences(txt)
padded = pad_sequences(seq, maxlen=max_length)
pred = model.predict(padded)

and the result is goog, so now i want to try this model on my android app.
how can I pass the string to the model and do the same evaluation written above?

when i export on tflite file, the model with this commands
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
i can’t determine string type input.

do you have any ideas?
thanks a lot


Using from_keras_model() will give you a model that expects the same input that you pass to predict(), so you’ll need to do the same pre-processing.

If you’re performing text classification in your Android app, you might find the TF Lite Task Library helps. When you convert the model, you’ll need to add metadata (example here), and then you can use NlClassifier (reference) in your app:

List<Category> results = classifier.classify("I love a cat");