Spaces:
Runtime error
Runtime error
Download converter.py from Jaysum/CropGuardFastAPI: direct link, hf CLI and curl.
- Browser
- Download file 664 Bytes
-
https://huggingface.co/spaces/Jaysum/CropGuardFastAPI/resolve/main/converter.py
- Command line
-
hf download hf://spaces/Jaysum/CropGuardFastAPI/converter.py
-
curl -L -o converter.py https://huggingface.co/spaces/Jaysum/CropGuardFastAPI/resolve/main/converter.py
664 Bytes
| import torch | |
| from models import ResNet9 | |
| # Load the existing model | |
| try: | |
| old_model = torch.load("plant-disease-model.pth", map_location="cpu", weights_only=False) | |
| # Save only the state dict | |
| torch.save(old_model.state_dict(), "plant-disease-model-state-dict.pth") | |
| print("✅ Model converted to state dict format") | |
| # Test loading the new format | |
| new_model = ResNet9(3, 38) # 38 classes based on your CLASS_NAMES | |
| new_model.load_state_dict(torch.load("plant-disease-model-state-dict.pth")) | |
| new_model.eval() | |
| print("✅ Converted model loads successfully") | |
| except Exception as e: | |
| print(f"❌ Conversion failed: {e}") |