Skip to content

Commit a108d4f

Browse files
committed
Format
1 parent 1b14238 commit a108d4f

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

detectionator.py

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,16 @@ def combine_duplicate_detections(detections, min_overlap: float):
151151
return detections
152152

153153
deduplicated_detections = []
154-
sorted_detections = sorted(detections, key=lambda y: (y[1][0], y[1][1], y[1][2], y[1][3]))
154+
sorted_detections = sorted(
155+
detections, key=lambda y: (y[1][0], y[1][1], y[1][2], y[1][3])
156+
)
155157
i = 0
156158
while i < len(sorted_detections) - 1:
157159
current = sorted_detections[i]
158160
j = 0
159-
while i + j < len(sorted_detections) and detections_are_duplicates(current, sorted_detections[j], min_overlap):
161+
while i + j < len(sorted_detections) and detections_are_duplicates(
162+
current, sorted_detections[j], min_overlap
163+
):
160164
current = combine_detections(current, sorted_detections[j])
161165
j += 1
162166
deduplicated_detections.append(current)
@@ -176,7 +180,10 @@ def combine_intersecting_rectangles(rectangles):
176180
while i < len(sorted_rectangles) - 1:
177181
current = sorted_rectangles[i]
178182
j = 0
179-
while i + j < len(sorted_rectangles) and intersection_area(current, sorted_rectangles[j]) > 0:
183+
while (
184+
i + j < len(sorted_rectangles)
185+
and intersection_area(current, sorted_rectangles[j]) > 0
186+
):
180187
current = combine_rectangles(current, sorted_rectangles[j])
181188
j += 1
182189
combined_rectangles.append(current)
@@ -185,11 +192,11 @@ def combine_intersecting_rectangles(rectangles):
185192

186193

