Download code/agt/eval/summary.py from MRBSTUDIO/AGT: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/MRBSTUDIO/AGT/resolve/main/code/agt/eval/summary.py
- Command line
-
hf download hf://MRBSTUDIO/AGT/code/agt/eval/summary.py
-
curl -L -o summary.py https://huggingface.co/MRBSTUDIO/AGT/resolve/main/code/agt/eval/summary.py
1.43 kB
| from __future__ import annotations | |
| import json | |
| import math | |
| import os | |
| from pathlib import Path | |
| import numpy as np | |
| from .rgb import mean, number, scalar | |
| METRICS = ('full_psnr', 'full_ssim', 'full_lpips', 'observed_psnr', 'observed_ssim', 'observed_lpips', | |
| 'unobserved_psnr', 'unobserved_lpips', 'unobserved_dists', 'depth_absrel', 'depth_rmse') | |
| def write_json(path, value): | |
| path = Path(path) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| temporary = path.with_name('.' + path.name + f'.{os.getpid()}.tmp') | |
| temporary.write_text(json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False) + '\n') | |
| temporary.replace(path) | |
| def valid_value(value): | |
| if value is None: | |
| return False | |
| value = number(value) | |
| return isinstance(value, (int, float, np.floating)) and not math.isnan(value) and value != -float('inf') | |
| def summary(per_clip): | |
| out, counts = {}, {} | |
| for key in METRICS: | |
| values = [row['values'][key] for row in per_clip if valid_value(row['values'][key])] | |
| out[key], counts[key] = (scalar(mean(values)) if values else None), len(values) | |
| out['n'] = len(per_clip) | |
| return dict(metrics=out, valid_clip_counts=counts) | |
| def export(per_clip, destination): | |
| destination = Path(destination) | |
| write_json(destination / 'per_clip.json', per_clip) | |
| result = summary(per_clip) | |
| write_json(destination / 'summary.json', result) | |
| return result | |