-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
main_2024.py detect target #156
Changes from 4 commits
2dbe3c9
10c489e
bfa1978
ad9ac08
f23f62d
dd6e5a1
3ee9905
d7ca078
8819c3c
d08e556
bd2a59d
a49c660
20e4018
0da5e01
37a37bc
cb186f4
724de57
5e6c8e7
0133d97
479a361
864bcaa
0b2f4b7
ba05393
108c7c6
ca549ba
0ab48c9
435992c
73a28a8
69be32a
5117781
dea615a
3080db0
6b00c7e
ef80b03
68fab82
f8359ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
from modules.detect_target import detect_target_worker | ||
from modules.flight_interface import flight_interface_worker | ||
from modules.video_input import video_input_worker | ||
from modules.detections_and_time import DetectionsAndTime | ||
|
||
|
||
CONFIG_FILE_PATH = pathlib.Path("config.yaml") | ||
|
@@ -43,6 +44,7 @@ def main() -> int: | |
parser = argparse.ArgumentParser() | ||
parser.add_argument("--cpu", action="store_true", help="option to force cpu") | ||
parser.add_argument("--full", action="store_true", help="option to force full precision") | ||
parser.add_argument("--show-annotated", action="store_true", help="option to show annotated image") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make multiline. |
||
args = parser.parse_args() | ||
|
||
# Set constants | ||
|
@@ -58,6 +60,7 @@ def main() -> int: | |
DETECT_TARGET_MODEL_PATH = config["detect_target"]["model_path"] | ||
DETECT_TARGET_OVERRIDE_FULL_PRECISION = args.full | ||
DETECT_TARGET_SAVE_PREFIX = config["detect_target"]["save_prefix"] | ||
DETECT_TARGET_ANNOTATE = args.show_annotated | ||
Xierumeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
FLIGHT_INTERFACE_ADDRESS = config["flight_interface"]["address"] | ||
FLIGHT_INTERFACE_WORKER_PERIOD = config["flight_interface"]["worker_period"] | ||
|
@@ -104,6 +107,7 @@ def main() -> int: | |
DETECT_TARGET_MODEL_PATH, | ||
DETECT_TARGET_OVERRIDE_FULL_PRECISION, | ||
DETECT_TARGET_SAVE_PREFIX, | ||
DETECT_TARGET_ANNOTATE, | ||
video_input_to_detect_target_queue, | ||
detect_target_to_main_queue, | ||
controller, | ||
|
@@ -129,9 +133,9 @@ def main() -> int: | |
|
||
while True: | ||
try: | ||
image = detect_target_to_main_queue.queue.get_nowait() | ||
detections = detect_target_to_main_queue.queue.get_nowait() | ||
except queue.Empty: | ||
image = None | ||
detections = None | ||
Xierumeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
odometry_and_time = flight_interface_to_main_queue.queue.get() | ||
|
||
|
@@ -145,10 +149,10 @@ def main() -> int: | |
print("pitch: " + str(odometry_and_time.odometry_data.orientation.pitch)) | ||
print("") | ||
|
||
if image is None: | ||
if detections is None: | ||
continue | ||
|
||
cv2.imshow("Landing Pad Detector", image) | ||
#cv2.imshow("Landing Pad Detector", image) | ||
Trotyl15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
|
@@ -164,6 +168,8 @@ def main() -> int: | |
detect_target_manager.join_workers() | ||
flight_interface_manager.join_workers() | ||
|
||
cv2.destroyAllWindows() | ||
|
||
return 0 | ||
|
||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert to when you were displaying the image in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Amy mentioned above that this causes issues. Is there a work around? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work on you end? If it does then maybe I missed something in the set up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh this works! @Ethan118 you can do this instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line 7 import (no longer being used). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ class DetectTarget: | |
""" | ||
Contains the YOLOv8 model for prediction. | ||
""" | ||
def __init__(self, device: "str | int", model_path: str, override_full: bool, save_name: str = ""): | ||
def __init__(self, device: "str | int", model_path: str, override_full: bool, save_name: str = "", show_annotations: bool = False): | ||
Xierumeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
device: name of target device to run inference on (i.e. "cpu" or cuda device 0, 1, 2, 3). | ||
model_path: path to the YOLOv8 model. | ||
|
@@ -28,16 +28,16 @@ def __init__(self, device: "str | int", model_path: str, override_full: bool, sa | |
self.__model = ultralytics.YOLO(model_path) | ||
self.__counter = 0 | ||
self.__enable_half_precision = False if self.__device == "cpu" else True | ||
self.__show_annotations = show_annotations | ||
if override_full: | ||
self.__enable_half_precision = False | ||
self.__filename_prefix = "" | ||
if save_name != "": | ||
self.__filename_prefix = save_name + "_" + str(int(time.time())) + "_" | ||
|
||
def run(self, data: image_and_time.ImageAndTime) -> "tuple[bool, np.ndarray | None]": | ||
def run(self, data: image_and_time.ImageAndTime) -> "tuple[bool, detections_and_time.DetectionsAndTime | None]": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make multiline. |
||
""" | ||
Returns annotated image. | ||
TODO: Change to DetectionsAndTime | ||
""" | ||
image = data.image | ||
predictions = self.__model.predict( | ||
|
@@ -50,7 +50,6 @@ def run(self, data: image_and_time.ImageAndTime) -> "tuple[bool, np.ndarray | No | |
if len(predictions) == 0: | ||
return False, None | ||
|
||
# TODO: Change this to DetectionsAndTime for image and telemetry merge for 2024 | ||
image_annotated = predictions[0].plot(conf=True) | ||
|
||
# Processing object detection | ||
|
@@ -84,7 +83,9 @@ def run(self, data: image_and_time.ImageAndTime) -> "tuple[bool, np.ndarray | No | |
|
||
self.__counter += 1 | ||
|
||
# TODO: Change this to DetectionsAndTime | ||
return True, image_annotated | ||
if self.__show_annotations: | ||
cv2.imshow("Annotated Image", image_annotated) | ||
|
||
return True, detections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work on your end? I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably isn't threadsafe, but since only a single process will be using it, it should be fine. The Autonomy bootcamp is an example of where it works without issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did a little test and when |
||
|
||
# pylint: enable=too-few-public-methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line 12 import (no longer being used).