Instructions to use devwinner/ocdf-maize with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use devwinner/ocdf-maize with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
OCDF 1.0.0 (doi:10.5281/zenodo.24546864)
Browse files- README.md +132 -0
- SHA256SUMS +6 -0
- comparison/maize_EfficientNetB0_s42_int8.tflite +3 -0
- comparison/maize_shift_EfficientNetB0_fp16.tflite +3 -0
- comparison/maize_shift_EfficientNetB0_int8_k0.tflite +3 -0
- comparison/maize_shift_MobileNetV2_int8.tflite +3 -0
- config.json +44 -0
- maize_EfficientNetB0_s42_fp16.tflite +3 -0
README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
pipeline_tag: image-classification
|
| 4 |
+
tags:
|
| 5 |
+
- tflite
|
| 6 |
+
- litert
|
| 7 |
+
- on-device
|
| 8 |
+
- offline
|
| 9 |
+
- plant-disease
|
| 10 |
+
- maize
|
| 11 |
+
- agriculture
|
| 12 |
+
- efficientnet
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# OCDF maize leaf-disease classifier (LiteRT)
|
| 16 |
+
|
| 17 |
+
A compact EfficientNet-B0 classifier for maize leaf diseases (maize streak virus, northern leaf blight, grey leaf spot, common rust, healthy), converted to
|
| 18 |
+
LiteRT (TensorFlow Lite) to run **offline on a phone**. It is part of OCDF, released with a
|
| 19 |
+
pre-registered evaluation of how the models transfer across African image sources.
|
| 20 |
+
|
| 21 |
+
- **Code, records and full documentation:** [github.com/DevaWinner/ocdf-cassava-maize](https://github.com/DevaWinner/ocdf-cassava-maize)
|
| 22 |
+
- **Archived release (cite this):** [doi:10.5281/zenodo.24546864](https://doi.org/10.5281/zenodo.24546864)
|
| 23 |
+
- **Companion model:** [devwinner/ocdf-cassava](https://huggingface.co/devwinner/ocdf-cassava)
|
| 24 |
+
|
| 25 |
+
## Licence
|
| 26 |
+
|
| 27 |
+
**CC BY 4.0.** Free to use, including commercially, with attribution (cite the DOI below).
|
| 28 |
+
|
| 29 |
+
## Files
|
| 30 |
+
|
| 31 |
+
| File | Release | Role |
|
| 32 |
+
|---|---|---|
|
| 33 |
+
| `maize_EfficientNetB0_s42_fp16.tflite` | Phase 1 FP16, 7.8 MiB | **deployed model: use this** |
|
| 34 |
+
| `comparison/maize_EfficientNetB0_s42_int8.tflite` | Phase 1 full INT8 | failed the pre-declared accuracy budget |
|
| 35 |
+
| `comparison/maize_shift_EfficientNetB0_fp16.tflite` | Phase 2 shift-augmented FP16 | frozen before the sealed test |
|
| 36 |
+
| `comparison/maize_shift_EfficientNetB0_int8_k0.tflite` | Phase 2 shift-augmented full INT8 | comparison |
|
| 37 |
+
| `comparison/maize_shift_MobileNetV2_int8.tflite` | Phase 2 MobileNetV2 full INT8 | smallest comparator |
|
| 38 |
+
|
| 39 |
+
`config.json` holds the class order, temperature and abstention threshold for the deployed
|
| 40 |
+
model. Settings for the Phase 2 files are in the
|
| 41 |
+
[Phase 2 freeze record](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/protocol/frozen_choices_v3.json). `SHA256SUMS` lists
|
| 42 |
+
every file's hash; they match the frozen records in the GitHub repository.
|
| 43 |
+
|
| 44 |
+
## How to use
|
| 45 |
+
|
| 46 |
+
| | |
|
| 47 |
+
|---|---|
|
| 48 |
+
| Input | float32 `[1, 224, 224, 3]`, RGB, values 0–255, aspect-preserving bilinear resize with centred zero padding (`tf.image.resize_with_pad`) |
|
| 49 |
+
| Output | logits in the order M01, M02, M03, M04, M05 |
|
| 50 |
+
| Classes | M01 Maize streak virus · M02 Northern leaf blight · M03 Grey leaf spot · M04 Common rust · M05 Healthy maize |
|
| 51 |
+
| Post-processing | `p = softmax(logits / 0.8557)`; abstain if `max(p) < 0.5` |
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
import json, numpy as np
|
| 55 |
+
from huggingface_hub import hf_hub_download
|
| 56 |
+
from ai_edge_litert.interpreter import Interpreter # pip install ai-edge-litert
|
| 57 |
+
import tensorflow as tf # only for the exact resize
|
| 58 |
+
|
| 59 |
+
repo = "devwinner/ocdf-maize"
|
| 60 |
+
cfg = json.load(open(hf_hub_download(repo, "config.json")))
|
| 61 |
+
it = Interpreter(model_path=hf_hub_download(repo, cfg["model"]))
|
| 62 |
+
it.allocate_tensors()
|
| 63 |
+
|
| 64 |
+
img = tf.io.decode_image(tf.io.read_file("leaf.jpg"), channels=3, expand_animations=False)
|
| 65 |
+
x = tf.image.resize_with_pad(tf.cast(img, tf.float32), 224, 224)[None].numpy()
|
| 66 |
+
it.set_tensor(it.get_input_details()[0]["index"], x)
|
| 67 |
+
it.invoke()
|
| 68 |
+
logits = it.get_tensor(it.get_output_details()[0]["index"])[0]
|
| 69 |
+
|
| 70 |
+
p = np.exp(logits / cfg["temperature_T"]); p /= p.sum()
|
| 71 |
+
label = cfg["labels_in_output_order"][int(p.argmax())]
|
| 72 |
+
if p.max() < cfg["abstain_if_max_probability_below"]:
|
| 73 |
+
print("abstain: retake the photo or ask an expert")
|
| 74 |
+
else:
|
| 75 |
+
print(cfg["label_names"][label], round(float(p.max()), 3))
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
A NumPy-only version of the preprocessing (no TensorFlow) is in
|
| 79 |
+
[`src/ocdf/inference.py`](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/src/ocdf/inference.py), and
|
| 80 |
+
[`scripts/predict.py`](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/scripts/predict.py) wraps it as a command-line tool.
|
| 81 |
+
|
| 82 |
+
## Training
|
| 83 |
+
|
| 84 |
+
EfficientNet-B0 pretrained on ImageNet and fine-tuned on Tanzanian maize field images and PlantVillage maize images, both CC0 (15,219 images after grouping and exclusions). Near-duplicate
|
| 85 |
+
images were grouped so no group crosses a split. The architecture was chosen over MobileNetV2
|
| 86 |
+
and MobileNetV3-Small by a pre-declared rule, with seed 42 named in advance. Methods:
|
| 87 |
+
[docs/METHODS.md](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/docs/METHODS.md).
|
| 88 |
+
|
| 89 |
+
## Performance (deployed file)
|
| 90 |
+
|
| 91 |
+
Macro-F1 with 95% bootstrap intervals.
|
| 92 |
+
|
| 93 |
+
| | |
|
| 94 |
+
|---|---|
|
| 95 |
+
| Internal test macro-F1 | 0.956 [0.935, 0.975] |
|
| 96 |
+
| Ghana CCMT macro-F1 (new source) | 0.809 [0.782, 0.832] |
|
| 97 |
+
| Ghana KaraAgro sealed test macro-F1 | 0.690 [0.673, 0.707] |
|
| 98 |
+
| Expected calibration error, internal → CCMT | 0.003 → 0.08 |
|
| 99 |
+
| Latency, 1 CPU thread: Galaxy S24 / Pixel 3 / laptop | 19.8 / 85.8 / 6.2 ms |
|
| 100 |
+
|
| 101 |
+
All results, and the per-image predictions behind them:
|
| 102 |
+
[docs/RESULTS.md](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/docs/RESULTS.md).
|
| 103 |
+
|
| 104 |
+
## Limitations
|
| 105 |
+
|
| 106 |
+
- **Accuracy drops on images from new sources**, and the model's confidence does not signal it.
|
| 107 |
+
- Source–class confounding: streak virus comes from one development source, and blight, leaf spot and rust only from PlantVillage laboratory images.
|
| 108 |
+
- Abstention does not reliably detect unfamiliar inputs such as other diseases, pests or other crops.
|
| 109 |
+
- **Background shortcut:** in one test source, healthy leaves were mostly photographed on paper. Photograph leaves where they grow.
|
| 110 |
+
- **No Nigerian or other West African farm images with expert labels** were available for training or testing.
|
| 111 |
+
|
| 112 |
+
Intended for research on offline plant-disease classification. It is not a diagnostic or
|
| 113 |
+
advisory service and has not been validated for any farm or region. Before use in a new
|
| 114 |
+
region, evaluate on a small set of expert-labelled local images and fine-tune on them; in
|
| 115 |
+
this study, tens of labelled images per class recovered most of the cross-source loss.
|
| 116 |
+
|
| 117 |
+
## Citation
|
| 118 |
+
|
| 119 |
+
```bibtex
|
| 120 |
+
@software{anietie_2026_ocdf,
|
| 121 |
+
author = {Anietie, Aniekan Winner},
|
| 122 |
+
title = {{OCDF}: offline cassava and maize leaf-disease classifiers with a
|
| 123 |
+
pre-registered cross-source evaluation},
|
| 124 |
+
year = {2026},
|
| 125 |
+
version = {1.0.0},
|
| 126 |
+
doi = {10.5281/zenodo.24546864},
|
| 127 |
+
url = {https://doi.org/10.5281/zenodo.24546864}
|
| 128 |
+
}
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
To cite whichever version is latest, use the concept DOI
|
| 132 |
+
[10.5281/zenodo.24546863](https://doi.org/10.5281/zenodo.24546863).
|
SHA256SUMS
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0af5fd20e0578a128ea80b8eb4962c3292b27eb9a6d0b01ec5a899ca24bdfd07 comparison/maize_EfficientNetB0_s42_int8.tflite
|
| 2 |
+
63c743cd5668485a831eef95ec3912d6e3c8fba54cf59158ce01aa4b6d6763c5 comparison/maize_shift_EfficientNetB0_fp16.tflite
|
| 3 |
+
8efbdd1ec955eedf96651b8d5479540a1e365b36a58f6012393f56d404b4bbe5 comparison/maize_shift_EfficientNetB0_int8_k0.tflite
|
| 4 |
+
3f217dddd11859f7a2286f3f8159c806d250d789cd1916f5d1742dbb74651bad comparison/maize_shift_MobileNetV2_int8.tflite
|
| 5 |
+
e7967eefcd41e04e706c936fd5102f68d08189f88b6b55fe0c6f5da23e9e76a5 config.json
|
| 6 |
+
fede5d9054c259d95c6785c9edb4822f28b09945d2b3128a4f333c7edcfb3c70 maize_EfficientNetB0_s42_fp16.tflite
|
comparison/maize_EfficientNetB0_s42_int8.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0af5fd20e0578a128ea80b8eb4962c3292b27eb9a6d0b01ec5a899ca24bdfd07
|
| 3 |
+
size 4949224
|
comparison/maize_shift_EfficientNetB0_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63c743cd5668485a831eef95ec3912d6e3c8fba54cf59158ce01aa4b6d6763c5
|
| 3 |
+
size 8161764
|
comparison/maize_shift_EfficientNetB0_int8_k0.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8efbdd1ec955eedf96651b8d5479540a1e365b36a58f6012393f56d404b4bbe5
|
| 3 |
+
size 4953280
|
comparison/maize_shift_MobileNetV2_int8.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3f217dddd11859f7a2286f3f8159c806d250d789cd1916f5d1742dbb74651bad
|
| 3 |
+
size 2745992
|
config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model": "maize_EfficientNetB0_s42_fp16.tflite",
|
| 3 |
+
"architecture": "EfficientNet-B0",
|
| 4 |
+
"format": "LiteRT FP16",
|
| 5 |
+
"release": "Phase 1 (deployed)",
|
| 6 |
+
"input": {
|
| 7 |
+
"shape": [
|
| 8 |
+
1,
|
| 9 |
+
224,
|
| 10 |
+
224,
|
| 11 |
+
3
|
| 12 |
+
],
|
| 13 |
+
"dtype": "float32",
|
| 14 |
+
"colour": "RGB",
|
| 15 |
+
"range": [
|
| 16 |
+
0,
|
| 17 |
+
255
|
| 18 |
+
],
|
| 19 |
+
"resize": "tf.image.resize_with_pad(img, 224, 224, method='bilinear')"
|
| 20 |
+
},
|
| 21 |
+
"output": "logits",
|
| 22 |
+
"labels_in_output_order": [
|
| 23 |
+
"M01",
|
| 24 |
+
"M02",
|
| 25 |
+
"M03",
|
| 26 |
+
"M04",
|
| 27 |
+
"M05"
|
| 28 |
+
],
|
| 29 |
+
"label_names": {
|
| 30 |
+
"M01": "Maize streak virus",
|
| 31 |
+
"M02": "Northern leaf blight",
|
| 32 |
+
"M03": "Grey leaf spot",
|
| 33 |
+
"M04": "Common rust",
|
| 34 |
+
"M05": "Healthy maize"
|
| 35 |
+
},
|
| 36 |
+
"temperature_T": 0.8557,
|
| 37 |
+
"abstain_if_max_probability_below": 0.5,
|
| 38 |
+
"postprocessing": "p = softmax(logits / temperature_T); abstain if max(p) < threshold",
|
| 39 |
+
"sha256": "fede5d9054c259d95c6785c9edb4822f28b09945d2b3128a4f333c7edcfb3c70",
|
| 40 |
+
"frozen_record": "https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/protocol/frozen_choices_v2.json",
|
| 41 |
+
"phase2_settings": "https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/protocol/frozen_choices_v3.json",
|
| 42 |
+
"doi": "10.5281/zenodo.24546864",
|
| 43 |
+
"license": "cc-by-4.0"
|
| 44 |
+
}
|
maize_EfficientNetB0_s42_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fede5d9054c259d95c6785c9edb4822f28b09945d2b3128a4f333c7edcfb3c70
|
| 3 |
+
size 8156552
|