From 0cb3b975d106cc4820f4dbf3a7fa9317c1ba44de Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Mon, 26 Sep 2022 20:46:31 +0000 Subject: [PATCH 01/31] Fix ros1 3d detection --- .../scripts/object_detection_3d_voxel.py | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py index 6d6b74015a..d5d5b95092 100644 --- a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py +++ b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import torch import os import rospy @@ -62,7 +63,7 @@ def __init__( self.bridge = ROSBridge() self.detection_publisher = rospy.Publisher( - output_detection3d_topic, Detection3DArray, queue_size=10 + output_detection3d_topic, Detection3DArray, queue_size=1 ) rospy.Subscriber(input_point_cloud_topic, ROS_PointCloud, self.callback) @@ -84,35 +85,53 @@ def callback(self, data): self.detection_publisher.publish(ros_boxes) rospy.loginfo("Published detection boxes") -if __name__ == "__main__": - # Automatically run on GPU/CPU - device = "cuda:0" if torch.cuda.is_available() else "cpu" - # initialize ROS node - rospy.init_node("opendr_voxel_detection_3d", anonymous=True) - rospy.loginfo("Voxel Detection 3D node started") - - model_name = rospy.get_param("~model_name", "tanet_car_xyres_16") - model_config_path = rospy.get_param( - "~model_config_path", os.path.join( +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-n", "--model_name", help="Name of the trained model", + type=str, default="tanet_car_xyres_16") + parser.add_argument( + "-c", "--model_config_path", help="Path to a model .proto config", + type=str, default=os.path.join( "..", "..", "src", "opendr", "perception", "object_detection_3d", "voxel_object_detection_3d", "second_detector", "configs", "tanet", - "car", "test_short.proto" + "car", "xyres_16.proto" ) ) - temp_dir = rospy.get_param("~temp_dir", "temp") - input_point_cloud_topic = rospy.get_param( - "~input_point_cloud_topic", "/opendr/dataset_point_cloud" - ) - rospy.loginfo("Using model_name: {}".format(model_name)) + parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + type=str, default="temp") + parser.add_argument("-i", "--input_point_cloud_topic", + help="Point Cloud topic provdied by either a point_cloud_dataset_node or any other 3D Point Cloud Node", + type=str, default="/opendr/dataset_point_cloud") + parser.add_argument("-o", "--output_detection3d_topic", + help="Output detections topic", + type=str, default="/opendr/detection3d") + parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", + type=str, default="cuda", choices=["cuda", "cpu"]) + args = parser.parse_args() + try: + if args.device == "cuda" and torch.cuda.is_available(): + device = "cuda" + elif args.device == "cuda": + print("GPU not found. Using CPU instead.") + device = "cpu" + else: + print("Using CPU.") + device = "cpu" + except: + print("Using CPU.") + device = "cpu" - # created node object voxel_node = ObjectDetection3DVoxelNode( device=device, - model_name=model_name, - model_config_path=model_config_path, - input_point_cloud_topic=input_point_cloud_topic, - temp_dir=temp_dir, + model_name=args.model_name, + model_config_path=args.model_config_path, + input_point_cloud_topic=args.input_point_cloud_topic, + temp_dir=args.temp_dir, + output_detection3d_topic=args.output_detection3d_topic, ) - # begin ROS communications - rospy.spin() + + voxel_node.listen() + +if __name__ == '__main__': + main() From 26db79b2f3dacc05b1747b8cfa30acb11dcdeae5 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Mon, 26 Sep 2022 20:50:30 +0000 Subject: [PATCH 02/31] Fix ros1 tracking 3d node --- .../scripts/object_tracking_3d_ab3dmot.py | 72 ++++++++++++++----- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py index b9927182ce..8a2c37cbaa 100644 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import os import torch from opendr.engine.learners import Learner @@ -91,29 +92,59 @@ def callback(self, data): self.tracking_id_publisher.publish(ros_ids) rospy.loginfo("Published tracking ids") -if __name__ == "__main__": - # Automatically run on GPU/CPU - device = "cuda:0" if torch.cuda.is_available() else "cpu" - # initialize ROS node - rospy.init_node("opendr_voxel_detection_3d", anonymous=True) - rospy.loginfo("AB3DMOT node started") - - input_point_cloud_topic = rospy.get_param( - "~input_point_cloud_topic", "/opendr/dataset_point_cloud" - ) - temp_dir = rospy.get_param("~temp_dir", "temp") - detector_model_name = rospy.get_param("~detector_model_name", "tanet_car_xyres_16") - detector_model_config_path = rospy.get_param( - "~detector_model_config_path", os.path.join( +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-dn", "--detector_model_name", help="Name of the trained model", + type=str, default="tanet_car_xyres_16") + parser.add_argument( + "-dc", "--detector_model_config_path", help="Path to a model .proto config", + type=str, default=os.path.join( "..", "..", "src", "opendr", "perception", "object_detection_3d", "voxel_object_detection_3d", "second_detector", "configs", "tanet", - "car", "test_short.proto" + "car", "xyres_16.proto" ) ) + parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + type=str, default="temp") + parser.add_argument("-i", "--input_point_cloud_topic", + help="Point Cloud topic provdied by either a point_cloud_dataset_node or any other 3D Point Cloud Node", + type=str, default="/opendr/dataset_point_cloud") + parser.add_argument("-od", "--output_detection3d_topic", + help="Output detections topic", + type=str, default="/opendr/detection3d") + parser.add_argument("-ot", "--output_tracking3d_id_topic", + help="Output tracking topic", + type=str, default="/opendr/tracking3d_id") + parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", + type=str, default="cuda", choices=["cuda", "cpu"]) + args = parser.parse_args() + + input_point_cloud_topic = args.input_point_cloud_topic + detector_model_name = args.detector_model_name + temp_dir = args.temp_dir + device = args.device + detector_model_config_path = args.detector_model_config_path + output_detection3d_topic = args.output_detection3d_topic + output_tracking3d_id_topic = args.output_tracking3d_id_topic + + try: + if args.device == "cuda" and torch.cuda.is_available(): + device = "cuda" + elif args.device == "cuda": + print("GPU not found. Using CPU instead.") + device = "cpu" + else: + print("Using CPU.") + device = "cpu" + except: + print("Using CPU.") + device = "cpu" detector = VoxelObjectDetection3DLearner( - device=device, temp_path=temp_dir, model_config_path=detector_model_config_path + device=device, + temp_path=temp_dir, + model_config_path=detector_model_config_path ) if not os.path.exists(os.path.join(temp_dir, detector_model_name)): VoxelObjectDetection3DLearner.download(detector_model_name, temp_dir) @@ -125,6 +156,11 @@ def callback(self, data): detector=detector, device=device, input_point_cloud_topic=input_point_cloud_topic, + output_detection3d_topic=output_detection3d_topic, + output_tracking3d_id_topic=output_tracking3d_id_topic, ) - # begin ROS communications - rospy.spin() + + ab3dmot_node.listen() + +if __name__ == '__main__': + main() From 039c4630386a967ae87997bd71fbe8f55a313742 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Mon, 26 Sep 2022 20:56:58 +0000 Subject: [PATCH 03/31] Fix ros1 tracking 2d fairmot node --- .../scripts/object_tracking_2d_fair_mot.py | 66 +++++++++++++------ 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py index 0f8d3a7373..5fe36a40b5 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import cv2 import torch import os @@ -166,27 +167,52 @@ def draw_predictions(frame, predictions: TrackingAnnotation, is_centered=False, ) -if __name__ == "__main__": - # Automatically run on GPU/CPU - device = "cuda:0" if torch.cuda.is_available() else "cpu" +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-n", "--model_name", help="Name of the trained model", + type=str, default="fairmot_dla34") + parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + type=str, default="temp") + parser.add_argument("-i", "--input_image_topic", + help="Input Image topic provdied by either an image_dataset_node, webcam or any other image node", + type=str, default="/opendr/dataset_image") + parser.add_argument("-od", "--output_detection_topic", + help="Output detections topic", + type=str, default="/opendr/detection") + parser.add_argument("-ot", "--output_tracking_id_topic", + help="Output detections topic", + type=str, default="/opendr/tracking_id") + parser.add_argument("-oi", "--output_image_topic", + help="Output detections topic", + type=str, default="/opendr/image_annotated") + parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", + type=str, default="cuda", choices=["cuda", "cpu"]) + args = parser.parse_args() + + try: + if args.device == "cuda" and torch.cuda.is_available(): + device = "cuda" + elif args.device == "cuda": + print("GPU not found. Using CPU instead.") + device = "cpu" + else: + print("Using CPU.") + device = "cpu" + except: + print("Using CPU.") + device = "cpu" - # initialize ROS node - rospy.init_node("opendr_fair_mot", anonymous=True) - rospy.loginfo("FairMOT node started") - - model_name = rospy.get_param("~model_name", "fairmot_dla34") - temp_dir = rospy.get_param("~temp_dir", "temp") - input_image_topic = rospy.get_param( - "~input_image_topic", "/opendr/dataset_image" - ) - rospy.loginfo("Using model_name: {}".format(model_name)) - - # created node object fair_mot_node = ObjectTracking2DFairMotNode( device=device, - model_name=model_name, - input_image_topic=input_image_topic, - temp_dir=temp_dir, + model_name=args.model_name, + input_image_topic=args.input_image_topic, + temp_dir=args.temp_dir, + output_detection_topic=args.output_detection_topic, + output_tracking_id_topic=args.output_tracking_id_topic, + output_image_topic=args.output_image_topic if args.output_image_topic != "None" else None, ) - # begin ROS communications - rospy.spin() + + fair_mot_node.listen() + +if __name__ == '__main__': + main() From 24e8be694817159ef520158ac9070e8085eb494c Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Mon, 26 Sep 2022 21:06:48 +0000 Subject: [PATCH 04/31] Fix ros1 tracking 2d deep sort node --- .../scripts/object_tracking_2d_deep_sort.py | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index 70d66c69a8..4a00687315 100644 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import cv2 import torch import os @@ -174,36 +175,61 @@ def draw_predictions(frame, predictions: TrackingAnnotation, is_centered=False, ) -if __name__ == "__main__": - # Automatically run on GPU/CPU - device = "cuda:0" if torch.cuda.is_available() else "cpu" - - # initialize ROS node - rospy.init_node("opendr_deep_sort", anonymous=True) - rospy.loginfo("Deep Sort node started") - - model_name = rospy.get_param("~model_name", "deep_sort") - temp_dir = rospy.get_param("~temp_dir", "temp") - input_image_topic = rospy.get_param( - "~input_image_topic", "/opendr/dataset_image" - ) - rospy.loginfo("Using model_name: {}".format(model_name)) +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-n", "--model_name", help="Name of the trained model", + type=str, default="deep_sort") + parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + type=str, default="temp") + parser.add_argument("-i", "--input_image_topic", + help="Input Image topic provdied by either an image_dataset_node, webcam or any other image node", + type=str, default="/opendr/dataset_image") + parser.add_argument("-od", "--output_detection_topic", + help="Output detections topic", + type=str, default="/opendr/detection") + parser.add_argument("-ot", "--output_tracking_id_topic", + help="Output detections topic", + type=str, default="/opendr/tracking_id") + parser.add_argument("-oi", "--output_image_topic", + help="Output detections topic", + type=str, default="/opendr/image_annotated") + parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", + type=str, default="cuda", choices=["cuda", "cpu"]) + args = parser.parse_args() + + try: + if args.device == "cuda" and torch.cuda.is_available(): + device = "cuda" + elif args.device == "cuda": + print("GPU not found. Using CPU instead.") + device = "cpu" + else: + print("Using CPU.") + device = "cpu" + except: + print("Using CPU.") + device = "cpu" detection_learner = ObjectTracking2DFairMotLearner( - device=device, temp_path=temp_dir, + device=device, temp_path=args.temp_dir, ) - if not os.path.exists(os.path.join(temp_dir, "fairmot_dla34")): - ObjectTracking2DFairMotLearner.download("fairmot_dla34", temp_dir) + if not os.path.exists(os.path.join(args.temp_dir, "fairmot_dla34")): + ObjectTracking2DFairMotLearner.download("fairmot_dla34", args.temp_dir) - detection_learner.load(os.path.join(temp_dir, "fairmot_dla34"), verbose=True) + detection_learner.load(os.path.join(args.temp_dir, "fairmot_dla34"), verbose=True) - # created node object deep_sort_node = ObjectTracking2DDeepSortNode( detector=detection_learner, device=device, - model_name=model_name, - input_image_topic=input_image_topic, - temp_dir=temp_dir, + model_name=args.model_name, + input_image_topic=args.input_image_topic, + temp_dir=args.temp_dir, + output_detection_topic=args.output_detection_topic, + output_tracking_id_topic=args.output_tracking_id_topic, + output_image_topic=args.output_image_topic if args.output_image_topic != "None" else None, ) - # begin ROS communications - rospy.spin() + + deep_sort_node.listen() + +if __name__ == '__main__': + main() From c9c7097b4e11b397ac426e547c7ac4abba11698e Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Mon, 26 Sep 2022 21:10:08 +0000 Subject: [PATCH 05/31] Fix ros1 point cloud dataset node --- .../perception/scripts/point_cloud_dataset.py | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py index 0701e1005e..009ddda460 100644 --- a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import os import rospy import time @@ -27,6 +28,7 @@ def __init__( self, dataset: DatasetIterator, output_point_cloud_topic="/opendr/dataset_point_cloud", + data_fps=10, ): """ Creates a ROS Node for publishing dataset point clouds @@ -36,6 +38,7 @@ def __init__( self.dataset = dataset # Initialize OpenDR ROSBridge object self.bridge = ROSBridge() + self.delay = 1.0 / data_fps if output_point_cloud_topic is not None: self.output_point_cloud_publisher = rospy.Publisher( @@ -55,20 +58,33 @@ def start(self): ) self.output_point_cloud_publisher.publish(message) - time.sleep(0.1) + time.sleep(self.delay) i += 1 - -if __name__ == "__main__": - - rospy.init_node('opendr_point_cloud_dataset') - - dataset_path = "KITTI/opendr_nano_kitti" +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-d", "--dataset_path", + help="Path to a dataset. If does not exist, nano KITTI dataset will be downloaded there.", + type=str, default="KITTI/opendr_nano_kitti") + parser.add_argument("-ks", "--kitti_subsets_path", + help="Path to kitti subsets. Used only if a KITTI dataset is downloaded", + type=str, + default="../../src/opendr/perception/object_detection_3d/datasets/nano_kitti_subsets") + parser.add_argument("-o", "--output_point_cloud_topic", help="Topic name to upload the data", + type=str, default="/opendr/dataset_point_cloud") + parser.add_argument("-f", "--fps", help="Data FPS", + type=float, default=10) + args = parser.parse_args() + + dataset_path = args.dataset_path + kitti_subsets_path = args.kitti_subsets_path + output_point_cloud_topic = args.output_point_cloud_topic + data_fps = args.fps if not os.path.exists(dataset_path): dataset_path = KittiDataset.download_nano_kitti( - "KITTI", kitti_subsets_path="../../src/opendr/perception/object_detection_3d/datasets/nano_kitti_subsets", + "KITTI", kitti_subsets_path=kitti_subsets_path, create_dir=True, ).path @@ -78,5 +94,11 @@ def start(self): dataset_path + "/training/calib", ) - dataset_node = PointCloudDatasetNode(dataset) + dataset_node = PointCloudDatasetNode( + dataset, output_point_cloud_topic=output_point_cloud_topic, data_fps=data_fps + ) + dataset_node.start() + +if __name__ == '__main__': + main() From 949b0cbb6235c98906cfaaaa2d823461e6aaa02f Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Mon, 26 Sep 2022 21:12:05 +0000 Subject: [PATCH 06/31] Fix ros1 image dataset node --- .../src/perception/scripts/image_dataset.py | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/image_dataset.py b/projects/opendr_ws/src/perception/scripts/image_dataset.py index 0ce4ee3850..5170a7a93b 100644 --- a/projects/opendr_ws/src/perception/scripts/image_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/image_dataset.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import os import rospy import time @@ -27,6 +28,7 @@ def __init__( self, dataset: DatasetIterator, output_image_topic="/opendr/dataset_image", + data_fps=30, ): """ Creates a ROS Node for publishing dataset images @@ -36,6 +38,7 @@ def __init__( self.dataset = dataset # Initialize OpenDR ROSBridge object self.bridge = ROSBridge() + self.delay = 1.0 / data_fps if output_image_topic is not None: self.output_image_publisher = rospy.Publisher( @@ -57,14 +60,32 @@ def start(self): ) self.output_image_publisher.publish(message) - time.sleep(0.1) + time.sleep(self.delay) i += 1 -if __name__ == "__main__": +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-d", "--dataset_path", help="Path to a dataset", + type=str, default="KITTI/opendr_nano_kitti") + parser.add_argument( + "-ks", "--mot20_subsets_path", help="Path to mot20 subsets", + type=str, default=os.path.join( + "..", "..", "src", "opendr", "perception", "object_tracking_2d", + "datasets", "splits", "nano_mot20.train" + ) + ) + parser.add_argument("-o", "--output_image_topic", help="Topic name to upload the data", + type=str, default="/opendr/dataset_image") + parser.add_argument("-f", "--fps", help="Data FPS", + type=float, default=30) + args = parser.parse_args() - rospy.init_node('opendr_image_dataset') + dataset_path = args.dataset_path + mot20_subsets_path = args.mot20_subsets_path + output_image_topic = args.output_image_topic + data_fps = args.fps dataset_path = MotDataset.download_nano_mot20( "MOT", True @@ -73,12 +94,17 @@ def start(self): dataset = RawMotDatasetIterator( dataset_path, { - "mot20": os.path.join( - "..", "..", "src", "opendr", "perception", "object_tracking_2d", - "datasets", "splits", "nano_mot20.train" - ) + "mot20": mot20_subsets_path }, scan_labels=False ) - dataset_node = ImageDatasetNode(dataset) + dataset_node = ImageDatasetNode( + dataset, + output_image_topic=output_image_topic, + data_fps=data_fps, + ) + dataset_node.start() + +if __name__ == '__main__': + main() From 91db7e1bd804432020753a0ac3d435b4531b056a Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Mon, 26 Sep 2022 21:13:28 +0000 Subject: [PATCH 07/31] Fix style errors --- projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py index 009ddda460..9b9b3e5c33 100644 --- a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py @@ -62,6 +62,7 @@ def start(self): i += 1 + def main(): parser = argparse.ArgumentParser() parser.add_argument("-d", "--dataset_path", From 39f3fc9c658ee4f1497bb2d896b6579a4699b8f3 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 8 Nov 2022 22:30:12 +0000 Subject: [PATCH 08/31] Fix point cloud dataset init --- .../src/perception/scripts/point_cloud_dataset.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py index 9b9b3e5c33..9607d96227 100755 --- a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py @@ -34,16 +34,13 @@ def __init__( Creates a ROS Node for publishing dataset point clouds """ - # Initialize the face detector self.dataset = dataset - # Initialize OpenDR ROSBridge object self.bridge = ROSBridge() self.delay = 1.0 / data_fps - if output_point_cloud_topic is not None: - self.output_point_cloud_publisher = rospy.Publisher( - output_point_cloud_topic, ROS_PointCloud, queue_size=10 - ) + self.output_point_cloud_publisher = rospy.Publisher( + output_point_cloud_topic, ROS_PointCloud, queue_size=10 + ) def start(self): i = 0 @@ -95,11 +92,16 @@ def main(): dataset_path + "/training/calib", ) + rospy.init_node('point_cloud_dataset') + rospy.loginfo("PointCloudDatasetNode started.") + dataset_node = PointCloudDatasetNode( dataset, output_point_cloud_topic=output_point_cloud_topic, data_fps=data_fps ) dataset_node.start() + rospy.spin() + if __name__ == '__main__': main() From f863cb2533a8e0a5681ceb833daac0bc284ce8b9 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 8 Nov 2022 23:46:02 +0000 Subject: [PATCH 09/31] Fix image dataset init node --- projects/opendr_ws/src/perception/scripts/image_dataset.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/opendr_ws/src/perception/scripts/image_dataset.py b/projects/opendr_ws/src/perception/scripts/image_dataset.py index 5170a7a93b..709f4c6566 100755 --- a/projects/opendr_ws/src/perception/scripts/image_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/image_dataset.py @@ -98,6 +98,9 @@ def main(): }, scan_labels=False ) + + rospy.init_node("image_dataset", anonymous=True) + dataset_node = ImageDatasetNode( dataset, output_image_topic=output_image_topic, @@ -106,5 +109,6 @@ def main(): dataset_node.start() + if __name__ == '__main__': main() From 2e74b4ed46ee68409678207132bb90335b42533d Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 8 Nov 2022 23:46:28 +0000 Subject: [PATCH 10/31] Fix fair mot init --- .../scripts/object_tracking_2d_fair_mot.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py index 5fe36a40b5..a46dd1d3ca 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py @@ -68,8 +68,8 @@ def __init__( self.learner.load(os.path.join(temp_dir, model_name), verbose=True) - # Initialize OpenDR ROSBridge object self.bridge = ROSBridge() + self.input_image_topic = input_image_topic self.detection_publisher = rospy.Publisher( output_detection_topic, Detection2DArray, queue_size=10 @@ -83,8 +83,6 @@ def __init__( output_image_topic, ROS_Image, queue_size=10 ) - rospy.Subscriber(input_image_topic, ROS_Image, self.callback) - def callback(self, data): """ Callback that process the input data and publishes to the corresponding topics @@ -121,6 +119,16 @@ def callback(self, data): self.tracking_id_publisher.publish(ros_ids) rospy.loginfo("Published tracking ids") + def listen(self): + """ + Start the node and begin processing input data. + """ + rospy.init_node('object_tracking_2d_fair_mot_node', anonymous=True) + rospy.Subscriber(self.input_image_topic, ROS_Image, self.callback, queue_size=1, buff_size=10000000) + + rospy.loginfo("Object Tracking 2D Fair Mot Node started.") + rospy.spin() + colors = [ (255, 0, 255), @@ -171,7 +179,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("-n", "--model_name", help="Name of the trained model", type=str, default="fairmot_dla34") - parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") parser.add_argument("-i", "--input_image_topic", help="Input Image topic provdied by either an image_dataset_node, webcam or any other image node", From b8ab5f06ab804051f97561f2acd606f7aeae2514 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 8 Nov 2022 23:46:44 +0000 Subject: [PATCH 11/31] Fix image format rgb8 to bgr8 --- projects/opendr_ws/src/perception/scripts/image_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/opendr_ws/src/perception/scripts/image_dataset.py b/projects/opendr_ws/src/perception/scripts/image_dataset.py index 709f4c6566..5c1abece2c 100755 --- a/projects/opendr_ws/src/perception/scripts/image_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/image_dataset.py @@ -56,7 +56,7 @@ def start(self): rospy.loginfo("Publishing image [" + str(i) + "]") message = self.bridge.to_ros_image( - image, encoding="rgb8" + image, encoding="bgr8" ) self.output_image_publisher.publish(message) From 05147061c88479a62fbe36447ff034c12024afd4 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 8 Nov 2022 23:46:55 +0000 Subject: [PATCH 12/31] Fix 3d detection init node --- .../scripts/object_detection_3d_voxel.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py index d5d5b95092..3e9b131885 100755 --- a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py +++ b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py @@ -59,15 +59,13 @@ def __init__( self.learner.load(os.path.join(temp_dir, model_name), verbose=True) - # Initialize OpenDR ROSBridge object + self.input_point_cloud_topic = input_point_cloud_topic self.bridge = ROSBridge() self.detection_publisher = rospy.Publisher( output_detection3d_topic, Detection3DArray, queue_size=1 ) - rospy.Subscriber(input_point_cloud_topic, ROS_PointCloud, self.callback) - def callback(self, data): """ Callback that process the input data and publishes to the corresponding topics @@ -81,9 +79,18 @@ def callback(self, data): # Convert detected boxes to ROS type and publish ros_boxes = self.bridge.to_ros_boxes_3d(detection_boxes, classes=["Car", "Van", "Truck", "Pedestrian", "Cyclist"]) - if self.detection_publisher is not None: - self.detection_publisher.publish(ros_boxes) - rospy.loginfo("Published detection boxes") + self.detection_publisher.publish(ros_boxes) + rospy.loginfo("Published detection boxes") + + def listen(self): + """ + Start the node and begin processing input data. + """ + rospy.init_node('voxel_detection_3d', anonymous=True) + rospy.Subscriber(self.input_point_cloud_topic, ROS_PointCloud, self.callback, queue_size=1, buff_size=10000000) + + rospy.loginfo("Object Detection 3D Voxel Node started.") + rospy.spin() def main(): @@ -98,7 +105,7 @@ def main(): "car", "xyres_16.proto" ) ) - parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") parser.add_argument("-i", "--input_point_cloud_topic", help="Point Cloud topic provdied by either a point_cloud_dataset_node or any other 3D Point Cloud Node", @@ -133,5 +140,6 @@ def main(): voxel_node.listen() + if __name__ == '__main__': main() From 0e5715698a626c9c4c0a1571e245092b3d50454f Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 00:02:36 +0000 Subject: [PATCH 13/31] Fix re-download of the dataset --- .../opendr_ws/src/perception/scripts/image_dataset.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/image_dataset.py b/projects/opendr_ws/src/perception/scripts/image_dataset.py index 5c1abece2c..6c1dd14d67 100755 --- a/projects/opendr_ws/src/perception/scripts/image_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/image_dataset.py @@ -68,7 +68,7 @@ def start(self): def main(): parser = argparse.ArgumentParser() parser.add_argument("-d", "--dataset_path", help="Path to a dataset", - type=str, default="KITTI/opendr_nano_kitti") + type=str, default="MOT") parser.add_argument( "-ks", "--mot20_subsets_path", help="Path to mot20 subsets", type=str, default=os.path.join( @@ -87,9 +87,10 @@ def main(): output_image_topic = args.output_image_topic data_fps = args.fps - dataset_path = MotDataset.download_nano_mot20( - "MOT", True - ).path + if not os.path.exists(dataset_path): + dataset_path = MotDataset.download_nano_mot20( + "MOT", True + ).path dataset = RawMotDatasetIterator( dataset_path, From d099939c336c5a748f142662ed1d1f016a7441f7 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 00:18:39 +0000 Subject: [PATCH 14/31] Fix fairmot conditional computing and typing --- .../scripts/object_tracking_2d_fair_mot.py | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py index a46dd1d3ca..d40966851d 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py @@ -17,7 +17,7 @@ import cv2 import torch import os -from opendr.engine.target import TrackingAnnotation +from opendr.engine.target import TrackingAnnotationList import rospy from vision_msgs.msg import Detection2DArray from std_msgs.msg import Int32MultiArray @@ -33,9 +33,9 @@ class ObjectTracking2DFairMotNode: def __init__( self, input_image_topic="/usb_cam/image_raw", - output_detection_topic="/opendr/detection", - output_tracking_id_topic="/opendr/tracking_id", - output_image_topic="/opendr/image_annotated", + output_detection_topic="/opendr/fairmot_detection", + output_tracking_id_topic="/opendr/fairmot_tracking_id", + output_image_topic="/opendr/fairmot_image_annotated", device="cuda:0", model_name="fairmot_dla34", temp_dir="temp", @@ -59,7 +59,6 @@ def __init__( :type temp_dir: str """ - # # Initialize the face detector self.learner = ObjectTracking2DFairMotLearner( device=device, temp_path=temp_dir, ) @@ -103,19 +102,16 @@ def callback(self, data): self.output_image_publisher.publish(message) rospy.loginfo("Published annotated image") - detection_boxes = tracking_boxes.bounding_box_list() - ids = [tracking_box.id for tracking_box in tracking_boxes] - - # Convert detected boxes to ROS type and publish - ros_boxes = self.bridge.to_ros_boxes(detection_boxes) if self.detection_publisher is not None: + detection_boxes = tracking_boxes.bounding_box_list() + ros_boxes = self.bridge.to_ros_boxes(detection_boxes) self.detection_publisher.publish(ros_boxes) rospy.loginfo("Published detection boxes") - ros_ids = Int32MultiArray() - ros_ids.data = ids - if self.tracking_id_publisher is not None: + ids = [tracking_box.id for tracking_box in tracking_boxes] + ros_ids = Int32MultiArray() + ros_ids.data = ids self.tracking_id_publisher.publish(ros_ids) rospy.loginfo("Published tracking ids") @@ -140,7 +136,7 @@ def listen(self): ] -def draw_predictions(frame, predictions: TrackingAnnotation, is_centered=False, is_flipped_xy=True): +def draw_predictions(frame, predictions: TrackingAnnotationList, is_centered=False, is_flipped_xy=True): global colors w, h, _ = frame.shape @@ -182,17 +178,17 @@ def main(): parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") parser.add_argument("-i", "--input_image_topic", - help="Input Image topic provdied by either an image_dataset_node, webcam or any other image node", + help="Input Image topic provided by either an image_dataset_node, webcam or any other image node", type=str, default="/opendr/dataset_image") parser.add_argument("-od", "--output_detection_topic", help="Output detections topic", - type=str, default="/opendr/detection") + type=str, default="/opendr/fairmot_detection") parser.add_argument("-ot", "--output_tracking_id_topic", help="Output detections topic", - type=str, default="/opendr/tracking_id") + type=str, default="/opendr/fairmot_tracking_id") parser.add_argument("-oi", "--output_image_topic", help="Output detections topic", - type=str, default="/opendr/image_annotated") + type=str, default="/opendr/fairmot_image_annotated") parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", type=str, default="cuda", choices=["cuda", "cpu"]) args = parser.parse_args() @@ -215,12 +211,13 @@ def main(): model_name=args.model_name, input_image_topic=args.input_image_topic, temp_dir=args.temp_dir, - output_detection_topic=args.output_detection_topic, - output_tracking_id_topic=args.output_tracking_id_topic, + output_detection_topic=args.output_detection_topic if args.output_detection_topic != "None" else None, + output_tracking_id_topic=args.output_tracking_id_topic if args.output_tracking_id_topic != "None" else None, output_image_topic=args.output_image_topic if args.output_image_topic != "None" else None, ) fair_mot_node.listen() + if __name__ == '__main__': main() From 1f1fbc147b7b52f911b1fc3e35c07edca74bda39 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 00:18:52 +0000 Subject: [PATCH 15/31] Fix deepsort init node --- .../scripts/object_tracking_2d_deep_sort.py | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index 4a00687315..6bdda7d04c 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -17,7 +17,7 @@ import cv2 import torch import os -from opendr.engine.target import TrackingAnnotation +from opendr.engine.target import TrackingAnnotationList import rospy from vision_msgs.msg import Detection2DArray from std_msgs.msg import Int32MultiArray @@ -36,9 +36,9 @@ def __init__( self, detector: Learner, input_image_topic="/usb_cam/image_raw", - output_detection_topic="/opendr/detection", - output_tracking_id_topic="/opendr/tracking_id", - output_image_topic="/opendr/image_annotated", + output_detection_topic="/opendr/deep_sort_detection", + output_tracking_id_topic="/opendr/deep_sort_tracking_id", + output_image_topic="/opendr/deep_sort_image_annotated", device="cuda:0", model_name="deep_sort", temp_dir="temp", @@ -64,7 +64,6 @@ def __init__( :type temp_dir: str """ - # # Initialize the face detector self.detector = detector self.learner = ObjectTracking2DDeepSortLearner( device=device, temp_path=temp_dir, @@ -74,8 +73,9 @@ def __init__( self.learner.load(os.path.join(temp_dir, model_name), verbose=True) - # Initialize OpenDR ROSBridge object self.bridge = ROSBridge() + self.input_image_topic = input_image_topic + self.tracking_id_publisher = rospy.Publisher( output_tracking_id_topic, Int32MultiArray, queue_size=10 ) @@ -129,6 +129,16 @@ def callback(self, data): self.tracking_id_publisher.publish(ros_ids) rospy.loginfo("Published tracking ids") + def listen(self): + """ + Start the node and begin processing input data. + """ + rospy.init_node('object_tracking_2d_deep_sort_node', anonymous=True) + rospy.Subscriber(self.input_image_topic, ROS_Image, self.callback, queue_size=1, buff_size=10000000) + + rospy.loginfo("Object Tracking 2D Deep Sort Node started.") + rospy.spin() + colors = [ (255, 0, 255), @@ -140,7 +150,7 @@ def callback(self, data): ] -def draw_predictions(frame, predictions: TrackingAnnotation, is_centered=False, is_flipped_xy=True): +def draw_predictions(frame, predictions: TrackingAnnotationList, is_centered=False, is_flipped_xy=True): global colors w, h, _ = frame.shape @@ -179,20 +189,20 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("-n", "--model_name", help="Name of the trained model", type=str, default="deep_sort") - parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") parser.add_argument("-i", "--input_image_topic", - help="Input Image topic provdied by either an image_dataset_node, webcam or any other image node", + help="Input Image topic provided by either an image_dataset_node, webcam or any other image node", type=str, default="/opendr/dataset_image") parser.add_argument("-od", "--output_detection_topic", help="Output detections topic", - type=str, default="/opendr/detection") + type=str, default="/opendr/deep_sort_detection") parser.add_argument("-ot", "--output_tracking_id_topic", help="Output detections topic", - type=str, default="/opendr/tracking_id") + type=str, default="/opendr/deep_sort_tracking_id") parser.add_argument("-oi", "--output_image_topic", help="Output detections topic", - type=str, default="/opendr/image_annotated") + type=str, default="/opendr/deep_sort_image_annotated") parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", type=str, default="cuda", choices=["cuda", "cpu"]) args = parser.parse_args() @@ -224,12 +234,13 @@ def main(): model_name=args.model_name, input_image_topic=args.input_image_topic, temp_dir=args.temp_dir, - output_detection_topic=args.output_detection_topic, - output_tracking_id_topic=args.output_tracking_id_topic, + output_detection_topic=args.output_detection_topic if args.output_detection_topic != "None" else None, + output_tracking_id_topic=args.output_tracking_id_topic if args.output_tracking_id_topic != "None" else None, output_image_topic=args.output_image_topic if args.output_image_topic != "None" else None, ) deep_sort_node.listen() + if __name__ == '__main__': main() From 81875c1be97fb1abda164d3ecdc48ae104ebd68d Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 00:19:01 +0000 Subject: [PATCH 16/31] Fix ab3dmot init node --- .../scripts/object_tracking_3d_ab3dmot.py | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py index 8a2c37cbaa..29fad766b6 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py @@ -40,7 +40,7 @@ def __init__( :param detector: Learner that proides 3D object detections :type detector: Learner :param input_point_cloud_topic: Topic from which we are reading the input point cloud - :type input_image_topic: str + :type input_point_cloud_topic: str :param output_detection3d_topic: Topic to which we are publishing the annotations :type output_detection3d_topic: str :param output_tracking3d_id_topic: Topic to which we are publishing the tracking ids @@ -54,15 +54,18 @@ def __init__( device=device ) - # Initialize OpenDR ROSBridge object self.bridge = ROSBridge() + self.input_point_cloud_topic = input_point_cloud_topic - self.detection_publisher = rospy.Publisher( - output_detection3d_topic, Detection3DArray, queue_size=10 - ) - self.tracking_id_publisher = rospy.Publisher( - output_tracking3d_id_topic, Int32MultiArray, queue_size=10 - ) + if output_detection3d_topic is not None: + self.detection_publisher = rospy.Publisher( + output_detection3d_topic, Detection3DArray, queue_size=10 + ) + + if output_tracking3d_id_topic is not None: + self.tracking_id_publisher = rospy.Publisher( + output_tracking3d_id_topic, Int32MultiArray, queue_size=10 + ) rospy.Subscriber(input_point_cloud_topic, ROS_PointCloud, self.callback) @@ -77,21 +80,30 @@ def callback(self, data): point_cloud = self.bridge.from_ros_point_cloud(data) detection_boxes = self.detector.infer(point_cloud) tracking_boxes = self.learner.infer(detection_boxes) - ids = [tracking_box.id for tracking_box in tracking_boxes] - # Convert detected boxes to ROS type and publish - ros_boxes = self.bridge.to_ros_boxes_3d(detection_boxes, classes=["Car", "Van", "Truck", "Pedestrian", "Cyclist"]) if self.detection_publisher is not None: + # Convert detected boxes to ROS type and publish + ros_boxes = self.bridge.to_ros_boxes_3d(detection_boxes, classes=["Car", "Van", "Truck", "Pedestrian", "Cyclist"]) self.detection_publisher.publish(ros_boxes) rospy.loginfo("Published detection boxes") - ros_ids = Int32MultiArray() - ros_ids.data = ids - if self.tracking_id_publisher is not None: + ids = [tracking_box.id for tracking_box in tracking_boxes] + ros_ids = Int32MultiArray() + ros_ids.data = ids self.tracking_id_publisher.publish(ros_ids) rospy.loginfo("Published tracking ids") + def listen(self): + """ + Start the node and begin processing input data. + """ + rospy.init_node('ab3dmot_tracking_3d', anonymous=True) + rospy.Subscriber(self.input_point_cloud_topic, ROS_PointCloud, self.callback, queue_size=1, buff_size=10000000) + + rospy.loginfo("Object Tracking 3D Ab3dmot Node started.") + rospy.spin() + def main(): parser = argparse.ArgumentParser() @@ -105,10 +117,10 @@ def main(): "car", "xyres_16.proto" ) ) - parser.add_argument("-t", "--temp_dir", help="Path to a temp dir with models", + parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") parser.add_argument("-i", "--input_point_cloud_topic", - help="Point Cloud topic provdied by either a point_cloud_dataset_node or any other 3D Point Cloud Node", + help="Point Cloud topic provided by either a point_cloud_dataset_node or any other 3D Point Cloud Node", type=str, default="/opendr/dataset_point_cloud") parser.add_argument("-od", "--output_detection3d_topic", help="Output detections topic", @@ -123,7 +135,6 @@ def main(): input_point_cloud_topic = args.input_point_cloud_topic detector_model_name = args.detector_model_name temp_dir = args.temp_dir - device = args.device detector_model_config_path = args.detector_model_config_path output_detection3d_topic = args.output_detection3d_topic output_tracking3d_id_topic = args.output_tracking3d_id_topic @@ -156,11 +167,12 @@ def main(): detector=detector, device=device, input_point_cloud_topic=input_point_cloud_topic, - output_detection3d_topic=output_detection3d_topic, - output_tracking3d_id_topic=output_tracking3d_id_topic, + output_detection3d_topic=output_detection3d_topic if output_detection3d_topic != "None" else None, + output_tracking3d_id_topic=output_tracking3d_id_topic if output_tracking3d_id_topic != "None" else None, ) ab3dmot_node.listen() + if __name__ == '__main__': main() From 348e719c6daaa08ab778abe51bbc1429337b31be Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 00:19:22 +0000 Subject: [PATCH 17/31] Add point cloud dataset anonymous node --- .../opendr_ws/src/perception/scripts/point_cloud_dataset.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py index 9607d96227..b6153f126f 100755 --- a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py @@ -92,8 +92,7 @@ def main(): dataset_path + "/training/calib", ) - rospy.init_node('point_cloud_dataset') - rospy.loginfo("PointCloudDatasetNode started.") + rospy.init_node('point_cloud_dataset', anonymous=True) dataset_node = PointCloudDatasetNode( dataset, output_point_cloud_topic=output_point_cloud_topic, data_fps=data_fps From fb709a456e27596da0aa0279ea2796c55e9b5008 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 00:19:31 +0000 Subject: [PATCH 18/31] Fix typo --- .../src/perception/scripts/object_detection_3d_voxel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py index 3e9b131885..826d13e791 100755 --- a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py +++ b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py @@ -108,7 +108,7 @@ def main(): parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") parser.add_argument("-i", "--input_point_cloud_topic", - help="Point Cloud topic provdied by either a point_cloud_dataset_node or any other 3D Point Cloud Node", + help="Point Cloud topic provided by either a point_cloud_dataset_node or any other 3D Point Cloud Node", type=str, default="/opendr/dataset_point_cloud") parser.add_argument("-o", "--output_detection3d_topic", help="Output detections topic", From 14c74e729ccc81693294c17e9e69f09e2e90b7e0 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 00:21:05 +0000 Subject: [PATCH 19/31] Fix phrasing --- projects/opendr_ws/src/perception/scripts/image_dataset.py | 2 +- .../opendr_ws/src/perception/scripts/point_cloud_dataset.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/image_dataset.py b/projects/opendr_ws/src/perception/scripts/image_dataset.py index 6c1dd14d67..77c2fa0eaa 100755 --- a/projects/opendr_ws/src/perception/scripts/image_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/image_dataset.py @@ -76,7 +76,7 @@ def main(): "datasets", "splits", "nano_mot20.train" ) ) - parser.add_argument("-o", "--output_image_topic", help="Topic name to upload the data", + parser.add_argument("-o", "--output_image_topic", help="Topic name to publish the data", type=str, default="/opendr/dataset_image") parser.add_argument("-f", "--fps", help="Data FPS", type=float, default=30) diff --git a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py index b6153f126f..2859e8db47 100755 --- a/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/point_cloud_dataset.py @@ -69,7 +69,7 @@ def main(): help="Path to kitti subsets. Used only if a KITTI dataset is downloaded", type=str, default="../../src/opendr/perception/object_detection_3d/datasets/nano_kitti_subsets") - parser.add_argument("-o", "--output_point_cloud_topic", help="Topic name to upload the data", + parser.add_argument("-o", "--output_point_cloud_topic", help="Topic name to publish the data", type=str, default="/opendr/dataset_point_cloud") parser.add_argument("-f", "--fps", help="Data FPS", type=float, default=10) From 1bde9d6af1d73ad4449e1db1838befb251b9e72a Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Wed, 9 Nov 2022 10:35:27 +0000 Subject: [PATCH 20/31] Remove extra print --- .../src/perception/scripts/object_tracking_2d_deep_sort.py | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index 6bdda7d04c..a1ceaea909 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -102,7 +102,6 @@ def callback(self, data): image = self.bridge.from_ros_image(data, encoding="bgr8") detection_boxes = self.detector.infer(image) image_with_detections = ImageWithDetections(image.numpy(), detection_boxes) - print(image_with_detections.data.shape) tracking_boxes = self.learner.infer(image_with_detections) if self.output_image_publisher is not None: From 2e6a8cf3a18b48ab62663d273db41be94b215be5 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 15 Nov 2022 14:08:46 +0100 Subject: [PATCH 21/31] Apply suggestions from code review Co-authored-by: Kostas Tsampazis <27914645+tsampazk@users.noreply.github.com> --- .../perception/scripts/object_detection_3d_voxel.py | 2 +- .../perception/scripts/object_tracking_2d_deep_sort.py | 10 +++++----- .../perception/scripts/object_tracking_2d_fair_mot.py | 10 +++++----- .../perception/scripts/object_tracking_3d_ab3dmot.py | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py index 826d13e791..34f5c09f56 100755 --- a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py +++ b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py @@ -96,7 +96,7 @@ def listen(self): def main(): parser = argparse.ArgumentParser() parser.add_argument("-n", "--model_name", help="Name of the trained model", - type=str, default="tanet_car_xyres_16") + type=str, default="tanet_car_xyres_16", choices=["tanet_car_xyres_16"]) parser.add_argument( "-c", "--model_config_path", help="Path to a model .proto config", type=str, default=os.path.join( diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index a1ceaea909..2383103820 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -35,10 +35,10 @@ class ObjectTracking2DDeepSortNode: def __init__( self, detector: Learner, - input_image_topic="/usb_cam/image_raw", + input_rgb_image_topic="/usb_cam/image_raw", output_detection_topic="/opendr/deep_sort_detection", output_tracking_id_topic="/opendr/deep_sort_tracking_id", - output_image_topic="/opendr/deep_sort_image_annotated", + output_rgb_image_topic="/opendr/deep_sort_image_annotated", device="cuda:0", model_name="deep_sort", temp_dir="temp", @@ -187,10 +187,10 @@ def draw_predictions(frame, predictions: TrackingAnnotationList, is_centered=Fal def main(): parser = argparse.ArgumentParser() parser.add_argument("-n", "--model_name", help="Name of the trained model", - type=str, default="deep_sort") + type=str, default="deep_sort", choices=["deep_sort"]) parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") - parser.add_argument("-i", "--input_image_topic", + parser.add_argument("-i", "--input_rgb_image_topic", help="Input Image topic provided by either an image_dataset_node, webcam or any other image node", type=str, default="/opendr/dataset_image") parser.add_argument("-od", "--output_detection_topic", @@ -199,7 +199,7 @@ def main(): parser.add_argument("-ot", "--output_tracking_id_topic", help="Output detections topic", type=str, default="/opendr/deep_sort_tracking_id") - parser.add_argument("-oi", "--output_image_topic", + parser.add_argument("-oi", "--output_rgb_image_topic", help="Output detections topic", type=str, default="/opendr/deep_sort_image_annotated") parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py index d40966851d..8e5b96c091 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py @@ -32,10 +32,10 @@ class ObjectTracking2DFairMotNode: def __init__( self, - input_image_topic="/usb_cam/image_raw", + input_rgb_image_topic="/usb_cam/image_raw", output_detection_topic="/opendr/fairmot_detection", output_tracking_id_topic="/opendr/fairmot_tracking_id", - output_image_topic="/opendr/fairmot_image_annotated", + output_rgb_image_topic="/opendr/fairmot_image_annotated", device="cuda:0", model_name="fairmot_dla34", temp_dir="temp", @@ -174,10 +174,10 @@ def draw_predictions(frame, predictions: TrackingAnnotationList, is_centered=Fal def main(): parser = argparse.ArgumentParser() parser.add_argument("-n", "--model_name", help="Name of the trained model", - type=str, default="fairmot_dla34") + type=str, default="fairmot_dla34", choices=["fairmot_dla34"]) parser.add_argument("-t", "--temp_dir", help="Path to a temporary directory with models", type=str, default="temp") - parser.add_argument("-i", "--input_image_topic", + parser.add_argument("-i", "--input_rgb_image_topic", help="Input Image topic provided by either an image_dataset_node, webcam or any other image node", type=str, default="/opendr/dataset_image") parser.add_argument("-od", "--output_detection_topic", @@ -186,7 +186,7 @@ def main(): parser.add_argument("-ot", "--output_tracking_id_topic", help="Output detections topic", type=str, default="/opendr/fairmot_tracking_id") - parser.add_argument("-oi", "--output_image_topic", + parser.add_argument("-oi", "--output_rgb_image_topic", help="Output detections topic", type=str, default="/opendr/fairmot_image_annotated") parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py index 29fad766b6..b054a40e41 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py @@ -37,7 +37,7 @@ def __init__( ): """ Creates a ROS Node for 3D object tracking - :param detector: Learner that proides 3D object detections + :param detector: Learner that provides 3D object detections :type detector: Learner :param input_point_cloud_topic: Topic from which we are reading the input point cloud :type input_point_cloud_topic: str @@ -108,7 +108,7 @@ def listen(self): def main(): parser = argparse.ArgumentParser() parser.add_argument("-dn", "--detector_model_name", help="Name of the trained model", - type=str, default="tanet_car_xyres_16") + type=str, default="tanet_car_xyres_16", choices =["tanet_car_xyres_16"]) parser.add_argument( "-dc", "--detector_model_config_path", help="Path to a model .proto config", type=str, default=os.path.join( @@ -126,7 +126,7 @@ def main(): help="Output detections topic", type=str, default="/opendr/detection3d") parser.add_argument("-ot", "--output_tracking3d_id_topic", - help="Output tracking topic", + help="Output tracking id topic", type=str, default="/opendr/tracking3d_id") parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", type=str, default="cuda", choices=["cuda", "cpu"]) From e7fbb96082851b289491f71a9c43bdbbfd5d102e Mon Sep 17 00:00:00 2001 From: ad-daniel Date: Tue, 22 Nov 2022 10:17:57 +0100 Subject: [PATCH 22/31] Fix sources --- .../src/perception/scripts/object_tracking_3d_ab3dmot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py index b054a40e41..6c565bc577 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_3d_ab3dmot.py @@ -108,7 +108,7 @@ def listen(self): def main(): parser = argparse.ArgumentParser() parser.add_argument("-dn", "--detector_model_name", help="Name of the trained model", - type=str, default="tanet_car_xyres_16", choices =["tanet_car_xyres_16"]) + type=str, default="tanet_car_xyres_16", choices=["tanet_car_xyres_16"]) parser.add_argument( "-dc", "--detector_model_config_path", help="Path to a model .proto config", type=str, default=os.path.join( From c4a896ba7d948a0d0a15232d2f6c27b057351339 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 22 Nov 2022 09:51:49 +0000 Subject: [PATCH 23/31] Fix names --- .../src/perception/scripts/image_dataset.py | 15 ++++---- .../scripts/object_detection_3d_voxel.py | 2 +- .../scripts/object_tracking_2d_deep_sort.py | 36 +++++++++---------- .../scripts/object_tracking_2d_fair_mot.py | 23 ++++++------ 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/image_dataset.py b/projects/opendr_ws/src/perception/scripts/image_dataset.py index 77c2fa0eaa..44977742df 100755 --- a/projects/opendr_ws/src/perception/scripts/image_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/image_dataset.py @@ -27,7 +27,7 @@ class ImageDatasetNode: def __init__( self, dataset: DatasetIterator, - output_image_topic="/opendr/dataset_image", + output_rgb_image_topic="/opendr/dataset_image", data_fps=30, ): """ @@ -40,10 +40,9 @@ def __init__( self.bridge = ROSBridge() self.delay = 1.0 / data_fps - if output_image_topic is not None: - self.output_image_publisher = rospy.Publisher( - output_image_topic, ROS_Image, queue_size=10 - ) + self.output_image_publisher = rospy.Publisher( + output_rgb_image_topic, ROS_Image, queue_size=10 + ) def start(self): rospy.loginfo("Timing images") @@ -76,7 +75,7 @@ def main(): "datasets", "splits", "nano_mot20.train" ) ) - parser.add_argument("-o", "--output_image_topic", help="Topic name to publish the data", + parser.add_argument("-o", "--output_rgb_image_topic", help="Topic name to publish the data", type=str, default="/opendr/dataset_image") parser.add_argument("-f", "--fps", help="Data FPS", type=float, default=30) @@ -84,7 +83,7 @@ def main(): dataset_path = args.dataset_path mot20_subsets_path = args.mot20_subsets_path - output_image_topic = args.output_image_topic + output_rgb_image_topic = args.output_rgb_image_topic data_fps = args.fps if not os.path.exists(dataset_path): @@ -104,7 +103,7 @@ def main(): dataset_node = ImageDatasetNode( dataset, - output_image_topic=output_image_topic, + output_rgb_image_topic=output_rgb_image_topic, data_fps=data_fps, ) diff --git a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py index 34f5c09f56..1716c2aa9a 100755 --- a/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py +++ b/projects/opendr_ws/src/perception/scripts/object_detection_3d_voxel.py @@ -40,7 +40,7 @@ def __init__( """ Creates a ROS Node for 3D object detection :param input_point_cloud_topic: Topic from which we are reading the input point cloud - :type input_image_topic: str + :type input_point_cloud_topic: str :param output_detection3d_topic: Topic to which we are publishing the annotations :type output_detection3d_topic: str :param device: device on which we are running inference ('cpu' or 'cuda') diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index 2383103820..c73f65411c 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -47,11 +47,11 @@ def __init__( Creates a ROS Node for 2D object tracking :param detector: Learner to generate object detections :type detector: Learner - :param input_image_topic: Topic from which we are reading the input image - :type input_image_topic: str - :param output_image_topic: Topic to which we are publishing the annotated image (if None, we are not publishing + :param input_rgb_image_topic: Topic from which we are reading the input image + :type input_rgb_image_topic: str + :param output_rgb_image_topic: Topic to which we are publishing the annotated image (if None, we are not publishing annotated image) - :type output_image_topic: str + :type output_rgb_image_topic: str :param output_detection_topic: Topic to which we are publishing the detections :type output_detection_topic: str :param output_tracking_id_topic: Topic to which we are publishing the tracking ids @@ -74,22 +74,22 @@ def __init__( self.learner.load(os.path.join(temp_dir, model_name), verbose=True) self.bridge = ROSBridge() - self.input_image_topic = input_image_topic + self.input_rgb_image_topic = input_rgb_image_topic - self.tracking_id_publisher = rospy.Publisher( - output_tracking_id_topic, Int32MultiArray, queue_size=10 - ) + if output_tracking_id_topic is not None: + self.tracking_id_publisher = rospy.Publisher( + output_tracking_id_topic, Int32MultiArray, queue_size=10 + ) - if output_image_topic is not None: + if output_rgb_image_topic is not None: self.output_image_publisher = rospy.Publisher( - output_image_topic, ROS_Image, queue_size=10 + output_rgb_image_topic, ROS_Image, queue_size=10 ) - self.detection_publisher = rospy.Publisher( - output_detection_topic, Detection2DArray, queue_size=10 - ) - - rospy.Subscriber(input_image_topic, ROS_Image, self.callback) + if output_detection_topic is not None: + self.detection_publisher = rospy.Publisher( + output_detection_topic, Detection2DArray, queue_size=10 + ) def callback(self, data): """ @@ -133,7 +133,7 @@ def listen(self): Start the node and begin processing input data. """ rospy.init_node('object_tracking_2d_deep_sort_node', anonymous=True) - rospy.Subscriber(self.input_image_topic, ROS_Image, self.callback, queue_size=1, buff_size=10000000) + rospy.Subscriber(self.input_rgb_image_topic, ROS_Image, self.callback, queue_size=1, buff_size=10000000) rospy.loginfo("Object Tracking 2D Deep Sort Node started.") rospy.spin() @@ -231,11 +231,11 @@ def main(): detector=detection_learner, device=device, model_name=args.model_name, - input_image_topic=args.input_image_topic, + input_rgb_image_topic=args.input_rgb_image_topic, temp_dir=args.temp_dir, output_detection_topic=args.output_detection_topic if args.output_detection_topic != "None" else None, output_tracking_id_topic=args.output_tracking_id_topic if args.output_tracking_id_topic != "None" else None, - output_image_topic=args.output_image_topic if args.output_image_topic != "None" else None, + output_rgb_image_topic=args.output_rgb_image_topic if args.output_rgb_image_topic != "None" else None, ) deep_sort_node.listen() diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py index 8e5b96c091..953110d975 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py @@ -42,11 +42,11 @@ def __init__( ): """ Creates a ROS Node for 2D object tracking - :param input_image_topic: Topic from which we are reading the input image - :type input_image_topic: str - :param output_image_topic: Topic to which we are publishing the annotated image (if None, we are not publishing + :param input_rgb_image_topic: Topic from which we are reading the input image + :type input_rgb_image_topic: str + :param output_rgb_image_topic: Topic to which we are publishing the annotated image (if None, we are not publishing annotated image) - :type output_image_topic: str + :type output_rgb_image_topic: str :param output_detection_topic: Topic to which we are publishing the detections :type output_detection_topic: str :param output_tracking_id_topic: Topic to which we are publishing the tracking ids @@ -68,18 +68,21 @@ def __init__( self.learner.load(os.path.join(temp_dir, model_name), verbose=True) self.bridge = ROSBridge() - self.input_image_topic = input_image_topic + self.input_rgb_image_topic = input_rgb_image_topic + if output_detection_topic is not None: self.detection_publisher = rospy.Publisher( output_detection_topic, Detection2DArray, queue_size=10 ) + + if output_tracking_id_topic is not None: self.tracking_id_publisher = rospy.Publisher( output_tracking_id_topic, Int32MultiArray, queue_size=10 ) - if output_image_topic is not None: + if output_rgb_image_topic is not None: self.output_image_publisher = rospy.Publisher( - output_image_topic, ROS_Image, queue_size=10 + output_rgb_image_topic, ROS_Image, queue_size=10 ) def callback(self, data): @@ -120,7 +123,7 @@ def listen(self): Start the node and begin processing input data. """ rospy.init_node('object_tracking_2d_fair_mot_node', anonymous=True) - rospy.Subscriber(self.input_image_topic, ROS_Image, self.callback, queue_size=1, buff_size=10000000) + rospy.Subscriber(self.input_rgb_image_topic, ROS_Image, self.callback, queue_size=1, buff_size=10000000) rospy.loginfo("Object Tracking 2D Fair Mot Node started.") rospy.spin() @@ -209,11 +212,11 @@ def main(): fair_mot_node = ObjectTracking2DFairMotNode( device=device, model_name=args.model_name, - input_image_topic=args.input_image_topic, + input_rgb_image_topic=args.input_rgb_image_topic, temp_dir=args.temp_dir, output_detection_topic=args.output_detection_topic if args.output_detection_topic != "None" else None, output_tracking_id_topic=args.output_tracking_id_topic if args.output_tracking_id_topic != "None" else None, - output_image_topic=args.output_image_topic if args.output_image_topic != "None" else None, + output_rgb_image_topic=args.output_rgb_image_topic if args.output_rgb_image_topic != "None" else None, ) fair_mot_node.listen() From 8053a17c9262a0dfb26faacdf9da28740ae87aa2 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 22 Nov 2022 09:52:38 +0000 Subject: [PATCH 24/31] Add topic comments --- .../scripts/object_tracking_2d_deep_sort.py | 4 ++-- .../scripts/object_tracking_2d_fair_mot.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index c73f65411c..ea13e8c0cf 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -197,10 +197,10 @@ def main(): help="Output detections topic", type=str, default="/opendr/deep_sort_detection") parser.add_argument("-ot", "--output_tracking_id_topic", - help="Output detections topic", + help="Output tracking ids topic with the same element cound as in output_detection_topic", type=str, default="/opendr/deep_sort_tracking_id") parser.add_argument("-oi", "--output_rgb_image_topic", - help="Output detections topic", + help="Output annotated image topic with a visualization of detections and their ids", type=str, default="/opendr/deep_sort_image_annotated") parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", type=str, default="cuda", choices=["cuda", "cpu"]) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py index 953110d975..4d767b645a 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py @@ -71,14 +71,14 @@ def __init__( self.input_rgb_image_topic = input_rgb_image_topic if output_detection_topic is not None: - self.detection_publisher = rospy.Publisher( - output_detection_topic, Detection2DArray, queue_size=10 - ) + self.detection_publisher = rospy.Publisher( + output_detection_topic, Detection2DArray, queue_size=10 + ) if output_tracking_id_topic is not None: - self.tracking_id_publisher = rospy.Publisher( - output_tracking_id_topic, Int32MultiArray, queue_size=10 - ) + self.tracking_id_publisher = rospy.Publisher( + output_tracking_id_topic, Int32MultiArray, queue_size=10 + ) if output_rgb_image_topic is not None: self.output_image_publisher = rospy.Publisher( @@ -187,10 +187,10 @@ def main(): help="Output detections topic", type=str, default="/opendr/fairmot_detection") parser.add_argument("-ot", "--output_tracking_id_topic", - help="Output detections topic", + help="Output tracking ids topic with the same element cound as in output_detection_topic", type=str, default="/opendr/fairmot_tracking_id") parser.add_argument("-oi", "--output_rgb_image_topic", - help="Output detections topic", + help="Output annotated image topic with a visualization of detections and their ids", type=str, default="/opendr/fairmot_image_annotated") parser.add_argument("--device", help="Device to use, either \"cpu\" or \"cuda\", defaults to \"cuda\"", type=str, default="cuda", choices=["cuda", "cpu"]) From 8c8b3e85fd1a945a0a6e234a47a96eb90b9bf97a Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 22 Nov 2022 10:09:11 +0000 Subject: [PATCH 25/31] Move fairmot to rgb-based --- projects/opendr_ws/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/opendr_ws/README.md b/projects/opendr_ws/README.md index 2fabf14d5d..0fe9f9c010 100755 --- a/projects/opendr_ws/README.md +++ b/projects/opendr_ws/README.md @@ -50,12 +50,12 @@ Currently, apart from tools, opendr_ws contains the following ROS nodes (categor 7. [Semantic Segmentation](src/perception/README.md#semantic-segmentation-ros-node) 8. [Video Human Activity Recognition](src/perception/README.md#human-action-recognition-ros-node) 9. [Landmark-based Facial Expression Recognition](src/perception/README.md#landmark-based-facial-expression-recognition-ros-node) -10. [Deep Sort Object Tracking 2D](src/perception/README.md#deep-sort-object-tracking-2d-ros-node) -11. [Skeleton-based Human Action Recognition](src/perception/README.md#skeleton-based-human-action-recognition-ros-node) +10. [FairMOT Object Tracking 2D](src/perception/README.md#fairmot-object-tracking-2d-ros-node) +11. [Deep Sort Object Tracking 2D](src/perception/README.md#deep-sort-object-tracking-2d-ros-node) +12. [Skeleton-based Human Action Recognition](src/perception/README.md#skeleton-based-human-action-recognition-ros-node) ## Point cloud input 1. [Voxel Object Detection 3D](src/perception/README.md#voxel-object-detection-3d-ros-node) 2. [AB3DMOT Object Tracking 3D](src/perception/README.md#ab3dmot-object-tracking-3d-ros-node) -3. [FairMOT Object Tracking 2D](src/perception/README.md#fairmot-object-tracking-2d-ros-node) ## RGB + Infrared input 1. [End-to-End Multi-Modal Object Detection (GEM)](src/perception/README.md#gem-ros-node) ## RGBD input nodes From eded88224694ecfe49673e767b79c8ff34f2b114 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 22 Nov 2022 11:18:26 +0000 Subject: [PATCH 26/31] Fix deep sort direction incompatibility --- .../perception/scripts/object_tracking_2d_deep_sort.py | 2 +- .../deep_sort/algorithm/deep_sort_tracker.py | 10 +++++----- .../deep_sort/object_tracking_2d_deep_sort_learner.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index ea13e8c0cf..afc98ae121 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -102,7 +102,7 @@ def callback(self, data): image = self.bridge.from_ros_image(data, encoding="bgr8") detection_boxes = self.detector.infer(image) image_with_detections = ImageWithDetections(image.numpy(), detection_boxes) - tracking_boxes = self.learner.infer(image_with_detections) + tracking_boxes = self.learner.infer(image_with_detections, swap_left_top=True) if self.output_image_publisher is not None: frame = image.opencv() diff --git a/src/opendr/perception/object_tracking_2d/deep_sort/algorithm/deep_sort_tracker.py b/src/opendr/perception/object_tracking_2d/deep_sort/algorithm/deep_sort_tracker.py index edd44325f2..178f933078 100644 --- a/src/opendr/perception/object_tracking_2d/deep_sort/algorithm/deep_sort_tracker.py +++ b/src/opendr/perception/object_tracking_2d/deep_sort/algorithm/deep_sort_tracker.py @@ -51,7 +51,7 @@ def __init__( self.deepsort = self.build_tracker() self.frame = 0 - def infer(self, imageWithDetections: ImageWithDetections, frame_id=None): + def infer(self, imageWithDetections: ImageWithDetections, frame_id=None, swap_left_top=False): if frame_id is not None: self.frame = frame_id @@ -65,8 +65,8 @@ def infer(self, imageWithDetections: ImageWithDetections, frame_id=None): for detection in detections: bbox_xywh.append(np.array([ - detection.left, - detection.top, + detection.top if swap_left_top else detection.left, + detection.left if swap_left_top else detection.top, detection.width, detection.height, ])) @@ -96,8 +96,8 @@ def infer(self, imageWithDetections: ImageWithDetections, frame_id=None): bb_tlwh = self.deepsort._xyxy_to_tlwh(bb_xyxy) results.append(TrackingAnnotation( cls_id, - bb_tlwh[0], - bb_tlwh[1], + (bb_tlwh[1] + bb_tlwh[3] / 2 if swap_left_top else bb_tlwh[0] + bb_tlwh[2] / 2), + (bb_tlwh[0] + bb_tlwh[2] / 2 if swap_left_top else bb_tlwh[1] + bb_tlwh[3] / 2), bb_tlwh[2], bb_tlwh[3], id, diff --git a/src/opendr/perception/object_tracking_2d/deep_sort/object_tracking_2d_deep_sort_learner.py b/src/opendr/perception/object_tracking_2d/deep_sort/object_tracking_2d_deep_sort_learner.py index d0cd3f36a4..a5f0d020fa 100644 --- a/src/opendr/perception/object_tracking_2d/deep_sort/object_tracking_2d_deep_sort_learner.py +++ b/src/opendr/perception/object_tracking_2d/deep_sort/object_tracking_2d_deep_sort_learner.py @@ -262,7 +262,7 @@ def eval( return result - def infer(self, batch, frame_ids=None): + def infer(self, batch, frame_ids=None, swap_left_top=False): if self.tracker is None: raise ValueError("No model loaded or created") @@ -286,7 +286,7 @@ def infer(self, batch, frame_ids=None): t0 = time.time() - result = self.tracker.infer(image, frame_id) + result = self.tracker.infer(image, frame_id, swap_left_top=swap_left_top) results.append(result) t0 = time.time() - t0 From 30c97e5bfeb6aff25bf40615cb355b96492e75f9 Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 22 Nov 2022 11:18:43 +0000 Subject: [PATCH 27/31] Fix bounding box frame reference --- src/opendr/engine/target.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opendr/engine/target.py b/src/opendr/engine/target.py index c00187e882..4b44543731 100644 --- a/src/opendr/engine/target.py +++ b/src/opendr/engine/target.py @@ -361,7 +361,7 @@ def mot(self, with_confidence=True, frame=-1): ], dtype=np.float32) else: result = np.array([ - self.frame, + frame, self.left, self.top, self.width, From de95bd1cab6444ddacf1f44bae191ab123f4727e Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 22 Nov 2022 11:22:12 +0000 Subject: [PATCH 28/31] Exlude opendr_ws devel from source check --- tests/test_license.py | 1 + tests/test_pep8.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/test_license.py b/tests/test_license.py index e8d39d4b37..6452095449 100755 --- a/tests/test_license.py +++ b/tests/test_license.py @@ -99,6 +99,7 @@ def setUp(self): 'src/opendr/perception/multimodal_human_centric/rgbd_hand_gesture_learner/algorithm/architectures', 'src/opendr/perception/skeleton_based_action_recognition/algorithm', 'projects/python/simulation/synthetic_multi_view_facial_image_generation/algorithm', + 'projects/opendr_ws/devel', 'src/opendr/perception/semantic_segmentation/bisenet/algorithm', 'src/opendr/perception/object_detection_2d/retinaface/algorithm', 'src/opendr/perception/object_detection_2d/gem/algorithm', diff --git a/tests/test_pep8.py b/tests/test_pep8.py index 800c6064c4..e4a445a9af 100755 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -33,6 +33,7 @@ 'lib', 'src/opendr/perception/panoptic_segmentation/efficient_ps/algorithm/EfficientPS', 'projects/python/control/eagerx', + 'projects/opendr_ws/devel', 'venv', 'build', ] From 32daa38aca93d2d05bececd89155c506a83c918c Mon Sep 17 00:00:00 2001 From: Illia Oleksiienko Date: Tue, 22 Nov 2022 11:27:02 +0000 Subject: [PATCH 29/31] Optimize deep sort topic computations --- .../scripts/object_tracking_2d_deep_sort.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index afc98ae121..38479722db 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -113,18 +113,15 @@ def callback(self, data): self.output_image_publisher.publish(message) rospy.loginfo("Published annotated image") - ids = [tracking_box.id for tracking_box in tracking_boxes] - - # Convert detected boxes to ROS type and publish - ros_boxes = self.bridge.to_ros_boxes(detection_boxes) if self.detection_publisher is not None: + ros_boxes = self.bridge.to_ros_boxes(detection_boxes) self.detection_publisher.publish(ros_boxes) rospy.loginfo("Published detection boxes") - ros_ids = Int32MultiArray() - ros_ids.data = ids - if self.tracking_id_publisher is not None: + ids = [tracking_box.id for tracking_box in tracking_boxes] + ros_ids = Int32MultiArray() + ros_ids.data = ids self.tracking_id_publisher.publish(ros_ids) rospy.loginfo("Published tracking ids") From 93ce946570684f585e0039e0d14099f540015cb6 Mon Sep 17 00:00:00 2001 From: ad-daniel Date: Thu, 24 Nov 2022 18:08:24 +0100 Subject: [PATCH 30/31] Fixes --- projects/opendr_ws/src/perception/scripts/image_dataset.py | 1 - .../src/perception/scripts/object_tracking_2d_deep_sort.py | 2 +- .../src/perception/scripts/object_tracking_2d_fair_mot.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/projects/opendr_ws/src/perception/scripts/image_dataset.py b/projects/opendr_ws/src/perception/scripts/image_dataset.py index 44977742df..c4af25488e 100755 --- a/projects/opendr_ws/src/perception/scripts/image_dataset.py +++ b/projects/opendr_ws/src/perception/scripts/image_dataset.py @@ -34,7 +34,6 @@ def __init__( Creates a ROS Node for publishing dataset images """ - # Initialize the face detector self.dataset = dataset # Initialize OpenDR ROSBridge object self.bridge = ROSBridge() diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py index 38479722db..3e083be118 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_deep_sort.py @@ -194,7 +194,7 @@ def main(): help="Output detections topic", type=str, default="/opendr/deep_sort_detection") parser.add_argument("-ot", "--output_tracking_id_topic", - help="Output tracking ids topic with the same element cound as in output_detection_topic", + help="Output tracking ids topic with the same element count as in output_detection_topic", type=str, default="/opendr/deep_sort_tracking_id") parser.add_argument("-oi", "--output_rgb_image_topic", help="Output annotated image topic with a visualization of detections and their ids", diff --git a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py index 4d767b645a..7c72a2d976 100755 --- a/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py +++ b/projects/opendr_ws/src/perception/scripts/object_tracking_2d_fair_mot.py @@ -187,7 +187,7 @@ def main(): help="Output detections topic", type=str, default="/opendr/fairmot_detection") parser.add_argument("-ot", "--output_tracking_id_topic", - help="Output tracking ids topic with the same element cound as in output_detection_topic", + help="Output tracking ids topic with the same element count as in output_detection_topic", type=str, default="/opendr/fairmot_tracking_id") parser.add_argument("-oi", "--output_rgb_image_topic", help="Output annotated image topic with a visualization of detections and their ids", From 65808b2525148e62009855776c5b2eb35a178125 Mon Sep 17 00:00:00 2001 From: ad-daniel Date: Fri, 25 Nov 2022 14:08:53 +0100 Subject: [PATCH 31/31] More fixes --- projects/opendr_ws/src/perception/README.md | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/projects/opendr_ws/src/perception/README.md b/projects/opendr_ws/src/perception/README.md index eebb580b86..5b31864fd7 100755 --- a/projects/opendr_ws/src/perception/README.md +++ b/projects/opendr_ws/src/perception/README.md @@ -38,11 +38,11 @@ rosrun perception pose_estimation.py ``` 3. You can examine the annotated image stream using `rqt_image_view` (select the topic `/opendr/image_pose_annotated`) or - `rostopic echo /opendr/poses`. + `rostopic echo /opendr/poses`. Note that to use the pose messages properly, you need to create an appropriate subscriber that will convert the ROS pose messages back to OpenDR poses which you can access as described in the [documentation](https://github.com/opendr-eu/opendr/blob/master/docs/reference/engine-target.md#posekeypoints-confidence): ```python - ... + ... rospy.Subscriber("opendr/poses", Detection2DArray, self.callback) ... def callback(self, data): @@ -212,7 +212,7 @@ A ROS node for performing heart anomaly (atrial fibrillation) detection from ecg ```shell rosrun perception heart_anomaly_detection.py ECG_TOPIC MODEL ``` -with `ECG_TOPIC` specifying the ROS topic to which the node will subscribe, and `MODEL` set to either *gru* or *anbof*. The predictied classes are published to the topic `/opendr/heartanomaly`. +with `ECG_TOPIC` specifying the ROS topic to which the node will subscribe, and `MODEL` set to either *gru* or *anbof*. The predicted classes are published to the topic `/opendr/heartanomaly`. ## Human Action Recognition ROS Node @@ -221,7 +221,7 @@ Assuming the drivers have been installed and OpenDR catkin workspace has been so ```shell rosrun perception video_activity_recognition.py ``` -The predictied class id and confidence is published under the topic name `/opendr/human_activity_recognition`, and the human-readable class name under `/opendr/human_activity_recognition_description`. +The predicted class id and confidence is published under the topic name `/opendr/human_activity_recognition`, and the human-readable class name under `/opendr/human_activity_recognition_description`. ## Landmark-based Facial Expression Recognition ROS Node @@ -230,16 +230,16 @@ Assuming the drivers have been installed and OpenDR catkin workspace has been so ```shell rosrun perception landmark_based_facial_expression_recognition.py ``` -The predictied class id and confidence is published under the topic name `/opendr/landmark_based_expression_recognition`, and the human-readable class name under `/opendr/landmark_based_expression_recognition_description`. +The predicted class id and confidence is published under the topic name `/opendr/landmark_based_expression_recognition`, and the human-readable class name under `/opendr/landmark_based_expression_recognition_description`. ## Skeleton-based Human Action Recognition ROS Node -A ROS node for performing Skeleton-based Human Action Recognition using either ST-GCN or PST-GCN models pretrained on NTU-RGBD-60 dataset. The human body poses of the image are first extracted by the light-weight Openpose method which is implemented in the toolkit, and they are passed to the skeleton-based action recognition method to be categorized. +A ROS node for performing Skeleton-based Human Action Recognition using either ST-GCN or PST-GCN models pretrained on NTU-RGBD-60 dataset. The human body poses of the image are first extracted by the light-weight Open-pose method which is implemented in the toolkit, and they are passed to the skeleton-based action recognition method to be categorized. Assuming the drivers have been installed and OpenDR catkin workspace has been sourced, the node can be started as: ```shell rosrun perception skeleton_based_action_recognition.py ``` -The predictied class id and confidence is published under the topic name `/opendr/skeleton_based_action_recognition`, and the human-readable class name under `/opendr/skeleton_based_action_recognition_description`. +The predicted class id and confidence is published under the topic name `/opendr/skeleton_based_action_recognition`, and the human-readable class name under `/opendr/skeleton_based_action_recognition_description`. Besides, the annotated image is published in `/opendr/image_pose_annotated` as well as the corresponding poses in `/opendr/poses`. ## Speech Command Recognition ROS Node @@ -270,7 +270,7 @@ To get a point cloud from a dataset on the disk, you can start a `point_cloud_da ```shell rosrun perception point_cloud_dataset.py ``` -This will pulbish the dataset point clouds to a `/opendr/dataset_point_cloud` topic by default, which means that the `input_point_cloud_topic` should be set to `/opendr/dataset_point_cloud`. +This will publish the dataset point clouds to a `/opendr/dataset_point_cloud` topic by default, which means that the `input_point_cloud_topic` should be set to `/opendr/dataset_point_cloud`. ## AB3DMOT Object Tracking 3D ROS Node @@ -286,7 +286,7 @@ To get a point cloud from a dataset on the disk, you can start a `point_cloud_da ```shell rosrun perception point_cloud_dataset.py ``` -This will pulbish the dataset point clouds to a `/opendr/dataset_point_cloud` topic by default, which means that the `input_point_cloud_topic` should be set to `/opendr/dataset_point_cloud`. +This will publish the dataset point clouds to a `/opendr/dataset_point_cloud` topic by default, which means that the `input_point_cloud_topic` should be set to `/opendr/dataset_point_cloud`. ## FairMOT Object Tracking 2D ROS Node @@ -305,7 +305,7 @@ If you want to use a dataset from the disk, you can start a `image_dataset.py` n ```shell rosrun perception image_dataset.py ``` -This will pulbish the dataset images to an `/opendr/dataset_image` topic by default, which means that the `input_image_topic` should be set to `/opendr/dataset_image`. +This will publish the dataset images to an `/opendr/dataset_image` topic by default, which means that the `input_image_topic` should be set to `/opendr/dataset_image`. ## Deep Sort Object Tracking 2D ROS Node @@ -323,5 +323,5 @@ If you want to use a dataset from the disk, you can start an `image_dataset.py` ```shell rosrun perception image_dataset.py ``` -This will pulbish the dataset images to an `/opendr/dataset_image` topic by default, which means that the `input_image_topic` should be set to `/opendr/dataset_image`. +This will publish the dataset images to an `/opendr/dataset_image` topic by default, which means that the `input_image_topic` should be set to `/opendr/dataset_image`.