From 44cc8bf4fcac239eb948326a3a8250dc6049e669 Mon Sep 17 00:00:00 2001 From: patrykorwat Date: Sun, 23 Aug 2026 20:51:44 +0000 Subject: [PATCH] perf(axelera): quantize uint8->int8 in one wrapping pass resized - 128 in uint8 wraps mod 256, then astype(int8) yields exactly px - 128 (verified for all 0..255, equivalent to the int16+clip path) without the intermediate int16 array or clip pass. --- frigate/detectors/plugins/axelera.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frigate/detectors/plugins/axelera.py b/frigate/detectors/plugins/axelera.py index 8f9bb57d05..e4480645b8 100644 --- a/frigate/detectors/plugins/axelera.py +++ b/frigate/detectors/plugins/axelera.py @@ -369,8 +369,9 @@ class _AxeleraRuntimeInference: (self._new_w, self._new_h), interpolation=cv2.INTER_LINEAR, ) - q = resized.astype(np.int16) - 128 # uint8 [0,255] -> int8 [-128,127] - q = np.clip(q, -128, 127).astype(np.int8) + # uint8 - 128 wraps mod 256, then cast to int8 == px - 128 (exactly), + # in one pass over the resized frame (no int16/clip intermediates) + q = (resized - np.uint8(128)).astype(np.int8) buf = self._in_buf buf.fill(INPUT_Q_ZERO) y0, y1 = self._pad_t, self._pad_t + self._new_h