Spaces:
Runtime error
Runtime error
Download modules/metrics.py from A1mal/APLIES-Model: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/A1mal/APLIES-Model/resolve/main/modules/metrics.py
- Command line
-
hf download hf://spaces/A1mal/APLIES-Model/modules/metrics.py
-
curl -L -o metrics.py https://huggingface.co/spaces/A1mal/APLIES-Model/resolve/main/modules/metrics.py
1.04 kB
| import time | |
| import numpy as np | |
| def calculate_execution_metrics(sequential_fn, parallel_fn, img, config): | |
| """ | |
| Compares timing and performance metrics. | |
| """ | |
| # Hot run to ensure cache/init doesn't skew small images (optional) | |
| # sequential_fn(img, config) | |
| # Sequential Test | |
| start_seq = time.perf_counter() | |
| res_seq = sequential_fn(img, config) | |
| time_seq = time.perf_counter() - start_seq | |
| # Parallel Test | |
| start_par = time.perf_counter() | |
| res_par = parallel_fn(img, config) | |
| time_par = time.perf_counter() - start_par | |
| speedup = time_seq / time_par if time_par > 0 else 1.0 | |
| return { | |
| "sequential_time": time_seq, | |
| "parallel_time": time_par, | |
| "speedup": speedup, | |
| "result": res_par # Use parallel result as final | |
| } | |
| def get_image_info(img): | |
| """ | |
| Returns resolution and channel info. | |
| """ | |
| h, w, c = img.shape | |
| return { | |
| "width": w, | |
| "height": h, | |
| "channels": c, | |
| "megapixels": (w * h) / 1e6 | |
| } | |