<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Keylor Pineda</title>
    <description>The latest articles on DEV Community by Keylor Pineda (@keylorpineda).</description>
    <link>https://dev.to/keylorpineda</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4200313%2F5c8cb354-c838-41a2-b439-9e41bff26cc9.png</url>
      <title>DEV Community: Keylor Pineda</title>
      <link>https://dev.to/keylorpineda</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/keylorpineda"/>
    <language>en</language>
    <item>
      <title>Building an Offline-First Crop Disease Detector with React Native, On-Device TFLite, and Grounded RAG</title>
      <dc:creator>Keylor Pineda</dc:creator>
      <pubDate>Thu, 22 Oct 2026 11:04:59 +0000</pubDate>
      <link>https://dev.to/keylorpineda/building-an-offline-first-crop-disease-detector-with-react-native-on-device-tflite-and-grounded-1l12</link>
      <guid>https://dev.to/keylorpineda/building-an-offline-first-crop-disease-detector-with-react-native-on-device-tflite-and-grounded-1l12</guid>
      <description>&lt;h3&gt;
  
  
  The Reality of Smallholder Agriculture in Central America
&lt;/h3&gt;

&lt;p&gt;In mountainous agricultural regions across Costa Rica and Central America, smallholder producers of coffee (&lt;em&gt;Coffea arabica&lt;/em&gt;), cacao (&lt;em&gt;Theobroma cacao&lt;/em&gt;), and banana (&lt;em&gt;Musa&lt;/em&gt; spp.) cultivate plots where cellular connectivity is intermittent or completely absent. &lt;/p&gt;

&lt;p&gt;When foliar and pod pathogens strike—such as Coffee Leaf Rust (&lt;em&gt;Hemileia vastatrix&lt;/em&gt;), Cacao Frosty Pod Rot (&lt;em&gt;Moniliophthora roreri&lt;/em&gt;), or Banana Black Sigatoka (&lt;em&gt;Pseudocercospora fijiensis&lt;/em&gt;)—early and accurate diagnosis is critical. A delay of several days or a mistaken treatment can destroy an entire seasonal harvest.&lt;/p&gt;

&lt;p&gt;Cloud-based computer vision APIs fail in this environment: when standing in a steep coffee parcel miles away from the nearest cell tower, an app requiring a round-trip network request is unusable.&lt;/p&gt;

&lt;p&gt;To address this challenge, we built &lt;strong&gt;HealthyCropping&lt;/strong&gt;, an open-source, non-commercial, offline-first Android application.&lt;/p&gt;

&lt;p&gt;GitHub Repository: &lt;a href="https://github.com/keylorpineda/healthycropping" rel="noopener noreferrer"&gt;https://github.com/keylorpineda/healthycropping&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Architectural Principle: 100% Offline by Default
&lt;/h3&gt;

&lt;p&gt;HealthyCropping was architected so that no core user action—capturing a photo, running deep learning inference, evaluating disease severity, or registering a plot sector—requires an internet connection.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Field Camera Capture:&lt;/strong&gt; Guided framing tips tailored to leaf underside (coffee/banana) or pod surface (cacao).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On-Device Preprocessing:&lt;/strong&gt; In-memory 224x224 RGB decoding and normalization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Offline Inference:&lt;/strong&gt; MobileNetV3 TFLite models running locally in under 50ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instant Severity Triage:&lt;/strong&gt; Results reported immediately on screen with actionable status (healthy, watch, act now).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Persistence:&lt;/strong&gt; Data written to expo-sqlite using client-side UUIDs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optional Cloud Bridge:&lt;/strong&gt; Asynchronous batch synchronization with FastAPI and Gemini RAG once connectivity is restored.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Challenge 1: Edge Inference Without Freezing the UI Thread
&lt;/h3&gt;

&lt;p&gt;Running deep learning models on mid-range and low-end Android hardware presents severe memory and latency constraints. Loading a full TensorFlow runtime or converting uncompressed models causes dropped frames, out-of-memory crashes, and excessive battery drain.&lt;/p&gt;

&lt;p&gt;We addressed this through three key architectural decisions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Specialist Models per Plant Organ:&lt;/strong&gt; Instead of an oversized multi-class model trying to classify all plants at once, we trained dedicated MobileNetV3-Large architectures focused on specific plant organs: Coffee Leaf, Cacao Pod, and Banana Leaf.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantization:&lt;/strong&gt; Models are exported and quantized to float16 and INT8, reducing file sizes to below 10 MB per model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hardware Acceleration via Fast TFLite:&lt;/strong&gt; We utilize react-native-fast-tflite, which binds directly to native C++ TFLite runtimes using GPU/NNAPI delegates where available. On test hardware, inference consistently completes in &lt;strong&gt;under 50 milliseconds&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Challenge 2: The Tensor Parity Trap
&lt;/h3&gt;

&lt;p&gt;A common pitfall in edge machine learning is &lt;strong&gt;training-to-deployment preprocessing drift&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;A model trained in Python with Keras might achieve 95% accuracy on test splits, but once deployed in a mobile JavaScript environment, slight differences in image decoding, resizing interpolation, or RGB normalization formulas degrade real-world accuracy drastically.&lt;/p&gt;

