Skip to main content
SDK Version: 2.5.0

Postprocessing

The postprocessing pipeline in DX-ModelZoo transforms raw model outputs into structured, task-specific results.

Module: dx_modelzoo.postprocessing

PostprocessingPipeline​

Sequentially executes postprocessing operations defined in a YAML configuration.

class PostprocessingPipeline:
def __init__(self, steps_config: list[dict])
def __call__(self, outputs, **kwargs) -> Any
ParameterTypeDescription
steps_configlist[dict]Step configuration dicts ({"type": ..., **params}), i.e. the YAML postprocessing: block
AttributeTypeDescription
stepslistInstantiated postprocessing operation objects built from steps_config
warning

The constructor argument is steps_config and takes config dicts, not operation instances. Using steps= raises TypeError; passing built objects raises AttributeError: 'TopK' object has no attribute 'get'.

Context keyword arguments (runtime_target, and for detection models origin_hw / input_hw) are forwarded to every step — see Adding Custom Postprocessing.

from dx_modelzoo.postprocessing import PostprocessingPipeline

postprocessing = PostprocessingPipeline(steps_config=[{"type": "topk", "k": 5}])

Usage Example​

from dx_modelzoo.loader.model_builder import ModelBuilder

builder = ModelBuilder("resnet50_224x224.yaml")
postprocessing = builder.build_postprocessing()

# Apply to model outputs
outputs = session.run(input_tensor)
result = postprocessing(outputs)
No NPU Skip

Unlike preprocessing, the postprocessing pipeline does not have NPU skip logic. All postprocessing operations are always executed.

Built-in Postprocessing Types​

The shared built-in types below are the only operations registered directly in dx_modelzoo.postprocessing.POSTPROCESSING_REGISTRY: identity, topk, nms, and segmentation_argmax.

identity​

Returns the input as-is without any transformation. Used for models that do not require postprocessing.

postprocessing:
- type: identity

No parameters.

topk​

Extracts the top-k predictions from a classification model.

postprocessing:
- type: topk
k: [1, 5]
ParameterTypeDescription
klist[int]Number of top predictions to extract (e.g., [1, 5] → Top-1, Top-5)
skip_backgroundboolDrop index 0 (background class) before ranking (default: False)

Input: list[np.ndarray] — Model output (logits/probabilities) Output: Top-k class indices, sorted by confidence descending

nms​

Applies Non-Maximum Suppression to remove duplicate detections.

postprocessing:
- type: nms
conf_thres: 0.001
iou_thres: 0.7
max_output_boxes: 300
ParameterTypeDescription
conf_thresfloatConfidence threshold to keep a detection (default: 0.001)
iou_thresfloatIoU threshold above which overlapping boxes are suppressed (default: 0.7)
max_output_boxesintMaximum number of boxes to keep per image (default: 300)
pad_resizeboolWhether to rescale coordinates for letterbox/pad-resize preprocessing (default: True)

Input: dict — {"boxes": [N,4] xyxy, "scores": [N], "class_ids": [N]} from a model-specific decode step Output: np.ndarray of shape [M, 6] — (x1, y1, x2, y2, score, class_id)

Task: Object Detection

segmentation_argmax​

Applies argmax along the channel axis to the output of a segmentation model.

postprocessing:
- type: segmentation_argmax
layout: nchw
target_size: [512, 512]
ParameterTypeDescription
layoutstrInput layout, nchw or nhwc (default: nchw)
target_sizelist[int] | NoneOptional [H, W] to resize the output via nearest interpolation (default: None)

Input: Logits of shape (1, num_classes, H, W) Output: Class index map of shape (H, W)

Task: Semantic Segmentation

Postprocessing Guide by Task​

The following table maps common tasks to their typical postprocessing:

TaskRecommended PostprocessingYAML Example
Image Classificationtopktype: topk, k: [1, 5]
Object Detectionmodel-specific decode + shared nmstype: yolov8_decode → type: nms, conf_thres: 0.001, iou_thres: 0.7
Semantic Segmentationsegmentation_argmaxtype: segmentation_argmax
Instance Segmentationmodel-specific decodetype: yolact_decode
Face Detectionmodel-specific decodetype: retinaface_decode
Pose Estimationmodel-specific decodetype: rtmpose_simcc_decode
Super Resolutionidentitytype: identity
Depth Estimationidentitytype: identity

Adding Custom Postprocessing​

Register a custom postprocessing operation the same way as preprocessing:

from dx_modelzoo.postprocessing import POSTPROCESSING_REGISTRY

@POSTPROCESSING_REGISTRY.register("my_postprocess")
class MyPostprocess:
"""Custom postprocessing operation"""

