How hasnard/pdefa works
pdefa is a CPU inference engine exposed to Python through ctypes, with image loading and preprocessing plus YOLO-oriented postprocessing. Its main workflow prepares an image tensor, loads an engine model, runs a session, and decodes model output. The tree supports the native engine and image pipeline; the README also mentions an ONNX-to-engine converter, but no converter source path appears in the supplied tree, so it is not mapped here.
Main entry points: _bindings.py ctypes bindings · session.cpp Inference session · pdefa_c_api.cpp Image API bridge · preprocess.cpp Letterbox preprocess
Components 22
Python API
- Python API
pdefa/python/src/pdefa/__init__.py - ctypes bindings
pdefa/python/src/pdefa/_bindings.py - Batch inference
pdefa/python/src/pdefa/batch.py - YOLO postprocess
pdefa/python/src/pdefa/_bindings.py
Image pipeline
- Image decoding
imageloader/src/loader.cpp - PNG / JPEG decoders
imageloader/src/png/png_decoder.cpp - Letterbox preprocess
imageloader/src/preprocess.cpp - Image API bridge
pdefa/src/pdefa_c_api.cpp
Inference engine
- Context and threads
PDEFA1.0/src/api/engine_api.cpp - Model loader
PDEFA1.0/src/core/model.cpp - Custom format loader
PDEFA1.0/src/loader/custom_loader.cpp - Inference session
PDEFA1.0/src/core/session.cpp - Inference output
PDEFA1.0/src/core/session.cpp
Compute internals
- Graph optimization
PDEFA1.0/src/optimizer/graph_optimizer.cpp - Layout transforms
PDEFA1.0/src/optimizer/layout_transform.cpp - Operator dispatch
PDEFA1.0/src/ops/conv2d.cpp - SIMD kernels
PDEFA1.0/src/kernels/kernel_registry.cpp - Tensor memory
PDEFA1.0/src/memory/memory_plan.cpp
Other components
- Python caller
- Image file
- Engine model file
- Detection results
Connections 24
- Python caller → Python API: calls
- Python API → ctypes bindings: uses
- Python caller → Image file: selects
- ctypes bindings → Image API bridge: calls
- Image API bridge → Image decoding: loads image
- Image decoding → PNG / JPEG decoders: dispatches format
- Image API bridge → Letterbox preprocess: prepares tensor
- Letterbox preprocess → ctypes bindings: returns tensor and metadata
- Python caller → Engine model file: selects
- ctypes bindings → Context and threads: creates context
- ctypes bindings → Model loader: loads model
- Model loader → Custom format loader: parses model
- ctypes bindings → Inference session: creates and runs
- Inference session → Graph optimization: optimizes graph
- Inference session → Layout transforms: transforms tensors
- Inference session → Operator dispatch: dispatches operators
- Operator dispatch → SIMD kernels: selects kernels
- Inference session → Tensor memory: plans tensor storage
- Inference session → Inference output: produces tensors
- ctypes bindings → YOLO postprocess: decodes output
- Inference output → YOLO postprocess: provides raw tensor
- YOLO postprocess → Detection results: returns detections
- Batch inference → Inference session: runs sessions
- Batch inference → Letterbox preprocess: prepares images