Download MTLCC/code/band_stats.py from Dhruv1000/TSRDA: direct link, hf CLI and curl.
- Browser
- Download file 861 Bytes
-
https://huggingface.co/Dhruv1000/TSRDA/resolve/main/MTLCC/code/band_stats.py
- Command line
-
hf download hf://Dhruv1000/TSRDA/MTLCC/code/band_stats.py
-
curl -L -o band_stats.py https://huggingface.co/Dhruv1000/TSRDA/resolve/main/MTLCC/code/band_stats.py
861 Bytes
| """Per-band mean/std of the MTLCC training pool (reflectance*1e-4), used ONLY to | |
| express the PASTIS-tuned augmentation magnitudes (written in z-score units) | |
| on un-normalised MTLCC input. Inputs to the network stay un-normalised.""" | |
| import json | |
| import torch | |
| import config as C | |
| _P = C.EXP_ROOT / "cache" / "band_stats.json" | |
| _T = {} | |
| def _load(): | |
| if "m" not in _T: | |
| d = json.loads(_P.read_text()) if _P.is_file() else {"mean": [0.0] * C.N_CHANNELS, "std": [1.0] * C.N_CHANNELS} | |
| _T["m"], _T["s"] = d["mean"], d["std"] | |
| def mean_like(xc): # (C,1,1) broadcast over (B,n,C,H,W) | |
| _load(); return torch.tensor(_T["m"], device=xc.device, dtype=xc.dtype).view(-1, 1, 1) | |
| def std_like(xc): # (1,1,C,1,1) | |
| _load(); return torch.tensor(_T["s"], device=xc.device, dtype=xc.dtype).view(1, 1, -1, 1, 1) | |