CropGuardFastAPI / converter.py
Jude Joseph Agustino
Initial Commit: CropGuard disease detection app
ca8798e
raw
history blame contribute delete
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}")