TSRDA / MTLCC /code /band_stats.py
Dhruv1000's picture
Add MTLCC: code, tools, results, report, checkpoints (Option 1 complete)
6e33b3b verified
Raw History Blame Contribute Delete
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)