Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f77a1d5
Added logger to detect target script
wdan31 Oct 31, 2024
fd080c4
Added logger to more detect target files
wdan31 Oct 31, 2024
fb29611
Reverted changed to abstract class
wdan31 Oct 31, 2024
f625bc9
Added logger to detect target worker
wdan31 Oct 31, 2024
2c725a3
Added logger to detect target
wdan31 Nov 3, 2024
f1752ff
Rounded time taken logs to 3 decimal places
wdan31 Nov 3, 2024
2573c60
Added logger to factory and worker
wdan31 Nov 3, 2024
cf66adb
Linted python
wdan31 Nov 3, 2024
1e65647
Changed time formatting in logs
wdan31 Nov 3, 2024
213f814
updated common
wdan31 Nov 3, 2024
051427f
Merge branch 'main' into detect-target-worker
wdan31 Nov 3, 2024
7e975a8
Formatted python
wdan31 Nov 3, 2024
6d8ff62
Added logger to detect target script
wdan31 Oct 31, 2024
2770962
Added logger to more detect target files
wdan31 Oct 31, 2024
c18c393
Reverted changed to abstract class
wdan31 Oct 31, 2024
e98a8e8
Added logger to detect target worker
wdan31 Oct 31, 2024
ea17935
Rounded time taken logs to 3 decimal places
wdan31 Nov 3, 2024
453ddc2
Added logger to factory and worker
wdan31 Nov 3, 2024
715d0fa
Linted python
wdan31 Nov 3, 2024
1ef8fb6
Changed time formatting in logs
wdan31 Nov 3, 2024
40b6d4e
updated common
wdan31 Nov 3, 2024
700be6f
Added logger to detect target
wdan31 Nov 3, 2024
f1b0cc2
Formatted python
wdan31 Nov 3, 2024
f364ea2
Fixed logger implementation
wdan31 Nov 7, 2024
1c1b6ee
Fixed model attributes
wdan31 Nov 7, 2024
48a6568
Fixed logger attribute
wdan31 Nov 7, 2024
582c88c
Merge branch 'detect-target-worker' of https://github.com/UWARG/compu…
wdan31 Nov 7, 2024
e560438
Fixed logger implementation (again)
wdan31 Nov 7, 2024
0ed8f29
Formatted python
wdan31 Nov 7, 2024
412b89d
common
wdan31 Nov 14, 2024
8037cd4
common
wdan31 Nov 14, 2024
a3b89bf
Merge branch 'main' of https://github.com/UWARG/computer-vision-pytho…
wdan31 Nov 14, 2024
7c51eb9
updated common
wdan31 Nov 14, 2024
8261e09
Added detect target logger to main_2024
wdan31 Nov 15, 2024
94005d0
Removed detect target logger from the worker properties, logger alrea…
wdan31 Nov 15, 2024
3da1017
Updated detect target logs
wdan31 Nov 15, 2024
9cf15d2
Formatted python
wdan31 Nov 15, 2024
0893c78
Removed text file logging
wdan31 Nov 15, 2024
e7d6974
Added string repr for detectionInWorld
wdan31 Nov 15, 2024
5ee53de
Added repr for Detections class
wdan31 Nov 15, 2024
60f51e7
Formatted python
wdan31 Nov 15, 2024
0ddd7e1
Changed python formatting and test logger implementation
wdan31 Nov 15, 2024
8912617
formatted python
wdan31 Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/detect_target/detect_target_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from . import base_detect_target
from . import detect_target_ultralytics
from ..common.modules.logger import logger


class DetectTargetOption(enum.Enum):
Expand All @@ -21,6 +22,7 @@ def create_detect_target(
device: "str | int",
model_path: str,
override_full: bool,
local_logger: logger.Logger,
show_annotations: bool,
save_name: str,
) -> tuple[bool, base_detect_target.BaseDetectTarget | None]:
Expand All @@ -33,6 +35,7 @@ def create_detect_target(
device,
model_path,
override_full,
local_logger,
show_annotations,
save_name,
)
Expand Down
15 changes: 10 additions & 5 deletions modules/detect_target/detect_target_ultralytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from . import base_detect_target
from .. import image_and_time
from .. import detections_and_time
from ..common.modules.logger import logger


class DetectTargetUltralytics(base_detect_target.BaseDetectTarget):
Expand All @@ -22,6 +23,7 @@ def __init__(
device: "str | int",
model_path: str,
override_full: bool,
local_logger: logger.Logger,
show_annotations: bool = False,
save_name: str = "",
) -> None:
Expand All @@ -36,6 +38,7 @@ def __init__(
self.__model = ultralytics.YOLO(model_path)
self.__counter = 0
self.__enable_half_precision = not self.__device == "cpu"
self.__local_logger = local_logger
self.__show_annotations = show_annotations
if override_full:
self.__enable_half_precision = False
Expand All @@ -54,6 +57,8 @@ def run(
Return: Success and the detections.
"""
image = data.image
start_time = time.time()

predictions = self.__model.predict(
source=image,
half=self.__enable_half_precision,
Expand Down Expand Up @@ -91,15 +96,15 @@ def run(

detections.append(detection)

end_time = time.time()
self.__local_logger.info(
f"{time.time()}: Count: {self.__counter}. Target detection took {end_time - start_time} seconds. Objects detected: {detections}."
)

# Logging
if self.__filename_prefix != "":
filename = self.__filename_prefix + str(self.__counter)

# Object detections
with open(filename + ".txt", "w", encoding="utf-8") as file:
# Use internal string representation
file.write(repr(detections))

# Annotated image
cv2.imwrite(filename + ".png", image_annotated) # type: ignore

Expand Down
1 change: 1 addition & 0 deletions modules/detect_target/detect_target_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def detect_target_worker(
device,
model_path,
override_full,
local_logger,
show_annotations,
save_name,
)
Expand Down
6 changes: 6 additions & 0 deletions modules/detection_in_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ def __str__(self) -> str:
To string.
"""
return f"{self.__class__}, vertices: {self.vertices.tolist()}, centre: {self.centre}, label: {self.label}, confidence: {self.confidence}"

def __repr__(self) -> str:
"""
For collections (e.g. list).
"""
return str(self)
6 changes: 6 additions & 0 deletions modules/detections_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def __str__(self) -> str:
"""
return f"cls: {self.label}, conf: {self.confidence}, bounds: {self.x_1} {self.y_1} {self.x_2} {self.y_2}"

def __repr__(self) -> str:
"""
For collections (e.g. list).
"""
return str(self)

def get_centre(self) -> "tuple[float, float]":
"""
Gets the xy centre of the bounding box.
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_detect_target_ultralytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from modules.detect_target import detect_target_ultralytics
from modules import image_and_time
from modules import detections_and_time
from modules.common.modules.logger import logger


TEST_PATH = pathlib.Path("tests", "model_example")
Expand Down Expand Up @@ -108,8 +109,13 @@ def detector() -> detect_target_ultralytics.DetectTargetUltralytics: # type: ig
"""
Construct DetectTargetUltralytics.
"""
result, test_logger = logger.Logger.create("test_logger", False)

assert result
assert test_logger is not None

detection = detect_target_ultralytics.DetectTargetUltralytics(
DEVICE, str(MODEL_PATH), OVERRIDE_FULL
DEVICE, str(MODEL_PATH), OVERRIDE_FULL, test_logger
)
yield detection # type: ignore

Expand Down