TFDF model deployment

I need to deploy a RandomForestModel regression model, then consume it.

  1. I have made a zip file of the entire folder containing the trained RandomForestModel regression model for deployment.
  2. In a separate notebook, I unzipped and loaded the model: loadedModel = tf.saved_model.load(’/RF_model’)
  3. 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.

Hi Frank,

you can try something like this:

reloaded_model = tf.saved_model.load('./my_model')
result = reloaded_model(your_data)

Hi,

Adding some more details on top of @lgusm reply.

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)

Cheers,
M.

1 Like