ugahost991/plant-disease-detector
๐ฑ Plant Disease Detection - Vector Database This dataset contains pre-computed embeddings and FAISS index for plant disease detection using a RAG (Retrieval-Augmented Generation) approach. ๐ Dataset Overview Total Images: 54,304 Disease Classes: 38 Embedding Model: ResNet-50 (Microsoft) Embedding Dimension: 2048 Index Type: FAISS IndexFlatIP (Cosine Similarity) ๐ Files File Size Description embeddings.npy ~440 MB Pre-computed 2048-Dโฆ See the full description on the dataset page: https://huggingface.co/datasets/ugahost991/plant-disease-detector.
๐ฑ Plant Disease Detection - Vector Database
This dataset contains pre-computed embeddings and FAISS index for plant disease detection using a RAG (Retrieval-Augmented Generation) approach.
๐ Dataset Overview
- Total Images: 54,304
- Disease Classes: 38
- Embedding Model: ResNet-50 (Microsoft)
- Embedding Dimension: 2048
- Index Type: FAISS IndexFlatIP (Cosine Similarity)
๐ Files
๐ฟ Supported Plant Diseases
The dataset covers 38 disease classes across multiple crops:
Tomato (10 classes)
- Target Spot
- Septoria Leaf Spot
- Early Blight
- Late Blight
- Bacterial Spot
- Leaf Mold
- Spider Mites
- Yellow Leaf Curl Virus
- Mosaic Virus
- Healthy
Pepper/Bell Pepper (2 classes)
- Bacterial Spot
- Healthy
Corn/Maize (4 classes)
- Northern Leaf Blight
- Common Rust
- Cercospora Leaf Spot
- Healthy
Potato (3 classes)
- Early Blight
- Late Blight
- Healthy
Apple (4 classes)
- Apple Scab
- Black Rot
- Cedar Apple Rust
- Healthy
Grape (4 classes)
- Black Rot
- Esca (Black Measles)
- Leaf Blight
- Healthy
Cherry (2 classes)
- Powdery Mildew
- Healthy
Strawberry (2 classes)
- Leaf Scorch
- Healthy
Other Crops
- Peach, Raspberry, Soybean, Squash, and more
๐ Usage
Load the Database
import numpy as np
import json
import faiss
# Load embeddings
embeddings = np.load('embeddings.npy')
print(f"Embeddings shape: {embeddings.shape}") # (54304, 2048)
# Load metadata
with open('metadata.json', 'r') as f:
metadata = json.load(f)
print(f"Total images: {len(metadata)}")
# Load FAISS index
index = faiss.read_index('faiss_index.bin')
print(f"Index size: {index.ntotal}")Search for Similar Images
from transformers import AutoImageProcessor, AutoModel
from PIL import Image
import torch
# Load model
processor = AutoImageProcessor.from_pretrained("microsoft/resnet-50")
model = AutoModel.from_pretrained("microsoft/resnet-50")
# Process query image
image = Image.open("plant_leaf.jpg")
inputs = processor(images=image, return_tensors="pt")
# Extract features
with torch.no_grad():
outputs = model(**inputs)
query_embedding = outputs.pooler_output.numpy()
# Normalize
query_embedding = query_embedding / np.linalg.norm(query_embedding)
# Search
k = 5 # Top 5 similar images
distances, indices = index.search(query_embedding, k)
# Get results
for i, idx in enumerate(indices[0]):
similar_image = metadata[idx]
print(f"{i+1}. {similar_image['class']} - Similarity: {distances[0][i]:.4f}")Use with FastAPI
from fastapi import FastAPI, File, UploadFile
import numpy as np
import faiss
app = FastAPI()
# Load database on startup
embeddings = np.load('embeddings.npy')
metadata = json.load(open('metadata.json'))
index = faiss.read_index('faiss_index.bin')
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
# Extract features from uploaded image
# ... (feature extraction code)
# Search similar images
distances, indices = index.search(query_embedding, k=5)
# Majority voting for disease class
classes = [metadata[idx]['class'] for idx in indices[0]]
predicted_class = max(set(classes), key=classes.count)
return {"disease": predicted_class, "confidence": distances[0][0]}๐ฏ Use Cases
- Plant Disease Detection: Identify diseases from leaf images
- Agricultural Monitoring: Track crop health
- Research: Study plant disease patterns
- Education: Learn about plant diseases
- Mobile Apps: Build plant disease detection apps
๐ฌ Technical Details
Embedding Extraction
- Model: microsoft/resnet-50
- Input Size: 224x224 pixels
- Normalization: L2 normalization
- Batch Size: 64 (GPU)
- Processing Time: ~15 minutes on T4 GPU
FAISS Index
- Type: IndexFlatIP (Inner Product)
- Metric: Cosine Similarity
- Dimension: 2048
- Search Time: <10ms per query
๐ Performance
- Search Speed: Sub-10ms per query
- Accuracy: High (based on similarity)
- Scalability: Can handle millions of images
- Memory: ~1.8 GB total
๐ ๏ธ Building the Database
The database was built using:
# Extract features
from transformers import AutoImageProcessor, AutoModel
processor = AutoImageProcessor.from_pretrained("microsoft/resnet-50")
model = AutoModel.from_pretrained("microsoft/resnet-50")
# Process images
embeddings = []
for image_path in image_paths:
image = Image.open(image_path)
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
embedding = outputs.pooler_output.numpy()
embeddings.append(embedding)
# Build FAISS index
embeddings = np.vstack(embeddings)
faiss.normalize_L2(embeddings)
index = faiss.IndexFlatIP(2048)
index.add(embeddings)๐ฆ Integration
Download in Your App
from huggingface_hub import hf_hub_download
files = ['embeddings.npy', 'metadata.json', 'faiss_index.bin']
for filename in files:
hf_hub_download(
repo_id="ugahost991/plant-disease-detector",
filename=filename,
repo_type="dataset",
local_dir="vector_store"
)๐ License
MIT License - Free to use for commercial and non-commercial purposes
๐ Acknowledgments
- Dataset: PlantVillage Dataset
- Model: Microsoft ResNet-50
- Framework: FAISS (Facebook AI)
- Platform: Hugging Face Hub
๐ Contact
Gaston Software Solutions LLP
- ๐ Website: www.gss-tec.com
- ๐ง Email: info@gss-tec.com
- ๐ผ LinkedIn: Gaston Software Solutions LLP
- ๐ Issues: Open an issue on the dataset repository
For business inquiries, partnerships, or custom solutions, please contact us via email or visit our website.
๐ Related Resources
- Space: Plant Disease Detector API
- Model: microsoft/resnet-50
- Original Dataset: PlantVillage on Kaggle
๐ Statistics
{
"total_images": 54304,
"unique_classes": 38,
"embedding_dimension": 2048,
"index_type": "FAISS IndexFlatIP",
"file_size_mb": 888,
"build_time_minutes": 15,
"gpu_used": "T4"
}๐ Citation
If you use this dataset, please cite:
@dataset{plant_disease_embeddings_2024,
title={Plant Disease Detection Vector Database},
author={ugahost991},
year={2024},
publisher={Hugging Face},
howpublished={\url{https://huggingface.co/datasets/ugahost991/plant-disease-detector}}
}Built with โค๏ธ using ResNet-50, FAISS, and Hugging Face ๐ฑ๐
