Skip to main content
Version: 4.5

Preprocessing Function

In a lot of situations, it's common to tranform the data in your single or multi-model flow before passing it on to the next level or the user. To do this, you can define your pre-processing steps under the preprocessing function. This function will be applied to the model's input. We have made this process optional incase you have a separate workflow for preparing the data for the model. Such processes are faster as the time required for data transformation is eliminated in the model API call and will only be responsible for prediction. This function needs to be in launch.py file.

The preprocessing function takes the features in any data format as one of compulsory argument and logger object as second argument. These features should in the data format supported by the tranformation functions defined inside the preprocessing function. Logger object helps you with logging the information that could be necessary to debug your model API workflow for smooth operation. It is important that the outcome of your pre-processing function reflect the shape and type of the model's input in the subsequent stage.

Below is one example showing the preprocessing required on the image before passing it to model for the prediction.

def preprocessing(features,logger):
r = requests.get(features, stream=True)
img = Image.open(io.BytesIO(r.content)).convert('RGB')
open_cv_image = np.array(img)
image = open_cv_image
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]
)])
img_t = transform(image)
batch_t = torch.unsqueeze(img_t, 0)
return batch_t

Almost all types of functions from various libraries are supported inside the function for example scikit-learn, pytorch, tensorflow etc.

Post Processing Functionโ€‹

Currently we have not resricted the users to choose the type of post-processing they want to apply on the API prediction results. They can apply any type of functions on the result.