Setup
-
Model: YOLOv5s trained on ~600 images
-
Classes:
nc=1 -
Export path: PyTorch → ONNX → Hailo Model Zoo →
.hef. Used this guide and follwed step by step: hailo_model_zoo/hailo_models/vehicle_detection/docs/TRAINING_GUIDE.rst at master · hailo-ai/hailo_model_zoo · GitHub
Issue
The .pt model in PyTorch detects objects fine.
But when I run the compiled .hef on Hailo-8, the bounding boxes don’t align with the objects. For example, detections land on unrelated regions (e.g. a person’s face) instead of the target object.
Example fused NMS output from Hailo:
yolov5s/yolov5_nms_postprocess (1, 1, 1, 5)
Raw dets: [[293.47 182.89 538.62 476.25]]
The coordinates look plausible, but they don’t match the object in the image.
My current post-processing functions:
def parse_hailo_nms(raw, img_hw):
H, W = img_hw
while isinstance(raw, list):
raw = raw[0] if len(raw) else np.zeros((0, 5), dtype=np.float32)
dets = np.asarray(raw).squeeze()
if dets.size == 0:
return np.zeros((0,4)), np.zeros((0,)), np.zeros((0,))
if dets.ndim == 1:
dets = dets.reshape(1, -1)
N, C = dets.shape
if C == 5:
boxes = dets[:, 0:4].astype(np.float32)
scores = dets[:, 4].astype(np.float32)
clsids = np.zeros((N,), dtype=np.int32)
else:
boxes = dets[:, 0:4].astype(np.float32)
scores = dets[:, 4].astype(np.float32)
clsids = dets[:, 5].astype(np.int32)
# scale boxes if normalized
if boxes.max() <= 1.5:
boxes[:, [0, 2]] *= W
boxes[:, [1, 3]] *= H
return boxes, scores, clsids
def undo_letterbox(boxes, r, dw, dh):
if len(boxes) == 0:
return boxes
boxes = boxes.copy()
boxes[:, [0, 2]] = (boxes[:, [0, 2]] - dw) / r
boxes[:, [1, 3]] = (boxes[:, [1, 3]] - dh) / r
return boxes
My suspicion
-
I may be misinterpreting the fused NMS output tensor from Hailo.
-
Are the YOLOv5s fused NMS outputs already in input size (640×640) coordinates, or still normalized 0–1?
-
Am I applying
undo_letterboxincorrectly?
What I need help with
-
Correct interpretation of
yolov5s/yolov5_nms_postprocessoutput format. -
Whether additional scaling/transform is required before mapping back to the original image.
-
Example of a minimal correct post-processing pipeline for YOLOv5s fused NMS on Hailo.
Has anyone already solved this mismatch for YOLOv5s on Hailo? Any reference code for mapping boxes back correctly would be super helpful ![]()