Repository navigation
Home
HealthyCropping (com.keylorpineda.healthycropping) is an open-source, non-commercial, offline-first agricultural decision-support system designed for smallholder farmers and field agronomists in Costa Rica. It provides real-time, on-device disease detection for Coffee, Cacao, and Banana crops using quantized deep learning models, augmented with grounded agronomic guidance powered by Retrieval-Augmented Generation (RAG).
The system is architected around a strict edge-first, privacy-preserving boundary. Primary phytosanitary triage operates 100% offline directly on the mobile device without external network dependencies. Cloud synchronization occurs opportunistically when connectivity is available.
flowchart TD
subgraph FIELD["Edge Layer (100% Offline — Android Device)"]
A["Leaf / Pod Photo Capture"] --> B["Deterministic Preprocessing<br/>(224x224 RGB, [-1.0, 1.0] Tensor)"]
B --> C["On-Device Fast-TFLite Engine<br/>(MobileNetV3-Large Float16)"]
C --> D{"Confidence ≥ Threshold?"}
D -- "Yes" --> E["Accepted Diagnosis<br/>& Immediate First-Aid Guidance"]
D -- "No (Abstention)" --> F["Low-Confidence Alert<br/>(Request Clearer Photo)"]
E --> G[("Local SQLite Storage<br/>healthycropping.db")]
F --> G
end
subgraph CLOUD["Cloud Layer (Opportunistic Online Sync)"]
G -. "Opportunistic Sync (Wi-Fi/4G)" .-> H["FastAPI Sync Gateway"]
H --> I["Gemini RAG Reasoning Engine"]
I <--> J[("Vector Knowledge Store<br/>ICAFE • CATIE • CORBANA Manuals")]
I -. "Grounded Agronomic Protocol" .-> G
end
| Crop | Target Organ | Monitored Classes | Scientific Agent | Reference Dataset Sources |
|---|---|---|---|---|
|
Coffee (Coffea arabica) |
Leaf | • Healthy • Rust (Roya) • Brown Eye Spot (Ojo de Gallo) • Iron Spot (Mancha de Hierro) |
Hemileia vastatrix Mycena citricolor Cercospora coffeicola |
RoCoLe • BRACOL (Group-stratified, pHash deduplicated) |
|
Cacao (Theobroma cacao) |
Pod (Mazorca) | • Healthy • Moniliasis (Monilia) • Black Pod (Mazorca Negra) |
Moniliophthora roreri Phytophthora palmivora |
CocoaMoniliaDataSet • UNAB YOLOv4 (YOLO pod crop extraction) |
|
Banana (Musa acuminata) |
Leaf | • Healthy • Black Sigatoka (Sigatoka Negra) • Fusarium Wilt (Mal de Panamá) |
Pseudocercospora fijiensis Fusarium oxysporum f. sp. cubense |
BananaLSD (Mendeley) • NM-AIST (Zenodo) (Range-based ZIP streaming) |
All classification models utilize the MobileNetV3-Large backbone, pre-trained on ImageNet-1k, fine-tuned on verified agricultural datasets, and quantized to IEEE 754 Float16.
flowchart LR
A["Raw RGB Image"] --> B["Bilinear Resize<br/>(224 × 224)"]
B --> C["Zero-Centered Normalization<br/>[(x / 127.5) - 1.0]"]
C --> D["Inverted Residual Blocks<br/>with Hard-Swish & Squeeze-Excite"]
D --> E["Global Average Pooling"]
E --> F["Dense Head + Softmax"]
F --> G["Calibrated Decision Gate"]
| Model Identifier | Architecture | Precision | Artifact Size | Test Macro-F1 | Top-1 Parity vs Keras | Calibrated Confidence Floor | Mean Inference Latency |
|---|---|---|---|---|---|---|---|
coffee-v0.1.0 |
MobileNetV3-Large | Float16 | 6.06 MB | 0.8841 | 100.0% | 0.70 | ~180 ms |
cacao-v0.1.0 |
MobileNetV3-Large | Float16 | 6.06 MB | 0.8502 | 100.0% | 0.70 | ~185 ms |
banana-v0.1.0 |
MobileNetV3-Large | Float16 | 6.06 MB | 0.9731 | 100.0% | 0.80 | ~185 ms |
To maximize diagnostic accuracy and eliminate visual ambiguity in agricultural conditions, adhere to the following sampling standards:
flowchart LR
Step1["1. Distance<br/>15 to 30 cm"] --> Step2["2. Illumination<br/>Diffuse daylight"]
Step2 --> Step3["3. Alignment<br/>Perpendicular to surface"]
Step3 --> Step4["4. Framing<br/>Single leaf/pod centered"]
- Distance & Framing: Position the camera lens 15 to 30 cm directly above the symptomatic tissue. Ensure the leaf blade or cacao pod occupies at least 70% of the active camera viewfinder.
- Illumination: Capture photos under uniform, diffuse ambient daylight (early morning or late afternoon). Avoid direct flashlight reflection, heavy lens glare, or intense overhead shadows.
- Background Isolation: Avoid placing fingers, tools, or multiple overlapping leaves directly beneath the target lesion.
- Abstention Handling: If the on-screen confidence gauge does not exceed the calibrated threshold, the application explicitly abstains from providing a definitive diagnosis. Re-frame and capture from an alternate angle with improved lighting.
When an internet connection is established, diagnosis records can be enriched via our FastAPI backend. The system prompts Gemini with relevant excerpts retrieved strictly from verified agronomic technical manuals:
- Coffee: Guía Técnica para la Caficultura Sostenible — Instituto del Café de Costa Rica (ICAFE).
- Cacao: Manual de Enfermedades y Manejo Agroecológico del Cacao — Centro Agronómico Tropical de Investigación y Enseñanza (CATIE).
- Banana: Guía de Identificación y Manejo de Sigatoka Negra y Fusariosis — Corporación Bananera Nacional (CORBANA).
Important
Ethical & Decision-Support Notice: HealthyCropping is a phytosanitary decision-support tool. It does not replace certified agronomists, official phytosanitary inspectors, or laboratory diagnostic assays (e.g., PCR or tissue culture).