From edb79844c59fe88c29c8a4641a55bae3ee2bc906 Mon Sep 17 00:00:00 2001 From: Caleb Vatral Date: Thu, 28 Sep 2023 11:38:24 -0500 Subject: [PATCH] Default empty result: Fixes Ahmednull/L2CS-Net#22 --- l2cs/pipeline.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/l2cs/pipeline.py b/l2cs/pipeline.py index 90c9d19c..894a70ec 100644 --- a/l2cs/pipeline.py +++ b/l2cs/pipeline.py @@ -55,6 +55,13 @@ def step(self, frame: np.ndarray) -> GazeResultContainer: landmarks = [] scores = [] + # default stacks + pitch = np.empty((0,1)) + yaw = np.empty((0,1)) + bboxes_stack = np.empty((0,1)) + landmarks_stack = np.empty((0,1)) + scores_stack = np.empty((0,1)) + if self.include_detector: faces = self.detector(frame) @@ -86,14 +93,12 @@ def step(self, frame: np.ndarray) -> GazeResultContainer: landmarks.append(landmark) scores.append(score) - # Predict gaze - pitch, yaw = self.predict_gaze(np.stack(face_imgs)) - - else: - - pitch = np.empty((0,1)) - yaw = np.empty((0,1)) - + if len(face_imgs) > 0: + # Predict gaze + pitch, yaw = self.predict_gaze(np.stack(face_imgs)) + bboxes_stack = np.stack(bboxes) + landmarks_stack = np.stack(landmarks) + scores_stack = np.stack(scores) else: pitch, yaw = self.predict_gaze(frame) @@ -101,9 +106,9 @@ def step(self, frame: np.ndarray) -> GazeResultContainer: results = GazeResultContainer( pitch=pitch, yaw=yaw, - bboxes=np.stack(bboxes), - landmarks=np.stack(landmarks), - scores=np.stack(scores) + bboxes=bboxes_stack, + landmarks=landmarks_stack, + scores=scores_stack ) return results