187194
def inference_hailo(
188-
image,
189-
hailo,
190-
labels: list,
191-
match_labels: list,
192-
threshold: float,
195+
image,
196+
hailo,
197+
labels: list,
198+
match_labels: list,
199+
threshold: float,
193200
):
194201
output = hailo.run(image)[0]
195202
height, width, _ = hailo.get_input_shape()
@@ -219,7 +226,12 @@ def inference_hailo(
219226

220227

221228
def inference_tensorflow(
222-
image, interpreter, labels: dict, match_labels: list, threshold: float, is_yolo: bool
229+
image,
230+
interpreter,
231+
labels: dict,
232+
match_labels: list,
233+
threshold: float,
234+
is_yolo: bool,
223235
):
224236
input_details = interpreter.get_input_details()
225237
output_details = interpreter.get_output_details()
@@ -248,9 +260,7 @@ def inference_tensorflow(
248260
if is_yolo:
249261
output_data = interpreter.get_tensor(output_details[0]["index"])[0]
250262
boxes = np.squeeze(output_data[..., :4])
251-
detected_scores = np.squeeze(
252-
output_data[..., 4:5]
253-
) # confidences [25200, 1]
263+
detected_scores = np.squeeze(output_data[..., 4:5]) # confidences [25200, 1]
254264
detected_classes = yolo_class_filter(output_data[..., 5:])
255265
x, y, w, h = boxes[..., 0], boxes[..., 1], boxes[..., 2], boxes[..., 3] # xywh
256266
# detected_boxes = [y - h / 2, x - w / 2, y + h / 2, x + w / 2] # xywh to yxyx
@@ -303,7 +313,9 @@ def inference(
303313
):
304314
if isinstance(interpreter, Hailo):
305315
return inference_hailo(image, interpreter, labels, match_labels, threshold)
306-
return inference_tensorflow(image, interpreter, labels, match_labels, threshold, is_yolo)
316+
return inference_tensorflow(
317+
image, interpreter, labels, match_labels, threshold, is_yolo
318+
)
307319

308320

309321
# Convert a rectangle defined by two coordinates to a string representation.
@@ -598,7 +610,9 @@ async def detect_and_capture(
598610
f"Possible detection: {detection_to_string(possible_detection)}"
599611
)
600612

601-
bounding_boxes = combine_intersecting_rectangles([d[1] for d in reversed(possible_detections)])
613+
bounding_boxes = combine_intersecting_rectangles(
614+
[d[1] for d in reversed(possible_detections)]
615+
)
602616
scaled_bounding_boxes = [
603617
cast_int(
604618
rectangle_coordinates_to_coordinate_width_height(
@@ -637,7 +651,9 @@ async def detect_and_capture(
637651
for detection in reversed(detections):
638652
logger.info(f"Detection: {detection_to_string(detection)}")
639653

640-
bounding_boxes = combine_intersecting_rectangles([d[1] for d in reversed(detections)])
654+
bounding_boxes = combine_intersecting_rectangles(
655+
[d[1] for d in reversed(detections)]
656+
)
641657
scaled_bounding_boxes = [
642658
cast_int(
643659
rectangle_coordinates_to_coordinate_width_height(
@@ -758,7 +774,9 @@ async def detect_and_record(
758774
f"Possible detection: {detection_to_string(possible_detection)}"
759775
)
760776

761-
bounding_boxes = combine_intersecting_rectangles([d[1] for d in reversed(possible_detections)])
777+
bounding_boxes = combine_intersecting_rectangles(
778+
[d[1] for d in reversed(possible_detections)]
779+
)
762780
scaled_bounding_boxes = [
763781
cast_int(
764782
rectangle_coordinates_to_coordinate_width_height(
@@ -796,7 +814,9 @@ async def detect_and_record(
796814
for detection in reversed(detections):
797815
logger.info(f"Detection: {detection_to_string(detection)}")
798816

799-
bounding_boxes = combine_intersecting_rectangles([d[1] for d in reversed(detections)])
817+
bounding_boxes = combine_intersecting_rectangles(
818+
[d[1] for d in reversed(detections)]
819+
)
800820
scaled_bounding_boxes = [
801821
cast_int(
802822
rectangle_coordinates_to_coordinate_width_height(
@@ -915,7 +935,9 @@ async def detect_and_record(
915935
f"Possible detection: {detection_to_string(possible_detection)}"
916936
)
917937

918-
bounding_boxes = combine_intersecting_rectangles([d[1] for d in reversed(possible_detections)])
938+
bounding_boxes = combine_intersecting_rectangles(
939+
[d[1] for d in reversed(possible_detections)]
940+
)
919941
scaled_bounding_boxes = [
920942
cast_int(
921943
rectangle_coordinates_to_coordinate_width_height(
@@ -956,7 +978,9 @@ async def detect_and_record(
956978

957979
for detection in reversed(detections):
958980
logger.info(f"Detection: {detection_to_string(detection)}")
959-
bounding_boxes = combine_intersecting_rectangles([d[1] for d in reversed(detections)])
981+
bounding_boxes = combine_intersecting_rectangles(
982+
[d[1] for d in reversed(detections)]
983+
)
960984
scaled_bounding_boxes = [
961985
cast_int(
962986
rectangle_coordinates_to_coordinate_width_height(
@@ -1215,7 +1239,7 @@ async def main():
12151239
labels = None
12161240
if label_file:
12171241
if args.hailo:
1218-
with open(label_file, 'r', encoding="utf-8") as f:
1242+
with open(label_file, "r", encoding="utf-8") as f:
12191243
# class names
12201244
labels = f.read().splitlines()
12211245
else:
@@ -1331,7 +1355,9 @@ async def main():
13311355
low_resolution_height: int = 0
13321356
low_resolution_width: int = 0
13331357
if args.hailo:
1334-
low_resolution_height, low_resolution_width, _ = interpreter.get_input_shape()
1358+
low_resolution_height, low_resolution_width, _ = (
1359+
interpreter.get_input_shape()
1360+
)
13351361
else:
13361362
if args.low_resolution_width:
13371363
low_resolution_width = args.low_resolution_width

models/coco_labels.txt

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@
7777
86 scissors
7878
87 teddy bear
7979
88 hair drier
80-
89 toothbrush
80+
89 toothbrush

models/deeplab_labels.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
17 sheep
1919
18 sofa
2020
19 train
21-
20 tv
21+
20 tv

0 commit comments

Comments
 (0)