--- license: mit tags: - keras - tensorflow - image-classification - agriculture - crop-disease-detection - mobilenetv2 - rwanda base_model: mobilenetv2 --- # CropSense MobileNetV2 - Crop Disease Detection Model ## Model Description This is a MobileNetV2-based deep learning model trained to detect crop diseases in leaf images. The model is specifically designed for smallholder farmers in Rwanda to identify common crop diseases. **Model Type**: Image Classification **Framework**: Keras/TensorFlow **Architecture**: MobileNetV2 **Input**: 224x224 RGB images **Output**: Disease classification (Healthy, Powdery, Rust) ## Model Details - **Model Size**: ~14 MB - **Classes**: 3 (Healthy, Powdery, Rust) - **Input Shape**: (224, 224, 3) - **Optimized for**: Mobile and edge devices ## Usage ### Using Python ```python from huggingface_hub import hf_hub_download import tensorflow as tf from PIL import Image import numpy as np # Download model from Hugging Face model_path = hf_hub_download( repo_id="Ruzindana/cropsense-mobilenetv2", filename="best_MobileNetV2.keras" ) # Load the model model = tf.keras.models.load_model(model_path) # Load class names import json with open(hf_hub_download( repo_id="Ruzindana/cropsense-mobilenetv2", filename="model_metadata.json" )) as f: metadata = json.load(f) class_names = metadata.get("classes", ["Healthy", "Powdery", "Rust"]) # Preprocess image def preprocess_image(image_path): img = Image.open(image_path).resize((224, 224)) img_array = np.array(img) / 255.0 img_array = np.expand_dims(img_array, axis=0) return img_array # Make prediction image = preprocess_image("path/to/leaf_image.jpg") predictions = model.predict(image) predicted_class_idx = np.argmax(predictions[0]) confidence = float(predictions[0][predicted_class_idx]) predicted_class = class_names[predicted_class_idx] print(f"Prediction: {predicted_class} ({confidence*100:.2f}% confidence)") ``` ### Using FastAPI Backend Set the environment variable: ```bash export HUGGINGFACE_MODEL_ID="Ruzindana/cropsense-mobilenetv2" ``` The backend will automatically download and use the model. ## Model Performance - **Accuracy**: Optimized for mobile deployment - **Inference Speed**: Fast inference on CPU and mobile devices - **Use Case**: Real-time crop disease detection in field conditions ## Training Data The model was trained on a dataset of crop leaf images from Rwanda, focusing on: - Healthy crop leaves - Powdery mildew infected leaves - Rust disease infected leaves ## Limitations - Trained specifically for certain crop types common in Rwanda - Best results with clear, well-lit leaf images - May require retraining for different geographic regions or crop varieties ## Citation If you use this model, please cite: ```bibtex @model{cropsense-mobilenetv2, author = {Ruzindana, Diana}, title = {CropSense MobileNetV2 - Crop Disease Detection Model}, year = {2025}, url = {https://huggingface.co/Ruzindana/cropsense-mobilenetv2} } ``` ## License MIT License - See LICENSE file for details ## Contact For questions or support, please contact the model maintainer.