diff --git a/frigate/detectors/plugins/axelera.py b/frigate/detectors/plugins/axelera.py index d8d12fbf66..4a0e02850e 100644 --- a/frigate/detectors/plugins/axelera.py +++ b/frigate/detectors/plugins/axelera.py @@ -216,12 +216,20 @@ class _AxeleraInference: ) def run(self, tensor_input, timeout: float = INFERENCE_TIMEOUT) -> np.ndarray: - if tensor_input is None or getattr(tensor_input, "ndim", 0) != 3: + if tensor_input is None or getattr(tensor_input, "ndim", 0) < 3: raise ValueError( f"Unexpected frame shape: {getattr(tensor_input, 'shape', tensor_input)}" ) - frame = np.ascontiguousarray(tensor_input) + frame = np.asarray(tensor_input) + if frame.ndim == 4: + # Frigate feeds a batched NHWC frame (1, H, W, C); drop the batch dim + if frame.shape[0] != 1: + raise ValueError( + f"Unexpected batch dimension in frame: {frame.shape}" + ) + frame = frame[0] + frame = np.ascontiguousarray(frame) request_id = self._input.put(frame) with self._lock: self._pending.append(request_id) diff --git a/frigate/test/test_axelera_detector.py b/frigate/test/test_axelera_detector.py index d1b6a187a4..eb4258135e 100644 --- a/frigate/test/test_axelera_detector.py +++ b/frigate/test/test_axelera_detector.py @@ -233,6 +233,18 @@ class TestAxeleraInference(unittest.TestCase): finally: engine.stop() + def test_batched_nhwc_frame_is_squeezed(self): + # Frigate feeds a batched NHWC frame (1, H, W, C); covers the live + # `type: zmq` worker crash (ValueError: unexpected shape) on every frame + engine = self._engine() + try: + flat = engine.run(np.zeros((320, 320, 3), np.uint8)) + batched = engine.run(np.zeros((1, 320, 320, 3), np.uint8)) + self.assertEqual(batched.shape, (20, 6)) + np.testing.assert_array_equal(batched, flat) + finally: + engine.stop() + def test_timeout_returns_zeros_when_stream_blocks(self): engine = self._engine(hold=True) try: