Skip to main content
SDK Version: 2.5.0

Pipeline

The DX-ModelZoo preprocessing and postprocessing pipelines execute operations sequentially in the order defined in YAML configuration.

Pipeline Overview​

The following diagram shows how preprocessing, inference, and postprocessing connect:

PreprocessingPipeline​

Applies preprocessing operations sequentially to the input data (images).

Class Structure​

class PreprocessingPipeline(Compose):
"""Inherits from torchvision.transforms.Compose."""

def __init__(
self,
steps_config: Union[List[Dict], Dict[str, List[Dict]]],
npu_mode: bool = False,
):
# Builds steps from config dicts; skips NPU-handled ops when npu_mode=True
...

def __call__(self, img: np.ndarray) -> np.ndarray:
for step in self.steps:
img = step(img)
return img

YAML to Pipeline Mapping​

YAML Definition
preprocessing:
- type: resize
size: [256, 256]
mode: torchvision
- type: centercrop
height: 224
width: 224
- type: div
x: 255
- type: normalize
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
- type: transpose
axis: [2, 0, 1]
- type: expanddim
axis: 0

The above YAML is transformed into the following:

# Automatically generated by ModelBuilder
pipeline = PreprocessingPipeline(
steps_config=[
{"type": "resize", "size": [256, 256], "mode": "torchvision"},
{"type": "centercrop", "height": 224, "width": 224},
{"type": "div", "x": 255},
{"type": "normalize", "mean": [0.485, 0.456, 0.406], "std": [0.229, 0.224, 0.225]},
{"type": "transpose", "axis": [2, 0, 1]},
{"type": "expanddim", "axis": 0},
],
npu_mode=False,
)

NPU Auto-Skip​

For target: dxnn, arithmetic preprocessing is skipped when runtime input dtype is uint8; it remains for float32 input unless appendix.npu_skip_arithmetic overrides the behavior.

NPU_SKIP_DEFAULT​

Arithmetic operations skipped on the NPU are defined in NPU_SKIP_DEFAULT: div, normalize, transpose, expanddim, mul, add, subtract — see Preprocessing API for the full definition.

Behavior Comparison​

resize → centercrop → convertcolor → div → normalize → transpose → expanddim
✅ ✅ ✅ ✅ ✅ ✅ ✅

All operations are executed in order.

Why Operations Are Skipped

The NPU accepts uint8 input and handles div (normalization), normalize, transpose (layout conversion), and expanddim (batch dimension) at the hardware level. Running these operations redundantly on the CPU would produce incorrect results.

Skip Flow​

PostprocessingPipeline​

Applies postprocessing operations sequentially to the model output.

Class Structure​

class PostprocessingPipeline:
def __init__(self, steps: list):
self.steps = steps

def __call__(self, outputs):
for step in self.steps:
outputs = step(outputs)
return outputs
No NPU Skip

The postprocessing pipeline does not have NPU skip logic. All postprocessing operations are always executed.

YAML to Pipeline Mapping​

Detection Model Example
postprocessing:
- type: nms
conf_thres: 0.001
iou_thres: 0.7
# Transformed result
pipeline = PostprocessingPipeline(
steps_config=[{"type": "nms", "conf_thres": 0.001, "iou_thres": 0.7}]
)
# pipeline.steps -> [NMS(conf_thres=0.001, iou_thres=0.7)]

Postprocessing Patterns by Task​

See Postprocessing Guide by Task for the full task-to-postprocessing mapping.

Full Execution Flow​

The following sequence diagram shows the complete evaluation flow, from raw data to final metrics:

Custom Pipeline Extension​

To add a custom operation, register it with the appropriate Registry:

from dx_modelzoo.preprocessing import PREPROCESSING_REGISTRY

@PREPROCESSING_REGISTRY.register("my_augment")
class MyAugment:
def __init__(self, probability: float = 0.5):
self.probability = probability

def __call__(self, img: np.ndarray) -> np.ndarray:
# Custom logic
return img
preprocessing:
- type: resize
size: [224, 224]
- type: my_augment # Custom operation inserted
probability: 0.8
- type: div
x: 255
Pipeline Debugging

Print the shape before and after each step's __call__ to trace the data transformation process:

for step in pipeline.steps:
print(f"{step.__class__.__name__}: {img.shape}", end=" → ")
img = step(img)
print(img.shape)