Spaces:
Sleeping
Sleeping
Download temp.py from harshitkalra02/CLIPCAP: direct link, hf CLI and curl.
- Browser
- Download file 659 Bytes
-
https://huggingface.co/spaces/harshitkalra02/CLIPCAP/resolve/main/temp.py
- Command line
-
hf download hf://spaces/harshitkalra02/CLIPCAP/temp.py
-
curl -L -o temp.py https://huggingface.co/spaces/harshitkalra02/CLIPCAP/resolve/main/temp.py
659 Bytes
| import torch | |
| # Load the fat checkpoint | |
| ckpt = torch.load("best_model.pt", map_location="cpu") | |
| print("Keys in checkpoint:", list(ckpt.keys())) | |
| for k, v in ckpt.items(): | |
| try: | |
| size = sum(p.numel() for p in v.values()) * 4 / 1e6 if isinstance(v, dict) else "scalar" | |
| print(f" {k}: {size} MB" if size != "scalar" else f" {k}: {v}") | |
| except Exception: | |
| print(f" {k}: (unknown)") | |
| # Keep ONLY what app.py needs | |
| slim = { | |
| "mapping_network_state_dict": ckpt["mapping_network_state_dict"], | |
| "epoch": ckpt.get("epoch"), | |
| "val_loss": ckpt.get("val_loss"), | |
| } | |
| torch.save(slim, "best_model_slim.pt") | |
| print("Saved slim checkpoint") |