File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import numpy as np
33import matplotlib .pyplot as plt
44from ultralytics import YOLO
5+ from collections import Counter
56
67from ..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 = "\n Detailed 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"\n On patch № { i } , { class_info } were detected"
325+ else :
326+ # Append the formatted string to the patch_info list
327+ output += f"\n On patch № { i } , nothing was detected"
328+ print (output )
329+
You can’t perform that action at this time.
0 commit comments