From 88ab9d4922beb652b8b52b6aebaba2ce7b6bb47d Mon Sep 17 00:00:00 2001 From: kinaryml Date: Tue, 8 Nov 2022 10:52:26 -0800 Subject: [PATCH] Used loops instead of complex list comprehensions --- .../tasks/python/vision/gesture_recognizer.py | 18 ++++++++++-------- .../tasks/python/vision/hand_landmarker.py | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/mediapipe/tasks/python/vision/gesture_recognizer.py b/mediapipe/tasks/python/vision/gesture_recognizer.py index 081ecc429..4c25aff33 100644 --- a/mediapipe/tasks/python/vision/gesture_recognizer.py +++ b/mediapipe/tasks/python/vision/gesture_recognizer.py @@ -122,19 +122,21 @@ def _build_recognition_result( for proto in hand_landmarks_proto_list: hand_landmarks = landmark_pb2.NormalizedLandmarkList() hand_landmarks.MergeFrom(proto) - hand_landmarks_results.append([ - landmark_module.NormalizedLandmark.create_from_pb2(hand_landmark) - for hand_landmark in hand_landmarks.landmark - ]) + hand_landmarks_list = [] + for hand_landmark in hand_landmarks.landmark: + hand_landmarks_list.append( + landmark_module.NormalizedLandmark.create_from_pb2(hand_landmark)) + hand_landmarks_results.append(hand_landmarks_list) hand_world_landmarks_results = [] for proto in hand_world_landmarks_proto_list: hand_world_landmarks = landmark_pb2.LandmarkList() hand_world_landmarks.MergeFrom(proto) - hand_world_landmarks_results.append([ - landmark_module.Landmark.create_from_pb2(hand_world_landmark) - for hand_world_landmark in hand_world_landmarks.landmark - ]) + hand_world_landmarks_list = [] + for hand_world_landmark in hand_world_landmarks.landmark: + hand_world_landmarks_list.append( + landmark_module.Landmark.create_from_pb2(hand_world_landmark)) + hand_world_landmarks_results.append(hand_world_landmarks_list) return GestureRecognitionResult(gesture_results, handedness_results, hand_landmarks_results, diff --git a/mediapipe/tasks/python/vision/hand_landmarker.py b/mediapipe/tasks/python/vision/hand_landmarker.py index e063bdafb..9dea08d02 100644 --- a/mediapipe/tasks/python/vision/hand_landmarker.py +++ b/mediapipe/tasks/python/vision/hand_landmarker.py @@ -98,19 +98,21 @@ def _build_detection_result( for proto in hand_landmarks_proto_list: hand_landmarks = landmark_pb2.NormalizedLandmarkList() hand_landmarks.MergeFrom(proto) - hand_landmarks_results.append([ - landmark_module.NormalizedLandmark.create_from_pb2(hand_landmark) - for hand_landmark in hand_landmarks.landmark - ]) + hand_landmarks_list = [] + for hand_landmark in hand_landmarks.landmark: + hand_landmarks_list.append( + landmark_module.NormalizedLandmark.create_from_pb2(hand_landmark)) + hand_landmarks_results.append(hand_landmarks_list) hand_world_landmarks_results = [] for proto in hand_world_landmarks_proto_list: hand_world_landmarks = landmark_pb2.LandmarkList() hand_world_landmarks.MergeFrom(proto) - hand_world_landmarks_results.append([ - landmark_module.Landmark.create_from_pb2(hand_world_landmark) - for hand_world_landmark in hand_world_landmarks.landmark - ]) + hand_world_landmarks_list = [] + for hand_world_landmark in hand_world_landmarks.landmark: + hand_world_landmarks_list.append( + landmark_module.Landmark.create_from_pb2(hand_world_landmark)) + hand_world_landmarks_results.append(hand_world_landmarks_list) return HandLandmarksDetectionResult(handedness_results, hand_landmarks_results,