Verta
Search…
Deploying a Tensorflow model
As mention in the deploying models guide, deploying models via Verta Inference is a two step process: (1) first create an endpoint, and (2) update the endpoint with a model.
This tutorial explains how Verta Inference can be used to deploy a Tensorflow model.

1. Create an endpoint

Users can create an endpoint using Client.create_endpoint() as follows:
1
census_endpoint = client.create_endpoint(path="/census")
Copied!

2. Updating the endpoint with a RMV

As discussed in the Registry Overview, there are multiple of ways to create an RMV for a Tensorflow model.
First, if we are provided with a Keras-Tensorflow model object, users can use the Keras convenience functions to create a Verta Standard Model.
1
from verta.environment import Python
2
3
from verta.environment import Python
4
model_version_from_obj = registered_model.create_standard_model_from_keras(
5
model,
6
environment=Python(requirements=["tensorflow"]),
7
name="v1")
Copied!
Alternatively, a Tensorflow saved model can be used as an artifact in a model that extends VertaModelBase.
1
model.save("mnist.tf_saved_model")
2
from verta.registry import VertaModelBase
3
4
class MNISTModel(VertaModelBase):
5
def __init__(self, artifacts):
6
import tensorflow as tf
7
self.model = tf.keras.models.load_model(
8
artifacts["mnist_model"])
9
10
def predict(self, input_data):
11
output = []
12
for input_data_point in input_data:
13
reshaped_data = tf.reshape(input_data_point, (1, 28, 28))
14
output.append(self.model(reshaped_data).numpy().tolist())
15
return output
16
17
model_version_from_cls = registered_model.create_standard_model(
18
MNISTModel,
19
environment=Python(["tensorflow"]),
20
name="v2",
21
artifacts={"mnist_model" : "mnist.tf_saved_model/"}
22
)
Copied!
Note that the input and output of the predict function must be JSON serializable. For the full list of acceptable data types for model I/O, refer to the VertaModelBase documentation.
Prior to deploy, don't forget to test your model class locally as follows.
1
# test locally
2
mnist_model1 = MNISTModel({"mnist_model" : "mnist.tf_saved_model/"})
3
mnist_model1.predict([x_test[0]])
Copied!
To ensure that the requirements specified in the model version are in fact adequate, you may build the model container locally or part of a continuous integration system. You may also deploy the model and make test predictions as show below.
Regardless of how a Registered Model Version has been created, the endpoint defined above can now be upated and we can make predictions against it.
1
mnist_endpoint = client.get_or_create_endpoint("mnist")
2
mnist_endpoint.update(model_version_from_obj, wait=True)
3
deployed_model = mnist_endpoint.get_deployed_model()
4
deployed_model.predict([x_test[0]])
Copied!
The full code for this tutorial can be found here.
Last modified 3mo ago