Postprocessing

Function Description

Typically, a postprocessing code file is provided once a model file is acquired. It is advised to employ the same postprocessing procedure as used during model training to ensure the inference results align with expectations.

Vision SDK encapsulates distinct postprocessing functions for various classic models to carry out their postprocessing operations. The data from model inference is directly passed to the postprocessing interface to obtain the final result, which significantly streamlines the usage process.

For details about related APIs, see Model Postprocessing.

API Calling Process

The following uses ResNet-50 postprocessing as an example:

Figure 1 API calling process

Sample Code

The following is an example of the postprocessing function for ResNet-50 based on Vision SDK. It is for reference only and cannot be directly copied for running.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Take ResNet-50 as an example. output indicates the model output.
# Step 1: Obtain the postprocessing object and load the configuration and label information.
postprocessor = post.Resnet50PostProcess(config_path=config_path, label_path=label_path) 

# Step 2: Send the model output to the process function of the postprocessing API.
pred = postprocessor.process([output])[0][0] # pred: <ClassInfo classId=... confidence=... className=...>

# Step 3: Obtain the result.
confidence = pred.confidence  # Obtain the class confidence.
className = pred.className  # Obtain the class name.
print('{}: {}'.format(className, confidence))  # Print the result.