@@ -446,3 +446,36 @@ def not_agnostic_nms(
446446 )
447447 all_keeps .extend (keep_indexes )
448448 return all_keeps
449+
450+ def __str__ (self ):
451+ # List of useful attributes (non-empty ones)
452+ useful_attributes = []
453+ if self .filtered_confidences :
454+ useful_attributes .append ("filtered_confidences" )
455+ if self .filtered_boxes :
456+ useful_attributes .append ("filtered_boxes" )
457+ if self .filtered_classes_id :
458+ useful_attributes .append ("filtered_classes_id" )
459+ if self .filtered_classes_names :
460+ useful_attributes .append ("filtered_classes_names" )
461+ if self .filtered_masks :
462+ useful_attributes .append ("filtered_masks" )
463+ if self .filtered_polygons :
464+ useful_attributes .append ("filtered_polygons" )
465+
466+ # If all attributes are empty
467+ if not useful_attributes :
468+ return "Useful attributes: nothing detected in the frame."
469+
470+ # Build the output string
471+ output = "Useful attributes: " + ", " .join (useful_attributes ) + "\n \n "
472+ for attr in useful_attributes :
473+ value = getattr (self , attr )
474+ if attr == "filtered_masks" :
475+ output += f"{ attr } : the list of binary masks with shape { value [0 ].shape } (length: { len (value )} )\n "
476+ elif len (value ) > 10 :
477+ list_text = f"{ value [:10 ]} "
478+ output += f"{ attr } : { list_text [:- 1 ]} , ...] (length: { len (value )} )\n "
479+ else :
480+ output += f"{ attr } : { value } (length: { len (value )} )\n "
481+ return output
0 commit comments