Spaces:
Sleeping
Sleeping
File size: 664 Bytes
ca8798e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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}") |