Following this instruction :
1. Strictly adhere to PEP-8 standards, ensuring code is clean, well-structured, and follows Python's style guide for readability.
2. Use appropriate modules like `typing` for type hints, ensuring code clarity, maintainability, and leveraging Python's standard libraries effectively.
3. Focus on time, space, robustness, scalability; write optimized, efficient code that can handle large datasets and scale seamlessly.
4. Implement comprehensive error handling, catching exceptions gracefully, providing meaningful error messages, and ensuring code robustness under unexpected conditions.
5. Ensure the developer agent writes advanced, maintainable Python code, balancing performance and readability while adhering to best practices.

TASK : we have develop below from scratch using torch module :


| **Metric**                       | **Equation**                                                                                           | **Description**                                                                                                 |
|----------------------------------|--------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| **Precision**                    | \( \text{Precision} = \frac{TP}{TP + FP} \)                                                           | Percentage of correctly predicted bounding boxes among all predicted boxes.                                   |
| **Recall**                       | \( \text{Recall} = \frac{TP}{TP + FN} \)                                                              | Measures the ability to detect all objects correctly.                                                          |
| **F1 Score**                     | \( \text{F1} = 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}{\text{Precision} + \text{Recall}} \) | Harmonic mean of Precision and Recall.                                                                        |
| **True Positive Rate (TPR)**     | \( \text{TPR} = \frac{TP}{TP + FN} \)                                                                 | Measures correctly identified positives, equivalent to Recall.                                                |
| **False Positive Rate (FPR)**    | \( \text{FPR} = \frac{FP}{FP + TN} \)                                                                 | Proportion of negatives incorrectly classified as positives.                                                  |
| **Intersection over Union (IoU)** | \( \text{IoU} = \frac{\text{Area of Overlap}}{\text{Area of Union}} \)                               | Measures overlap between predicted and ground truth bounding boxes.                                           |
| **Average Precision (AP)**       | \( \text{AP} = \int_{0}^{1} p(r) \, dr \)                                                             | Area under the precision-recall curve for a single class.                                                     |
| **Mean Average Precision (mAP)** | \( \text{mAP} = \frac{1}{N} \sum_{i=1}^{N} AP_i \)                                                   | Average of AP across all classes, a standard measure in object detection.                                     |
| **Average IoU**                  | \( \text{Average IoU} = \frac{1}{N} \sum_{i=1}^{N} \text{IoU}_i \)                                   | Average IoU for all objects, reflecting localization accuracy.                                                |
| **False Negative Rate (FNR)**    | \( \text{FNR} = \frac{FN}{FN + TP} \)                                                                | Measures how often ground truth objects are missed.                                                           |
| **Mean Precision (mP)**          | \( \text{mP} = \frac{1}{N} \sum_{i=1}^{N} \text{Precision}_i \)                                      | Average precision across multiple detection thresholds or classes.                                            |
| **Mean Recall (mR)**             | \( \text{mR} = \frac{1}{N} \sum_{i=1}^{N} \text{Recall}_i \)                                         | Average recall across multiple detection thresholds or classes.                                               |
| **Localization Error**           | Proportion of correctly detected objects with IoU < threshold                                        | Measures errors due to incorrect localization despite correct classification.                                 |
| **Classification Error**         | Proportion of misclassified objects, given IoU > threshold                                           | Measures classification errors where objects are detected with high IoU but incorrect class.                  |
| **Duplicate Detection Rate**     | \( \text{DDR} = \frac{\text{Number of Duplicate Detections}}{\text{Total Number of Detections}} \)   | Measures the frequency of duplicate detections for the same object.                                           |
| **Detection Rate**               | \( \text{Detection Rate} = \frac{TP}{TP + FN} \)                                                     | Ratio of correctly detected objects to all ground truth objects.                                              |
| **Miss Rate**                    | \( \text{Miss Rate} = \frac{FN}{TP + FN} \)                                                          | Ratio of missed objects relative to total ground truth objects.                                               |
| **False Discovery Rate (FDR)**   | \( \text{FDR} = \frac{FP}{TP + FP} \)                                                                | Measures the proportion of false positives among all positive detections.                                     |
| **Mean Squared Error (MSE) for Localization** | \( \text{MSE} = \frac{1}{N} \sum_{i=1}^{N} (y_i - \hat{y}_i)^2 \)                              | Measures the average squared error in bounding box coordinates (used in regression-based models).             |
| **Boundary Box Regression Loss** | Loss function used to improve localization accuracy, e.g., Smooth L1 or IoU Loss                      | Penalizes bounding box regression errors during model training.                                               |
| **Top-k Precision**              | Measures if the ground truth object is within the top k detected boxes                                | Commonly used in multi-object scenarios to check if the object is one of the top k predictions.               |
| **Precision@k (P@k)**            | Precision when considering top-k detections for each object                                          | Measures accuracy for the top-k detections.                                                                   |
| **Cohen’s Kappa**                | \( \kappa = \frac{\text{Observed Agreement} - \text{Expected Agreement}}{1 - \text{Expected Agreement}} \) | Measures the agreement between predictions and ground truth, adjusted for chance.                            |
| **Balanced Accuracy**            | \( \text{Balanced Accuracy} = \frac{\text{Recall} + \text{Specificity}}{2} \)                         | Average of Recall and Specificity, useful in imbalanced datasets.                                            |
| **Adjusted mAP**                 | mAP calculated using a stricter IoU threshold (e.g., 0.75)                                           | Measures model performance with stricter localization requirements.





we have test using module module 
for image/video/ objection