fruit_project.utils.metrics =========================== .. py:module:: fruit_project.utils.metrics Classes ------- .. autoapisummary:: fruit_project.utils.metrics.ConfusionMatrix fruit_project.utils.metrics.MAPEvaluator Module Contents --------------- .. py:class:: ConfusionMatrix(nc: int, conf: float = 0.25, iou_thres: float = 0.45) Object Detection Confusion Matrix inspired by Ultralytics. :param nc: Number of classes. :type nc: int :param conf: Confidence threshold for detections. :type conf: float :param iou_thres: IoU threshold for matching. :type iou_thres: float .. py:attribute:: nc .. py:attribute:: conf :value: 0.25 .. py:attribute:: iou_thres :value: 0.45 .. py:attribute:: matrix .. py:attribute:: eps :value: 1e-06 .. py:method:: process_batch(detections: torch.Tensor, labels: torch.Tensor) -> None Update the confusion matrix with a batch of detections and ground truths. :param detections: Tensor of detections, shape [N, 6] (x1, y1, x2, y2, conf, class). :type detections: torch.Tensor :param labels: Tensor of ground truths, shape [M, 5] (class, x1, y1, x2, y2). :type labels: torch.Tensor .. py:method:: update(preds, targets_for_cm) .. py:method:: plot(class_names: List[str], normalize: bool = True) -> matplotlib.pyplot.Figure Generates and returns a matplotlib figure of the confusion matrix. .. py:method:: get_matrix() -> torch.Tensor Returns the raw confusion matrix tensor. :returns: The (nc + 1) x (nc + 1) confusion matrix. :rtype: torch.Tensor .. py:class:: MAPEvaluator(image_processor, device, threshold: float = 0.0, id2label: Optional[Dict[int, str]] = None) Mean Average Precision evaluator for RT-DETRv2 - adapted for fruit_project. .. py:attribute:: image_processor .. py:attribute:: threshold :value: 0.0 .. py:attribute:: id2label :value: None .. py:attribute:: map_metric .. py:attribute:: map_50_metric .. py:attribute:: device .. py:method:: collect_image_sizes(targets) Collect image sizes from targets. .. py:method:: collect_targets(targets, image_sizes) Process ground truth targets - now handles HF-processed format. .. py:method:: collect_predictions(predictions, image_sizes) Process model predictions using HuggingFace post-processing. .. py:method:: get_per_class(map_50_metrics, metric) .. py:method:: get_optimal_f1_ultralytics_style(metrics_dict) .. py:method:: get_averaged_precision_recall_ultralytics_style(optimal_precisions: torch.Tensor, optimal_recalls: torch.Tensor, present_classes: torch.Tensor) Calculate overall precision and recall...