DLESyM / scripts /inference.py
zhangrenchao's picture
Publish DLESyM reproduction
bec9cbb verified
Raw
History Blame Contribute Delete
692 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.dlesym import *
c=cfg(R);z=torch.load(R/c['paths']['checkpoint'],map_location='cpu',weights_only=True);m=DLESyM(**z['model_config']);m.load_state_dict(z['model']);a,s=state(20);a=a[None];s=s[None];aa=[];ss=[];pp=[]
with torch.no_grad():
for _ in range(4):a,s,p=m(a,s);aa.append(a[0].numpy());ss.append(s[0].numpy());pp.append(p[0].numpy())
q=R/c['paths']['predictions'];q.parent.mkdir(parents=True,exist_ok=True);np.savez_compressed(q,atmosphere=aa,sst=ss,precipitation=pp,lead_days=np.arange(1,5)*4,logical_shape=[10,180,360],is_complete_global=False);print(q)