Download model/nncam_stable.py from OneScience-Group/NNCAM-Stable: direct link, hf CLI and curl.
- Browser
- Download file 766 Bytes
-
https://huggingface.co/OneScience-Group/NNCAM-Stable/resolve/main/model/nncam_stable.py
- Command line
-
hf download hf://OneScience-Group/NNCAM-Stable/model/nncam_stable.py
-
curl -L -o nncam_stable.py https://huggingface.co/OneScience-Group/NNCAM-Stable/resolve/main/model/nncam_stable.py
766 Bytes
| import json,torch,yaml | |
| from pathlib import Path | |
| from torch import nn | |
| def cfg(r):return yaml.safe_load((Path(r)/'conf/config.yaml').read_text()) | |
| class ResidualDNN(nn.Module): | |
| def __init__(self,i,o,h):super().__init__();self.a=nn.Linear(i,h);self.b=nn.Linear(h,h);self.o=nn.Linear(h,o) | |
| def forward(self,x):z=torch.relu(self.a(x));return self.o(z+torch.relu(self.b(z))) | |
| class NNCAM(nn.Module): | |
| def __init__(self,hidden=64):super().__init__();self.q=ResidualDNN(122,30,hidden);self.s=ResidualDNN(122,30,hidden);self.rad=ResidualDNN(122,8,hidden);self.model_config={'hidden':hidden} | |
| def forward(self,x):return torch.cat((self.q(x),self.s(x),self.rad(x)),1) | |
| def write(p,o):p=Path(p);p.parent.mkdir(parents=True,exist_ok=True);p.write_text(json.dumps(o,indent=2)+'\n') | |