ocdf-cassava / README.md
devwinner's picture
OCDF 1.0.0 (doi:10.5281/zenodo.24546864)
efd7f05 verified
|
Raw History Blame Contribute Delete
6.35 kB
---
license: cc-by-nc-4.0
pipeline_tag: image-classification
tags:
- tflite
- litert
- on-device
- offline
- plant-disease
- cassava
- agriculture
- efficientnet
---
# OCDF cassava leaf-disease classifier (LiteRT)
A compact EfficientNet-B0 classifier for cassava leaf diseases (cassava bacterial blight, cassava mosaic disease, healthy), converted to
LiteRT (TensorFlow Lite) to run **offline on a phone**. It is part of OCDF, released with a
pre-registered evaluation of how the models transfer across African image sources.
- **Code, records and full documentation:** [github.com/DevaWinner/ocdf-cassava-maize](https://github.com/DevaWinner/ocdf-cassava-maize)
- **Archived release (cite this):** [doi:10.5281/zenodo.24546864](https://doi.org/10.5281/zenodo.24546864)
- **Companion model:** [devwinner/ocdf-maize](https://huggingface.co/devwinner/ocdf-maize)
## Licence
**Non-commercial use only (CC BY-NC 4.0).** These models were trained on the Kaggle Cassava Leaf Disease Classification data, whose competition rules allow non-commercial use only (participation, academic research and education). Use them for non-commercial research and education. The companion maize models carry no such restriction.
## Files
| File | Release | Role |
|---|---|---|
| `cassava_EfficientNetB0_s42_fp16.tflite` | Phase 1 FP16, 7.8 MiB | **deployed model: use this** |
| `comparison/cassava_EfficientNetB0_s42_int8.tflite` | Phase 1 full INT8 | failed the pre-declared accuracy budget |
| `comparison/cassava_shift_EfficientNetB0_fp16.tflite` | Phase 2 shift-augmented FP16 | frozen before the sealed test |
| `comparison/cassava_shift_EfficientNetB0_int8_k0.tflite` | Phase 2 shift-augmented full INT8 | comparison |
| `comparison/cassava_shift_MobileNetV2_int8.tflite` | Phase 2 MobileNetV2 full INT8 | smallest comparator |
`config.json` holds the class order, temperature and abstention threshold for the deployed
model. Settings for the Phase 2 files are in the
[Phase 2 freeze record](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/protocol/frozen_choices_v3.json). `SHA256SUMS` lists
every file's hash; they match the frozen records in the GitHub repository.
## How to use
| | |
|---|---|
| Input | float32 `[1, 224, 224, 3]`, RGB, values 0–255, aspect-preserving bilinear resize with centred zero padding (`tf.image.resize_with_pad`) |
| Output | logits in the order C01, C02, C03 |
| Classes | C01 Cassava bacterial blight · C02 Cassava mosaic disease · C03 Healthy cassava |
| Post-processing | `p = softmax(logits / 1.0873)`; abstain if `max(p) < 0.85` |
```python
import json, numpy as np
from huggingface_hub import hf_hub_download
from ai_edge_litert.interpreter import Interpreter # pip install ai-edge-litert
import tensorflow as tf # only for the exact resize
repo = "devwinner/ocdf-cassava"
cfg = json.load(open(hf_hub_download(repo, "config.json")))
it = Interpreter(model_path=hf_hub_download(repo, cfg["model"]))
it.allocate_tensors()
img = tf.io.decode_image(tf.io.read_file("leaf.jpg"), channels=3, expand_animations=False)
x = tf.image.resize_with_pad(tf.cast(img, tf.float32), 224, 224)[None].numpy()
it.set_tensor(it.get_input_details()[0]["index"], x)
it.invoke()
logits = it.get_tensor(it.get_output_details()[0]["index"])[0]
p = np.exp(logits / cfg["temperature_T"]); p /= p.sum()
label = cfg["labels_in_output_order"][int(p.argmax())]
if p.max() < cfg["abstain_if_max_probability_below"]:
print("abstain: retake the photo or ask an expert")
else:
print(cfg["label_names"][label], round(float(p.max()), 3))
```
A NumPy-only version of the preprocessing (no TensorFlow) is in
[`src/ocdf/inference.py`](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/src/ocdf/inference.py), and
[`scripts/predict.py`](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/scripts/predict.py) wraps it as a command-line tool.
## Training
EfficientNet-B0 pretrained on ImageNet and fine-tuned on Ugandan cassava leaves from the Kaggle Cassava Leaf Disease Classification data (16,820 images after grouping and exclusions). Near-duplicate
images were grouped so no group crosses a split. The architecture was chosen over MobileNetV2
and MobileNetV3-Small by a pre-declared rule, with seed 42 named in advance. Methods:
[docs/METHODS.md](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/docs/METHODS.md).
## Performance (deployed file)
Macro-F1 with 95% bootstrap intervals.
| | |
|---|---|
| Internal test macro-F1 | 0.728 [0.697, 0.757] |
| Ghana CCMT macro-F1 (new source) | 0.559 [0.534, 0.587] |
| Expected calibration error, internal → CCMT | 0.02 → 0.21 |
| Latency, 1 CPU thread: Galaxy S24 / Pixel 3 / laptop | 19.8 / 85.8 / 6.2 ms |
All results, and the per-image predictions behind them:
[docs/RESULTS.md](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/docs/RESULTS.md).
## Limitations
- **Accuracy drops on images from new sources**, and the model's confidence does not signal it.
- On Ghanaian cassava, most missed blight leaves were called healthy, the costliest error for a grower.
- Abstention does not detect unfamiliar inputs: other diseases, pests and other crops are often accepted with high confidence (AUROC 0.52).
- **Background shortcut:** in one test source, healthy leaves were mostly photographed on paper. Photograph leaves where they grow.
- **No Nigerian or other West African farm images with expert labels** were available for training or testing.
Intended for research on offline plant-disease classification. It is not a diagnostic or
advisory service and has not been validated for any farm or region. Before use in a new
region, evaluate on a small set of expert-labelled local images and fine-tune on them; in
this study, tens of labelled images per class recovered most of the cross-source loss.
## Citation
```bibtex
@software{anietie_2026_ocdf,
author = {Anietie, Aniekan Winner},
title = {{OCDF}: offline cassava and maize leaf-disease classifiers with a
pre-registered cross-source evaluation},
year = {2026},
version = {1.0.0},
doi = {10.5281/zenodo.24546864},
url = {https://doi.org/10.5281/zenodo.24546864}
}
```
To cite whichever version is latest, use the concept DOI
[10.5281/zenodo.24546863](https://doi.org/10.5281/zenodo.24546863).