File size: 1,552 Bytes
1c58706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import cv2
import time
from src.core.pose import PoseEstimator
from src.core.cache_utils import save_to_cache, load_from_cache, get_file_hash

def test_optimization():
    print("--- Testing Optimization ---")
    
    # Create a dummy image
    dummy_img = (os.urandom(480*640*3))
    import numpy as np
    frame = np.frombuffer(dummy_img, dtype=np.uint8).reshape((480, 640, 3))
    
    # 1. Test Model Selection & Resizing
    print("Testing PoseEstimator(model_type='lite', resize_width=240)...")
    try:
        estimator = PoseEstimator(model_type="lite", resize_width=240)
        start_time = time.time()
        results = estimator.process_frame(frame)
        end_time = time.time()
        print(f"Inference time (Lite, 240p): {end_time - start_time:.4f}s")
        estimator.close()
    except Exception as e:
        print(f"Error in Lite/240p: {e}")

    # 2. Test Caching logic
    print("\nTesting Cache Logic...")
    test_file = "test_video.mp4"
    # Create a dummy file for hashing
    with open(test_file, 'wb') as f:
        f.write(b"dummy data")
    
    data = [{"frame": 0, "landmarks": {"pose": "test"}}]
    
    save_to_cache(test_file, data)
    loaded_data = load_from_cache(test_file)
    
    if loaded_data == data:
        print("✅ Cache Save/Load successful!")
    else:
        print("❌ Cache Save/Load failed!")
    
    # Cleanup
    if os.path.exists(test_file): os.remove(test_file)
    # Note: Cache file remains in outputs/cache/ (intended)

if __name__ == "__main__":
    test_optimization()