| 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 ---") |
| |
| |
| dummy_img = (os.urandom(480*640*3)) |
| import numpy as np |
| frame = np.frombuffer(dummy_img, dtype=np.uint8).reshape((480, 640, 3)) |
| |
| |
| 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}") |
|
|
| |
| print("\nTesting Cache Logic...") |
| test_file = "test_video.mp4" |
| |
| 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!") |
| |
| |
| if os.path.exists(test_file): os.remove(test_file) |
| |
|
|
| if __name__ == "__main__": |
| test_optimization() |
|
|