Search⌘ K
AI Features

Serving a TensorFlow Model

Explore the steps to serve a TensorFlow model for image classification, including loading the model, preprocessing images, running inference, and interpreting prediction probabilities. This lesson helps you understand model serving in Python applications.

We can use the TensorFlow model for inference on our datasets.

Utility functions

First, we need to define the softmax utility function.

Python
import tensorflow as tf
import numpy as np
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
def softmax(vec):
exponential = np.exp(vec)
probabilities = exponential / np.sum(exponential)
return probabilities
# test softmax function
dummy_vec = np.array([1.5630065, -0.24305986, -0.08382231, -0.4424621])
print('The output probabilities after softmax is:', softmax(dummy_vec))

Note: The softmax utility function will convert the model prediction into probabilities that sum to 1. ...