From 4df05c8637514e614e57cbffd462c8f80047e4db Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Wed, 9 Oct 2024 12:21:06 -0400 Subject: [PATCH 1/5] redo of integrating cluster estimation worker into main --- config.yaml | 5 +++++ main_2024.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index b0dd9811..62534d32 100644 --- a/config.yaml +++ b/config.yaml @@ -34,3 +34,8 @@ geolocation: camera_orientation_yaw: 0.0 camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 + +cluster_merge: + min_activation_threshold: 0 + min_new_points_to_run: 0 + random_state: 0 \ No newline at end of file diff --git a/main_2024.py b/main_2024.py index 66ad913d..fe4d3278 100644 --- a/main_2024.py +++ b/main_2024.py @@ -19,6 +19,7 @@ from modules.data_merge import data_merge_worker from modules.geolocation import geolocation_worker from modules.geolocation import camera_properties +from modules.cluster_estimation import cluster_estimation_worker from modules.common.logger.modules import logger from modules.common.logger.modules import logger_setup_main from modules.common.logger.read_yaml.modules import read_yaml @@ -85,8 +86,8 @@ def main() -> int: VIDEO_INPUT_SAVE_PREFIX = str(pathlib.Path(logging_path, VIDEO_INPUT_SAVE_NAME_PREFIX)) DETECT_TARGET_WORKER_COUNT = config["detect_target"]["worker_count"] - detect_target_option_int = config["detect_target"]["option"] - DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(detect_target_option_int) + DETECT_TARGET_OPTION_INT = config["detect_target"]["option"] + DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(DETECT_TARGET_OPTION_INT) DETECT_TARGET_DEVICE = "cpu" if args.cpu else config["detect_target"]["device"] DETECT_TARGET_MODEL_PATH = config["detect_target"]["model_path"] DETECT_TARGET_OVERRIDE_FULL_PRECISION = args.full @@ -111,6 +112,10 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_YAW = config["geolocation"]["camera_orientation_yaw"] GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] + + MIN_ACTIVATION_THRESHOLD = config["cluster_merge"]["min_activation_threshold"] + MIN_NEW_POINTS_TO_RUN = config["cluster_merge"]["min_new_points_to_run"] + RANDOM_STATE = config["cluster_merge"]["random_state"] # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -139,7 +144,7 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) - geolocation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + geolocation_to_cluster_estimation_queue = queue_proxy_wrapper.QueueProxyWrapper( mp_manager, QUEUE_MAX_SIZE, ) @@ -147,6 +152,10 @@ def main() -> int: mp_manager, QUEUE_MAX_SIZE, ) + cluster_estimation_to_main_queue = queue_proxy_wrapper.QueueProxyWrapper( + mp_manager, + QUEUE_MAX_SIZE, + ) result, camera_intrinsics = camera_properties.CameraIntrinsics.create( GEOLOCATION_RESOLUTION_X, @@ -266,7 +275,7 @@ def main() -> int: camera_extrinsics, ), input_queues=[data_merge_to_geolocation_queue], - output_queues=[geolocation_to_main_queue], + output_queues=[geolocation_to_cluster_estimation_queue], controller=controller, local_logger=main_logger, ) @@ -277,6 +286,22 @@ def main() -> int: # Get Pylance to stop complaining assert geolocation_worker_properties is not None + result, cluster_estimation_worker_properties = worker_manager.WorkerProperties.create( + count=1, + target=cluster_estimation_worker.cluster_estimation_worker, + work_arguments=(MIN_ACTIVATION_THRESHOLD, MIN_NEW_POINTS_TO_RUN, RANDOM_STATE), + input_queues=[geolocation_to_cluster_estimation_queue], + output_queues=[cluster_estimation_to_main_queue], + controller=controller, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create arguments for Video Input", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_worker_properties is not None + # Create managers worker_managers = [] @@ -345,6 +370,19 @@ def main() -> int: worker_managers.append(geolocation_manager) + result, cluster_estimation_manager = worker_manager.WorkerManager.create( + worker_properties=cluster_estimation_worker_properties, + local_logger=main_logger, + ) + if not result: + main_logger.error("Failed to create manager for Flight Interface", True) + return -1 + + # Get Pylance to stop complaining + assert cluster_estimation_manager is not None + + worker_managers.append(cluster_estimation_manager) + # Run for manager in worker_managers: manager.start_workers() @@ -357,7 +395,7 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_main_queue.queue.get_nowait() + geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() except queue.Empty: geolocation_data = None @@ -374,7 +412,16 @@ def main() -> int: main_logger.debug( "geolocation confidence: " + str(detection_world.confidence), True ) - + try: + cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + except queue.Empty: + cluster_estimations = None + if cluster_estimations is not None: + for cluster in cluster_estimations: + main_logger.debug("Cluser in world: True") + main_logger.debug("Cluster location x: " + str(cluster.location_x)) + main_logger.debug("Cluster location y: " + str(cluster.location_y)) + main_logger.debug("Cluster spherical variance: " + str(cluster.spherical_variance)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break @@ -386,8 +433,9 @@ def main() -> int: detect_target_to_data_merge_queue.fill_and_drain_queue() flight_interface_to_data_merge_queue.fill_and_drain_queue() data_merge_to_geolocation_queue.fill_and_drain_queue() - geolocation_to_main_queue.fill_and_drain_queue() + geolocation_to_cluster_estimation_queue.fill_and_drain_queue() flight_interface_decision_queue.fill_and_drain_queue() + cluster_estimation_to_main_queue.fill_and_drain_queue() for manager in worker_managers: manager.join_workers() From 9ec46f24a9c33987a58db1a60ae4a775a1fd2fcc Mon Sep 17 00:00:00 2001 From: Cyuber Date: Fri, 11 Oct 2024 19:06:27 -0400 Subject: [PATCH 2/5] implemented changes from review --- config.yaml | 4 ++-- main_2024.py | 37 +++++++++---------------------------- modules/object_in_world.py | 6 ++++++ 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/config.yaml b/config.yaml index 62534d32..de8fe916 100644 --- a/config.yaml +++ b/config.yaml @@ -35,7 +35,7 @@ geolocation: camera_orientation_pitch: -1.57079632679 camera_orientation_roll: 0.0 -cluster_merge: +cluster_estimation: min_activation_threshold: 0 min_new_points_to_run: 0 - random_state: 0 \ No newline at end of file + random_state: 0 diff --git a/main_2024.py b/main_2024.py index fe4d3278..c18bd0c0 100644 --- a/main_2024.py +++ b/main_2024.py @@ -296,7 +296,7 @@ def main() -> int: local_logger=main_logger, ) if not result: - main_logger.error("Failed to create arguments for Video Input", True) + main_logger.error("Failed to create arguments for Cluster Estimation", True) return -1 # Get Pylance to stop complaining @@ -375,7 +375,7 @@ def main() -> int: local_logger=main_logger, ) if not result: - main_logger.error("Failed to create manager for Flight Interface", True) + main_logger.error("Failed to create manager for Cluster Estimation", True) return -1 # Get Pylance to stop complaining @@ -395,33 +395,14 @@ def main() -> int: return -1 try: - geolocation_data = geolocation_to_cluster_estimation_queue.queue.get_nowait() - except queue.Empty: - geolocation_data = None - - if geolocation_data is not None: - for detection_world in geolocation_data: - main_logger.debug("Detection in world:", True) - main_logger.debug( - "geolocation vertices: " + str(detection_world.vertices.tolist()), True - ) - main_logger.debug( - "geolocation centre: " + str(detection_world.centre.tolist()), True - ) - main_logger.debug("geolocation label: " + str(detection_world.label), True) - main_logger.debug( - "geolocation confidence: " + str(detection_world.confidence), True - ) - try: - cluster_estimations = cluster_estimation_to_main_queue.queue.get_nowait() + cluster_estimation_data = cluster_estimation_to_main_queue.queue.get_nowait() except queue.Empty: - cluster_estimations = None - if cluster_estimations is not None: - for cluster in cluster_estimations: - main_logger.debug("Cluser in world: True") - main_logger.debug("Cluster location x: " + str(cluster.location_x)) - main_logger.debug("Cluster location y: " + str(cluster.location_y)) - main_logger.debug("Cluster spherical variance: " + str(cluster.spherical_variance)) + cluster_estimation_data = None + + if cluster_estimation_data is not None: + for object_in_world in cluster_estimation_data: + main_logger.debug("Cluster in world: ", True) + main_logger.debug(object_in_world.__str__) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 1ce9f65e..31f7ef01 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -38,3 +38,9 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance + + def __str__(self) -> str: + """ + To string. + """ + return f"{self.__class__}, location x: {self.location_x}, location y: {self.location_y}, spherical variance: {self.spherical_variance}, label: {self.label}" From fb2897285348d796c109afb5ba85028c8d6d4a7e Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Thu, 31 Oct 2024 00:27:14 -0400 Subject: [PATCH 3/5] fixed formatting issue --- main_2024.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_2024.py b/main_2024.py index c18bd0c0..2f6cacd0 100644 --- a/main_2024.py +++ b/main_2024.py @@ -398,7 +398,7 @@ def main() -> int: cluster_estimation_data = cluster_estimation_to_main_queue.queue.get_nowait() except queue.Empty: cluster_estimation_data = None - + if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: main_logger.debug("Cluster in world: ", True) From 62e5b7a01c2055315f2c95cb7844254b6e7e1dff Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Fri, 1 Nov 2024 15:15:34 -0400 Subject: [PATCH 4/5] implemented reviewed changes --- main_2024.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main_2024.py b/main_2024.py index 2f6cacd0..4349ea9e 100644 --- a/main_2024.py +++ b/main_2024.py @@ -113,9 +113,9 @@ def main() -> int: GEOLOCATION_CAMERA_ORIENTATION_PITCH = config["geolocation"]["camera_orientation_pitch"] GEOLOCATION_CAMERA_ORIENTATION_ROLL = config["geolocation"]["camera_orientation_roll"] - MIN_ACTIVATION_THRESHOLD = config["cluster_merge"]["min_activation_threshold"] - MIN_NEW_POINTS_TO_RUN = config["cluster_merge"]["min_new_points_to_run"] - RANDOM_STATE = config["cluster_merge"]["random_state"] + MIN_ACTIVATION_THRESHOLD = config["cluster_estimation"]["min_activation_threshold"] + MIN_NEW_POINTS_TO_RUN = config["cluster_estimation"]["min_new_points_to_run"] + RANDOM_STATE = config["cluster_estimation"]["random_state"] # pylint: enable=invalid-name except KeyError as exception: main_logger.error(f"Config key(s) not found: {exception}", True) @@ -401,8 +401,8 @@ def main() -> int: if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: - main_logger.debug("Cluster in world: ", True) - main_logger.debug(object_in_world.__str__) + main_logger.debug("Cluster in world: ", (object_in_world is not None)) + main_logger.debug(str(object_in_world)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True) break From d6183f0e59fcc1b2c7e6a9bba931c2d6a49925ef Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Fri, 1 Nov 2024 20:25:00 -0400 Subject: [PATCH 5/5] fixed review changes --- config.yaml | 4 ++-- main_2024.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index de8fe916..44bdd6df 100644 --- a/config.yaml +++ b/config.yaml @@ -36,6 +36,6 @@ geolocation: camera_orientation_roll: 0.0 cluster_estimation: - min_activation_threshold: 0 - min_new_points_to_run: 0 + min_activation_threshold: 25 + min_new_points_to_run: 5 random_state: 0 diff --git a/main_2024.py b/main_2024.py index 4349ea9e..0cc5e2e1 100644 --- a/main_2024.py +++ b/main_2024.py @@ -401,7 +401,7 @@ def main() -> int: if cluster_estimation_data is not None: for object_in_world in cluster_estimation_data: - main_logger.debug("Cluster in world: ", (object_in_world is not None)) + main_logger.debug("Cluster in world: ", True) main_logger.debug(str(object_in_world)) if cv2.waitKey(1) == ord("q"): # type: ignore main_logger.info("Exiting main loop", True)