Download scripts/predict.py from SPARK-LAB/ST-DTKD: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/SPARK-LAB/ST-DTKD/resolve/main/scripts/predict.py
- Command line
-
hf download hf://SPARK-LAB/ST-DTKD/scripts/predict.py
-
curl -L -o predict.py https://huggingface.co/SPARK-LAB/ST-DTKD/resolve/main/scripts/predict.py
1.26 kB
| """Frozen inference on preprocessed tensor inputs, not raw magnetograms.""" | |
| import argparse,json | |
| from common import * | |
| p=argparse.ArgumentParser(description=__doc__);p.add_argument('--artifact',required=True);p.add_argument('--input',required=True,help='torch tensor dictionary: HMI and/or AIA');p.add_argument('--output',default='predictions.npz');p.add_argument('--device',default='cpu');p.add_argument('--checkpoint-root');p.add_argument('--run-tag');args=p.parse_args() | |
| import torch,numpy as np | |
| a=artifact(args.artifact);model=load_model(a,args.device,args.checkpoint_root,args.run_tag);batch=torch.load(args.input,map_location='cpu',weights_only=True) | |
| with torch.inference_mode(): | |
| if a['architecture']=='mdt':logits=model(batch['AIA'].to(args.device),batch['HMI'].to(args.device))[0] | |
| elif a['temporal']:logits=model(batch[a['modality']].to(args.device),return_features=False) | |
| else:logits=model(batch[a['modality']].to(args.device)) | |
| assert logits.ndim==2 and logits.shape[1]==2 and torch.isfinite(logits).all();prob=logits.softmax(-1).cpu().numpy() | |
| out=output_path(args.output);np.savez(out,logits=logits.cpu().numpy(),probabilities=prob,predictions=(prob[:,1]>=.5).astype(int));print(json.dumps({'artifact':a['id'],'output':str(out),'n':len(prob)})) | |