I need to deploy a RandomForestModel regression model, then consume it.
I have made a zip file of the entire folder containing the trained RandomForestModel regression model for deployment.
In a separate notebook, I unzipped and loaded the model: loadedModel = tf.saved_model.load(‘/RF_model’)
With the loaded model, I need to predict with a new dataset. However, I can’t find any information about what methods I have to use.
Any help is greatly appreciated.
In TensorFlow/Keras, there are two ways to load and use a model:
The SavedModel API : tf.saved_model.load('./my_model').
The Keras API: tf.keras.models.load_model('./my_model').
The Keras API calls the SavedModel API and adds some extra utility functions. If you can the choose, I would recommend using the Keras API.
Once a model is loaded you can use if as follow:
# Generate some predictions. Works with all APIs.
# dataset can be a tensor, array, structure of tensor or structure of arrays.
# All tensors need to be of rank>=2.
predictions = model(dataset)
# Generate some predictions. Works only with the Keras APIs.
# dataset can be anything as before. Also support dataset being a tf.dataset.
# There are not constrains on the tensor ranks.
predictions = model.predict(dataset)
# Evaluate the model.
metrics = model.evaluate(dataset)