&lt;p&gt;To prevent this drift, we created a shared fixture test suite between the Python ML repository (&lt;code&gt;ml/&lt;/code&gt;) and the React Native client (&lt;code&gt;app/&lt;/code&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A reference test image is passed through Python preprocessing (&lt;code&gt;ml/src/preprocessing/&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The resulting 224x224 RGB float array is exported as an exact numerical fixture.&lt;/li&gt;
&lt;li&gt;A Jest unit test in React Native runs the mobile decoding pipeline (&lt;code&gt;app/src/ml/preprocessor.ts&lt;/code&gt;) and asserts bit-for-bit parity against the Python reference tensor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any change is made to normalization statistics or channel ordering, the automated CI pipeline fails before any model reaches the mobile bundle.&lt;/p&gt;




&lt;h3&gt;
  
  
  Challenge 3: Offline Data Integrity with SQLite
&lt;/h3&gt;

&lt;p&gt;Farms, plots, and scans are stored locally using &lt;code&gt;expo-sqlite&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Because users work offline for days, primary keys cannot rely on auto-incrementing database IDs generated by a remote server. We generate client-side &lt;code&gt;UUIDv4&lt;/code&gt; identifiers for all entities.&lt;/p&gt;

&lt;p&gt;When connectivity is eventually restored, an idempotent synchronization engine reconciles local changes with our remote backend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unsynced records are batched into a single payload.&lt;/li&gt;
&lt;li&gt;The backend processes records with upsert semantics, eliminating duplicate entries caused by network drops during sync.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Challenge 4: Preventing Dangerous AI Hallucinations
&lt;/h3&gt;

&lt;p&gt;Generative AI in agriculture presents a serious risk: an unconstrained Large Language Model might invent chemical mixtures, incorrect dosages, or illegal fungicides that harm crops, contaminate soil, or void organic certifications.&lt;/p&gt;

&lt;p&gt;HealthyCropping uses a &lt;strong&gt;Grounded Retrieval-Augmented Generation (RAG)&lt;/strong&gt; pipeline powered by FastAPI and Gemini:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Curated Agronomic Corpus:&lt;/strong&gt; We ingest verified technical manuals from national institutions (such as Costa Rica's ICAFE for coffee and CATIE for cacao).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strict Source Attribution:&lt;/strong&gt; The RAG prompt strictly confines Gemini to the retrieved manual passages. It is instructed to reject answering if verified guidance is missing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structured Recommendations:&lt;/strong&gt; Guidance is categorized into Cultural Controls (e.g., pruning, shade regulation) and Approved Phytosanitary Measures, always citing the exact manual title and page number.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Current Status and Open Source Opportunities
&lt;/h3&gt;

&lt;p&gt;HealthyCropping is actively in development across 9 structured phases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Phases 1 to 5 (Completed):&lt;/strong&gt; Model pipelines for coffee, cacao, and banana; float16/INT8 TFLite export; Expo React Native client shell; offline SQLite schema; and camera triage interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Phases 6 and 7 (In Progress):&lt;/strong&gt; FastAPI cloud synchronization, Firebase token boundaries, Cloudinary image ingestion, and Gemini RAG advisory integration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We welcome open-source contributions across all layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mobile Engineers (React Native, TypeScript, Expo, SQLite):&lt;/strong&gt; Sync engine optimizations, battery profiling, and UI testing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend Engineers (Python 3.12, FastAPI, Firebase Admin):&lt;/strong&gt; Batch sync endpoints, async processing pipelines, and API security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ML Engineers (TensorFlow, TFLite):&lt;/strong&gt; Quantization-aware training (QAT), dataset validation, and mobile inference benchmarks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agronomists &amp;amp; Researchers:&lt;/strong&gt; Manual curation, retrieval chunk validation, and field trial feedback.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Explore the Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/keylorpineda/healthycropping" rel="noopener noreferrer"&gt;https://github.com/keylorpineda/healthycropping&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Architecture Overview:&lt;/strong&gt; &lt;a href="https://github.com/keylorpineda/healthycropping/blob/develop/docs/ARCHITECTURE.md" rel="noopener noreferrer"&gt;https://github.com/keylorpineda/healthycropping/blob/develop/docs/ARCHITECTURE.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation Roadmap:&lt;/strong&gt; &lt;a href="https://github.com/keylorpineda/healthycropping/blob/develop/docs/PLAN.md" rel="noopener noreferrer"&gt;https://github.com/keylorpineda/healthycropping/blob/develop/docs/PLAN.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contributing Guidelines:&lt;/strong&gt; &lt;a href="https://github.com/keylorpineda/healthycropping/blob/develop/CONTRIBUTING.md" rel="noopener noreferrer"&gt;https://github.com/keylorpineda/healthycropping/blob/develop/CONTRIBUTING.md&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feedback, issues, and discussions are welcome.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
