--- license: mit library_name: ultralytics pipeline_tag: image-classification tags: - agriculture - bangladesh - crop-disease - tflite - yolo26 - on-device - rice - chashibhai language: - bn - en base_model_relation: quantized --- # ChashiBhAI Rice Disease Classifier | | | |---|---| | **Author** | [Shaq2](https://huggingface.co/Shaq2) (Shakil Ahmed) | | **Crop** | rice (ধান) | | **Task** | Image classification (leaf disease) | | **Architecture** | YOLO26-cls → TFLite FP16 | | **Input** | `[1, 640, 640, 3]` NHWC RGB `/255.0` | | **Output** | `[1, 8]` softmax probabilities (`nms: false`) | | **Status** | `production-demo` | | **App** | ChashiBhAI (Expo / React Native, on-device diagnosis) | | **Code** | [GitHub](https://github.com/MRSHAKILS/AI-Powered-Smart-Agriculture-Advisory-Platform-for-Bangladesh) | | **Collection** | [ChashiBhAI on-device classifiers](https://huggingface.co/collections/Shaq2/chashibhai-on-device-disease-classifiers) | Disease ID in ChashiBhAI **always** runs on-device. Gemini / KrishokChat generate advisory **text only** and never see the photo. ## Files | File | Role | |---|---| | `model.tflite` | On-device graph used by the Android app (~3.12 MB) | | `labels.json` | Canonical class names **and** preprocess contract | | `best.pt` | Ultralytics source weights (export parent) | ## Classes (8) | Label | English | Bangla | |---|---|---| | `Rice__Bacterial_Leaf_Blight` | Bacterial Leaf Blight | ব্যাকটেরিয়াজনিত পাতা পোড়া | | `Rice__Brown_Spot` | Brown Spot | বাদামী দাগ | | `Rice__Healthy_Leaf` | Healthy Leaf | সুস্থ পাতা | | `Rice__Leaf_Blast` | Leaf Blast | ব্লাস্ট | | `Rice__Leaf_Scald` | Leaf Scald | পাতা পোড়া | | `Rice__Narrow_Brown_Leaf_Spot` | Narrow Brown Leaf Spot | সরু বাদামী দাগ | | `Rice__Rice_Hispa` | Rice Hispa | হিসপা | | `Rice__Sheath_Blight` | Sheath Blight | শেথ ব্লাইট | ## Preprocessing (variant C) — required Do **not** letterbox. Letterbox disagreed with the `.pt` on non-square photos. 1. Resize the **shortest side** to `imgsz` = **640**, keep aspect ratio. 2. **Centre-crop** to `640×640`. 3. RGB, NHWC, `float32 / 255.0`. `labels.json` is the source of truth (`preprocess: centercrop`). ## Measured export checks | Check | Result | |---|---| | Preprocess verified vs `.pt` | yes (variant C, 100% top-1 vs `.pt` on the rice hold-out used for export) | | FP16 vs FP32 top-1 agreement | 1.0 | | FP16 vs FP32 max softmax diff | 0.000372171 | | Independent machine test | pass (August 2026) | | Bundled in APK | yes (rice) | ## Validation Independent test on a **separate machine** (August 2026) confirmed this TFLite export loads and classifies correctly with the variant-C contract in `labels.json`. Rice, brassica, and corn all passed the same check. ## Intended use - On-device diagnosis in ChashiBhAI for Bangladeshi farmers (Bangla-first UI). - Research reproduction of the mobile export. **Out of scope:** detection / bounding boxes, crop auto-routing, chemical dosage (handled by a separate advisory stack with a refuse gate). ## Limitations Demo-grade on-device classifier. Not a plant-pathologist substitute. Retake if confidence is low or the leaf is not centred. ## Load (Python) ```python import json from pathlib import Path import numpy as np from PIL import Image import tensorflow as tf def preprocess_centercrop(path: str, imgsz: int = 640) -> np.ndarray: im = Image.open(path).convert("RGB") w, h = im.size scale = imgsz / min(w, h) nw, nh = int(round(w * scale)), int(round(h * scale)) im = im.resize((nw, nh), Image.BILINEAR) left, top = (nw - imgsz) // 2, (nh - imgsz) // 2 im = im.crop((left, top, left + imgsz, top + imgsz)) return (np.asarray(im, dtype=np.float32) / 255.0)[None, ...] labels = json.loads(Path("labels.json").read_text(encoding="utf-8")) it = tf.lite.Interpreter(model_path="model.tflite") it.allocate_tensors() inp, out = it.get_input_details()[0], it.get_output_details()[0] it.set_tensor(inp["index"], preprocess_centercrop("leaf.jpg", labels["imgsz"])) it.invoke() p = it.get_tensor(out["index"])[0] i = int(p.argmax()) print(labels["names"][i], float(p[i])) ``` ## Related models (same author) - [Rice](https://huggingface.co/Shaq2/chashibhai-rice-disease-cls) - [Brassica](https://huggingface.co/Shaq2/chashibhai-brassica-disease-cls) - [Corn](https://huggingface.co/Shaq2/chashibhai-corn-disease-cls) - Suite index: [chashibhai-disease-classifiers](https://huggingface.co/Shaq2/chashibhai-disease-classifiers) ## Credit (not this model) KrishokChat Bengali advisory LLM / RAG is **not** this classifier. See [RaiyanKhaan/KrishokChat-Advisory-System](https://huggingface.co/RaiyanKhaan/KrishokChat-Advisory-System) and arXiv:2606.29243 (Reza & Shahid). ## Citation ```bibtex @software{ahmed2026chashibhai_rice_cls, author = {Ahmed, Shakil}, title = {ChashiBhAI Rice Disease Classifier}, year = {2026}, url = {https://huggingface.co/Shaq2/chashibhai-rice-disease-cls} } ``` ## License MIT (see `LICENSE`). Ultralytics remains under its own license. This pack redistributes **weights**, not training images.