Skip to main content

Postprocess

In some scenarios it may be necessary to manipulate the outputs of the model. For example, the output of your classification model contains a list of the probabilities of each class. You may want to take the highest probability in this list or take the top 3 classes with the highest probability. In this case, you should manipulate the output of the model. Moreover, postprocessing is widely used in computer vision models. Modelify lets you write your own postprocess function for flexibility. After you write your own function, you need to assign it to the Model Inference object.

For example, the output of the widely known Mnist Handwritten Digit Classification model output includes a list of 10 possibilities. The probabilities in this list are the probability of each number occurring. If we want to get the number with the highest probability instead of all the possibilities, we need to use the argmax function in the numpy library.

def my_postprocess(outputs):
import numpy as np
return np.argmax(outputs, axis=1).tolist() # take the highest probability

my_input = Image(width=28, height=28,channel=1) # grayscale image
inference = ModelInference(model=model, framework="KERAS", inputs=my_input)

inference.postprocess = my_postprocess
info

Your postprocess function must take outputs argument to get model prediction outputs.