Download src/core/test_optimization.py from AnhLee0/AI-Coach: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/AnhLee0/AI-Coach/resolve/main/src/core/test_optimization.py
- Command line
-
hf download hf://spaces/AnhLee0/AI-Coach/src/core/test_optimization.py
-
curl -L -o test_optimization.py https://huggingface.co/spaces/AnhLee0/AI-Coach/resolve/main/src/core/test_optimization.py
1.55 kB
| 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() | |