Skip to content

Commit 5eb33e0

Browse files
committed
patches_info func
1 parent 7ee8735 commit 5eb33e0

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

patched_yolo_infer/nodes/MakeCropsDetectThem.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
import matplotlib.pyplot as plt
44
from ultralytics import YOLO
5+
from collections import Counter
56

67
from ..elements.CropElement import CropElement
78

@@ -302,4 +303,27 @@ def __str__(self):
302303
return (
303304
f"{len(self.crops)} patches of size {self.crops[0].crop.shape} "
304305
f"were created from an image sized {self.image.shape}"
305-
)
306+
)
307+
308+
def patches_info(self):
309+
print(self)
310+
output = "\nDetailed information about the detections for each patch:"
311+
for i, patch in enumerate(self.crops):
312+
if len(patch.detected_cls) > 0:
313+
detected_cls_names_list = [
314+
self.class_names_dict[value] for value in patch.detected_cls
315+
] # make str list
316+
317+
# Count the occurrences of each class in the current patch
318+
class_counts = Counter(detected_cls_names_list)
319+
320+
# Format the class counts into a readable string
321+
class_info = ", ".join([f"{count} {cls}" for cls, count in class_counts.items()])
322+
323+
# Append the formatted string to the patch_info list
324+
output += f"\nOn patch № {i}, {class_info} were detected"
325+
else:
326+
# Append the formatted string to the patch_info list
327+
output += f"\nOn patch № {i}, nothing was detected"
328+
print(output)
329+

0 commit comments

Comments
 (0)