iqramukhtiar's picture
Update dummy_model.py
27ae391 verified
raw
history blame
2.08 kB
import torch
import torch.nn as nn
from torchvision import models
import json
import random
import os
def create_dummy_model():
"""
Creates a dummy model and class names file for demonstration purposes.
This allows the app to run without requiring a fully trained model.
"""
print("Creating dummy model for demonstration...")
# Create a simple ResNet model
model = models.resnet50(weights=None)
# Modify the final layer for our number of classes
num_classes = 38
model.fc = nn.Linear(model.fc.in_features, num_classes)
# Save the untrained model
torch.save(model.state_dict(), 'plant_disease_model.pth')
print("Dummy model saved as plant_disease_model.pth")
# Create default class names
class_names = [
"Apple___Apple_scab", "Apple___Black_rot", "Apple___Cedar_apple_rust", "Apple___healthy",
"Cherry___healthy", "Cherry___Powdery_mildew", "Corn___Cercospora_leaf_spot",
"Corn___Common_rust", "Corn___healthy", "Corn___Northern_Leaf_Blight",
"Grape___Black_rot", "Grape___Esca_(Black_Measles)", "Grape___healthy",
"Grape___Leaf_blight_(Isariopsis_Leaf_Spot)", "Orange___Haunglongbing_(Citrus_greening)",
"Peach___Bacterial_spot", "Peach___healthy", "Pepper,_bell___Bacterial_spot",
"Pepper,_bell___healthy", "Potato___Early_blight", "Potato___healthy",
"Potato___Late_blight", "Squash___Powdery_mildew", "Strawberry___healthy",
"Strawberry___Leaf_scorch", "Tomato___Bacterial_spot", "Tomato___Early_blight",
"Tomato___healthy", "Tomato___Late_blight", "Tomato___Leaf_Mold",
"Tomato___Septoria_leaf_spot", "Tomato___Spider_mites Two-spotted_spider_mite",
"Tomato___Target_Spot", "Tomato___Tomato_mosaic_virus",
"Tomato___Tomato_Yellow_Leaf_Curl_Virus"
]
# Save class names to a JSON file
with open('class_names.json', 'w') as f:
json.dump(class_names, f)
print("Class names saved to class_names.json")
if __name__ == "__main__":
create_dummy_model()