def __init__(self, threshold: float = 0.5):
self.threshold = threshold

def __call__(self, outputs: list[np.ndarray], **kwargs) -> dict:
# outputs: list of raw model outputs
# kwargs carries pipeline context (see table below) — always accept **kwargs
result = outputs[0]
mask = result > self.threshold
return {"predictions": result[mask]}
__call__ must accept **kwargs

PostprocessingPipeline.__call__(outputs, **kwargs) forwards its context to every step. A step defined as __call__(self, outputs) raises TypeError: __call__() got an unexpected keyword argument 'runtime_target'.

KeywordProvided byMeaning
runtime_targetall evaluators"onnx" / "npu" — the active runtime
origin_hwdetection-style evaluators(H, W) of the original image
input_hwdetection-style evaluators(H, W) of the model input

Steps producing coordinates (boxes, keypoints) must map model-input pixel space back to original image coordinates using origin_hw / input_hw:

from dx_modelzoo.postprocessing.coord_scaler import unpad_and_scale

@POSTPROCESSING_REGISTRY.register("my_box_postprocess")
class MyBoxPostprocess:
def __call__(self, outputs, origin_hw=None, input_hw=None, **kwargs):
boxes = outputs[0] # [M, 6] (x1, y1, x2, y2, score, class_id) in input space
if origin_hw is not None and input_hw is not None:
boxes[:, :4] = unpad_and_scale(boxes[:, :4], input_hw, origin_hw)
return boxes
postprocessing:
- type: my_postprocess
threshold: 0.7

Chaining Multiple Postprocessing Steps​

Multiple postprocessing operations can be chained sequentially:

postprocessing:
- type: yolov8_decode # Step 1: model-specific decode
- type: nms # Step 2: shared NMS
conf_thres: 0.001
iou_thres: 0.7
Postprocessing Order

Postprocessing operations are executed in the order they are defined in the YAML configuration. The output of each step becomes the input to the next, so ordering matters.

For detailed usage, refer to the Custom Models guide.

Model-Specific Postprocessing (custom_ops.py)​

For model-specific decoding logic that doesn't belong in the shared postprocessing module, use a custom_ops.py file in the model's directory. Many model YAMLs reference names registered there instead of shared built-ins.

Auto-Discovery Mechanism​

When ModelBuilder loads a model YAML, it automatically imports custom_ops.py from the same directory:

models/custom/MyModel/
├── MyModel_v1.yaml
└── custom_ops.py ← auto-imported

The import happens before validation, so any @POSTPROCESSING_REGISTRY.register() calls in custom_ops.py are available for the YAML's postprocessing section.

Example: Model-Specific Decoder​

models/cv/pose_estimation/RTMPose/custom_ops.py
from dx_modelzoo.postprocessing import POSTPROCESSING_REGISTRY
import numpy as np

@POSTPROCESSING_REGISTRY.register("rtmpose_simcc_decode")
class RTMPoseSimCCDecode:
"""Decode SimCC heatmaps to COCO 17-keypoint format."""

def __init__(self, split_ratio: float = 2.0, **kwargs):
self.split_ratio = split_ratio

def __call__(self, outputs, **kwargs):
simcc_x, simcc_y = outputs[0], outputs[1]
x_idx = simcc_x[0].argmax(axis=-1).astype(np.float32)
y_idx = simcc_y[0].argmax(axis=-1).astype(np.float32)
scores = (simcc_x[0].max(axis=-1) + simcc_y[0].max(axis=-1)) / 2.0
kpts = np.stack([x_idx / self.split_ratio, y_idx / self.split_ratio], axis=-1)
return kpts, scores
RTMPose_T.yaml (postprocessing section)
postprocessing:
- type: rtmpose_simcc_decode
split_ratio: 2.0

Built-in Model-Specific Types​

These types are registered via custom_ops.py in their respective model directories:

TypeModelInput → Output
superpoint_decodeSuperPoint65-ch heatmap → (keypoints, descriptors)
rtmpose_simcc_decodeRTMPoseSimCC bins → (keypoints [17,2], scores [17])
mediapipe_pose_decodeMediaPipePoseLandmarks → (keypoints [17,2], scores [17])
blazeface_decodeBlazeFaceRaw boxes → [N, 5] (xyxy + score)

When NOT to Use POSTPROCESSING_REGISTRY​

Not all model-specific code belongs in the postprocessing registry:

  • Init-time utilities (run once at startup, not per-sample): Place in a utility file.
    • Example: clip_utils.py for building text embeddings at evaluation init time.
  • Common operations (used across many models): Keep in src/dx_modelzoo/postprocessing/.
    • Example: NMS, TopK, coordinate scaling.