Spaces:
Sleeping
Sleeping
Delete test_improvements.py
Browse files- test_improvements.py +0 -103
test_improvements.py
DELETED
|
@@ -1,103 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Quick test to verify all 9 recommendations are working
|
| 3 |
-
"""
|
| 4 |
-
import cv2
|
| 5 |
-
import numpy as np
|
| 6 |
-
from reid import SQLiteEnhancedReID
|
| 7 |
-
from tracking import DeepSORTTracker
|
| 8 |
-
from detection import DogDetector
|
| 9 |
-
|
| 10 |
-
def test_recommendations():
|
| 11 |
-
"""Test that all recommendations are properly applied"""
|
| 12 |
-
|
| 13 |
-
print("="*80)
|
| 14 |
-
print("TESTING RECOMMENDATIONS 1-9")
|
| 15 |
-
print("="*80)
|
| 16 |
-
|
| 17 |
-
# Test #1: Threshold hierarchy
|
| 18 |
-
print("\nπ TEST #1: Threshold Hierarchy")
|
| 19 |
-
reid = SQLiteEnhancedReID()
|
| 20 |
-
reid.set_all_thresholds(0.35)
|
| 21 |
-
|
| 22 |
-
assert reid.database_threshold > reid.session_threshold, "β DB should be stricter!"
|
| 23 |
-
assert reid.session_threshold > reid.sleeping_threshold, "β Session should be > sleeping!"
|
| 24 |
-
print(f" β
Correct: DB({reid.database_threshold:.2f}) > "
|
| 25 |
-
f"Session({reid.session_threshold:.2f}) > "
|
| 26 |
-
f"Sleeping({reid.sleeping_threshold:.2f})")
|
| 27 |
-
|
| 28 |
-
# Test #2-4: DeepSORT parameters
|
| 29 |
-
print("\nπ― TEST #2-4: DeepSORT Parameters")
|
| 30 |
-
tracker = DeepSORTTracker(
|
| 31 |
-
max_iou_distance=0.5,
|
| 32 |
-
max_age=90,
|
| 33 |
-
n_init=1
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
assert tracker.n_init == 1, "β n_init should be 1"
|
| 37 |
-
assert tracker.max_age == 90, "β max_age should be 90"
|
| 38 |
-
assert tracker.max_iou_distance == 0.5, "β max_iou should be 0.5"
|
| 39 |
-
print(" β
n_init=1, max_age=90, max_iou=0.5")
|
| 40 |
-
|
| 41 |
-
# Test #5-6: Adaptive thresholding
|
| 42 |
-
print("\nπ TEST #5-6: Adaptive Thresholding")
|
| 43 |
-
metadata = {
|
| 44 |
-
'deepsort_hits': 15,
|
| 45 |
-
'deepsort_age': 20,
|
| 46 |
-
'frames_since_update': 0
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
adaptive_threshold = reid.compute_adaptive_threshold(metadata)
|
| 50 |
-
assert adaptive_threshold < reid.session_threshold, "β Should reduce threshold"
|
| 51 |
-
print(f" β
Adaptive: {reid.session_threshold:.2f} β {adaptive_threshold:.2f}")
|
| 52 |
-
|
| 53 |
-
# Test #7: Quality scoring
|
| 54 |
-
print("\nβ TEST #7: Quality Scoring")
|
| 55 |
-
test_image = np.random.randint(0, 255, (200, 200, 3), dtype=np.uint8)
|
| 56 |
-
quality, components = reid.compute_feature_quality(
|
| 57 |
-
test_image,
|
| 58 |
-
[50, 50, 150, 150],
|
| 59 |
-
confidence=0.8
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
assert 0 <= quality <= 1, "β Quality should be 0-1"
|
| 63 |
-
assert len(components) == 4, "β Should have 4 components"
|
| 64 |
-
print(f" β
Quality score: {quality:.3f}")
|
| 65 |
-
print(f" β
Components: {list(components.keys())}")
|
| 66 |
-
|
| 67 |
-
# Test #8: Storage reduction
|
| 68 |
-
print("\nπΎ TEST #8: Storage Reduction")
|
| 69 |
-
# Simulate adding many features
|
| 70 |
-
test_features = []
|
| 71 |
-
for i in range(30):
|
| 72 |
-
feat = np.random.randn(1536)
|
| 73 |
-
feat = feat / np.linalg.norm(feat)
|
| 74 |
-
test_features.append(feat)
|
| 75 |
-
|
| 76 |
-
# Should keep only 20
|
| 77 |
-
reid.temp_id_features[1] = []
|
| 78 |
-
for feat in test_features:
|
| 79 |
-
from reid import DogFeatures
|
| 80 |
-
dog_feat = DogFeatures(
|
| 81 |
-
features=feat,
|
| 82 |
-
quality=np.random.random(),
|
| 83 |
-
frame_num=i
|
| 84 |
-
)
|
| 85 |
-
reid.smart_feature_storage(1, dog_feat)
|
| 86 |
-
|
| 87 |
-
assert len(reid.temp_id_features[1]) <= 20, "β Should keep max 20 features"
|
| 88 |
-
print(f" β
Storage limited: {len(reid.temp_id_features[1])}/20")
|
| 89 |
-
|
| 90 |
-
# Test #9: Mean aggregation
|
| 91 |
-
print("\nπ TEST #9: Mean Aggregation")
|
| 92 |
-
mean_emb = reid.compute_mean_embedding(reid.temp_id_features[1])
|
| 93 |
-
|
| 94 |
-
assert mean_emb is not None, "β Should compute mean"
|
| 95 |
-
assert abs(np.linalg.norm(mean_emb) - 1.0) < 0.01, "β Should be normalized"
|
| 96 |
-
print(f" β
Mean embedding computed, norm={np.linalg.norm(mean_emb):.3f}")
|
| 97 |
-
|
| 98 |
-
print("\n" + "="*80)
|
| 99 |
-
print("β
ALL TESTS PASSED - Recommendations 1-9 working!")
|
| 100 |
-
print("="*80)
|
| 101 |
-
|
| 102 |
-
if __name__ == "__main__":
|
| 103 |
-
test_recommendations()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|