Skip to content

Commit 021b948

Browse files
authored
Fix ROS1 bridge type conversion bug (opendr-eu#300)
* Fixed type conversion bug * Added conditionals in download method to not re-download existing files * Simplified else-ifs as suggested by review
1 parent 364f000 commit 021b948

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

projects/opendr_ws/src/ros_bridge/src/opendr_bridge/bridge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def to_ros_bounding_box_list(self, bounding_box_list):
294294
detection.bbox.center.y = bounding_box.top + bounding_box.height / 2.0
295295
detection.bbox.size_x = bounding_box.width
296296
detection.bbox.size_y = bounding_box.height
297-
detection.results[0].id = bounding_box.name
297+
detection.results[0].id = int(bounding_box.name)
298298
detection.results[0].score = bounding_box.confidence
299299
detections.detections.append(detection)
300300
return detections

src/opendr/perception/object_detection_2d/yolov3/yolov3_learner.py

+36-7
Original file line numberDiff line numberDiff line change
@@ -572,21 +572,35 @@ def download(self, path=None, mode="pretrained", verbose=False,
572572
"yolo_voc.json")
573573
if verbose:
574574
print("Downloading metadata...")
575-
urlretrieve(file_url, os.path.join(path, "yolo_default.json"))
575+
if not os.path.exists(os.path.join(path, "yolo_default.json")):
576+
urlretrieve(file_url, os.path.join(path, "yolo_default.json"))
577+
if verbose:
578+
print("Downloaded metadata json.")
579+
elif verbose:
580+
print("Metadata json file already exists.")
576581

577582
if verbose:
578583
print("Downloading params...")
579584
file_url = os.path.join(url, "pretrained", "yolo_voc",
580585
"yolo_voc.params")
581586

582-
urlretrieve(file_url,
583-
os.path.join(path, "yolo_voc.params"))
587+
if not os.path.exists(os.path.join(path, "yolo_voc.params")):
588+
urlretrieve(file_url, os.path.join(path, "yolo_voc.params"))
589+
if verbose:
590+
print("Downloaded params.")
591+
elif verbose:
592+
print("Params file already exists.")
584593

585594
elif mode == "images":
586595
file_url = os.path.join(url, "images", "cat.jpg")
587596
if verbose:
588597
print("Downloading example image...")
589-
urlretrieve(file_url, os.path.join(path, "cat.jpg"))
598+
if not os.path.exists(os.path.join(path, "cat.jpg")):
599+
urlretrieve(file_url, os.path.join(path, "cat.jpg"))
600+
if verbose:
601+
print("Downloaded example image.")
602+
elif verbose:
603+
print("Example image already exists.")
590604

591605
elif mode == "test_data":
592606
os.makedirs(os.path.join(path, "test_data"), exist_ok=True)
@@ -596,17 +610,32 @@ def download(self, path=None, mode="pretrained", verbose=False,
596610
file_url = os.path.join(url, "test_data", "train.txt")
597611
if verbose:
598612
print("Downloading filelist...")
599-
urlretrieve(file_url, os.path.join(path, "test_data", "train.txt"))
613+
if not os.path.exists(os.path.join(path, "test_data", "train.txt")):
614+
urlretrieve(file_url, os.path.join(path, "test_data", "train.txt"))
615+
if verbose:
616+
print("Downloaded filelist.")
617+
elif verbose:
618+
print("Filelist already exists.")
600619
# download image
601620
file_url = os.path.join(url, "test_data", "Images", "000040.jpg")
602621
if verbose:
603622
print("Downloading image...")
604-
urlretrieve(file_url, os.path.join(path, "test_data", "Images", "000040.jpg"))
623+
if not os.path.exists(os.path.join(path, "test_data", "Images", "000040.jpg")):
624+
urlretrieve(file_url, os.path.join(path, "test_data", "Images", "000040.jpg"))
625+
if verbose:
626+
print("Downloaded image.")
627+
elif verbose:
628+
print("Image already exists.")
605629
# download annotations
606630
file_url = os.path.join(url, "test_data", "Annotations", "000040.jpg.txt")
607631
if verbose:
608632
print("Downloading annotations...")
609-
urlretrieve(file_url, os.path.join(path, "test_data", "Annotations", "000040.jpg.txt"))
633+
if not os.path.exists(os.path.join(path, "test_data", "Annotations", "000040.jpg.txt")):
634+
urlretrieve(file_url, os.path.join(path, "test_data", "Annotations", "000040.jpg.txt"))
635+
if verbose:
636+
print("Downloaded annotations.")
637+
elif verbose:
638+
print("Annotations already exist.")
610639

611640
def optimize(self, target_device):
612641
"""This method is not used in this implementation."""

0 commit comments

Comments
 (0)