Spaces:
Runtime error
Runtime error
Download Experiments Notebook/scripts/utils.py from masabhuq/lemon_quality_classifier: direct link, hf CLI and curl.
- Browser
- Download file 491 Bytes
-
https://huggingface.co/spaces/masabhuq/lemon_quality_classifier/resolve/main/Experiments%20Notebook/scripts/utils.py
- Command line
-
hf download 'hf://spaces/masabhuq/lemon_quality_classifier/Experiments Notebook/scripts/utils.py'
-
curl -L -o utils.py https://huggingface.co/spaces/masabhuq/lemon_quality_classifier/resolve/main/Experiments%20Notebook/scripts/utils.py
491 Bytes
| from pathlib import Path | |
| import torch | |
| def save_model(model: torch.nn.Module, | |
| model_name: str, | |
| target_dir: str): | |
| target_dir_path = Path(target_dir) | |
| target_dir_path.mkdir(parents = True, | |
| exist_ok = True) | |
| assert model_name.endswith(".pth") or model_name.endswith(".pt"), "Model name should end with .pth or .pt" | |
| model_save_path = target_dir_path / model_name | |
| torch.save(obj = model.state_dict(), | |
| f = model_save_path) | |