Download pixelgen/weights.py from DJLougen/pixelgen2: direct link, hf CLI and curl.
- Browser
- Download file 770 Bytes
-
https://huggingface.co/DJLougen/pixelgen2/resolve/main/pixelgen/weights.py
- Command line
-
hf download hf://DJLougen/pixelgen2/pixelgen/weights.py
-
curl -L -o weights.py https://huggingface.co/DJLougen/pixelgen2/resolve/main/pixelgen/weights.py
770 Bytes
| """Save and load the hand-written PixelGen state dict. | |
| The weights are set in code, so saving is only a convenience: it lets | |
| generate.py run without re-building the model and gives a file to check | |
| into version control. | |
| """ | |
| from pathlib import Path | |
| import torch | |
| from .model import PixelGen | |
| DEFAULT_PATH = Path(__file__).resolve().parent.parent / "weights" / "pixelgen.pt" | |
| def save(path=DEFAULT_PATH, model=None): | |
| model = model or PixelGen() | |
| path = Path(path) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| torch.save(model.state_dict(), path) | |
| return path | |
| def load(path=DEFAULT_PATH): | |
| model = PixelGen() | |
| state = torch.load(path, map_location="cpu", weights_only=True) | |
| model.load_state_dict(state) | |
| model.eval() | |
| return model | |