Skip to content

Commit d4fc1a8

Browse files
committed
make string class constant and fixed formatting
1 parent a6407b1 commit d4fc1a8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

modules/detect_target/detect_target_ultralytics.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class DetectTargetUltralyticsConfig:
1818
"""
1919
Configuration for DetectTargetUltralytics.
2020
"""
21+
CPU_DEVICE = "cpu"
2122

2223
def __init__(
2324
self,
@@ -57,7 +58,10 @@ def __init__(
5758
save_name: filename prefix for logging detections and annotated images.
5859
"""
5960
self.__device = config.device
60-
self.__enable_half_precision = self.__device != "cpu"
61+
if self.__device != DetectTargetUltralyticsConfig.CPU_DEVICE and not torch.cuda.is_available():
62+
self.__local_logger.warning("CUDA not available. Falling back to CPU.")
63+
self.__device = DetectTargetUltralyticsConfig.CPU_DEVICE
64+
self.__enable_half_precision = self.__device != DetectTargetUltralyticsConfig.CPU_DEVICE
6165
self.__model = ultralytics.YOLO(config.model_path)
6266
if config.override_full:
6367
self.__enable_half_precision = False
@@ -68,9 +72,7 @@ def __init__(
6872
if save_name != "":
6973
self.__filename_prefix = save_name + "_" + str(int(time.time())) + "_"
7074

71-
if self.__device != "cpu" and not torch.cuda.is_available():
72-
self.__local_logger.warning("CUDA not available. Falling back to CPU.")
73-
self.__device = "cpu"
75+
7476

7577
def run(
7678
self, data: image_and_time.ImageAndTime
@@ -132,7 +134,7 @@ def run(
132134
filename = self.__filename_prefix + str(self.__counter)
133135

134136
# Annotated image
135-
cv2.imwrite(filename + ".png", image_annotated) # type: ignore
137+
cv2.imwrite(filename + ".png", image_annotated)
136138

137139
self.__counter += 1
138140

0 commit comments

Comments
 (0)