ClimateNet / scripts /inference.py
zhangrenchao's picture
Publish ClimateNet reproduction
63ef347 verified
Raw
History Blame Contribute Delete
718 Bytes
from pathlib import Path
import sys,numpy as np,torch
R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R));from model.climatenet import *
c=cfg(R);d=np.load(R/c['data']['path']);z=torch.load(R/c['paths']['checkpoint'],map_location='cpu',weights_only=True);m=ClimateNetDeepLab(**z['model_config']);m.load_state_dict(z['model']);mask=d['split']==2
with torch.no_grad():logits=m(torch.tensor(d['input'][mask]));pred=logits.argmax(1)
p=R/c['paths']['predictions'];p.parent.mkdir(parents=True,exist_ok=True);np.savez_compressed(p,prediction=pred.numpy(),probability=logits.softmax(1).numpy(),target=d['target'][mask],origins=d['origins'][mask],logical_shape=d['logical_shape'],is_complete_global=False);print(p)