Instructions to use devwinner/ocdf-cassava with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use devwinner/ocdf-cassava 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 +131 -0
- SHA256SUMS +6 -0
- cassava_EfficientNetB0_s42_fp16.tflite +3 -0
- comparison/cassava_EfficientNetB0_s42_int8.tflite +3 -0
- comparison/cassava_shift_EfficientNetB0_fp16.tflite +3 -0
- comparison/cassava_shift_EfficientNetB0_int8_k0.tflite +3 -0
- comparison/cassava_shift_MobileNetV2_int8.tflite +3 -0
- config.json +40 -0
README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
pipeline_tag: image-classification
|
| 4 |
+
tags:
|
| 5 |
+
- tflite
|
| 6 |
+
- litert
|
| 7 |
+
- on-device
|
| 8 |
+
- offline
|
| 9 |
+
- plant-disease
|
| 10 |
+
- cassava
|
| 11 |
+
- agriculture
|
| 12 |
+
- efficientnet
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# OCDF cassava leaf-disease classifier (LiteRT)
|
| 16 |
+
|
| 17 |
+
A compact EfficientNet-B0 classifier for cassava leaf diseases (cassava bacterial blight, cassava mosaic disease, 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-maize](https://huggingface.co/devwinner/ocdf-maize)
|
| 24 |
+
|
| 25 |
+
## Licence
|
| 26 |
+
|
| 27 |
+
**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.
|
| 28 |
+
|
| 29 |
+
## Files
|
| 30 |
+
|
| 31 |
+
| File | Release | Role |
|
| 32 |
+
|---|---|---|
|
| 33 |
+
| `cassava_EfficientNetB0_s42_fp16.tflite` | Phase 1 FP16, 7.8 MiB | **deployed model: use this** |
|
| 34 |
+
| `comparison/cassava_EfficientNetB0_s42_int8.tflite` | Phase 1 full INT8 | failed the pre-declared accuracy budget |
|
| 35 |
+
| `comparison/cassava_shift_EfficientNetB0_fp16.tflite` | Phase 2 shift-augmented FP16 | frozen before the sealed test |
|
| 36 |
+
| `comparison/cassava_shift_EfficientNetB0_int8_k0.tflite` | Phase 2 shift-augmented full INT8 | comparison |
|
| 37 |
+
| `comparison/cassava_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 C01, C02, C03 |
|
| 50 |
+
| Classes | C01 Cassava bacterial blight · C02 Cassava mosaic disease · C03 Healthy cassava |
|
| 51 |
+
| Post-processing | `p = softmax(logits / 1.0873)`; abstain if `max(p) < 0.85` |
|
| 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-cassava"
|
| 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 Ugandan cassava leaves from the Kaggle Cassava Leaf Disease Classification data (16,820 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.728 [0.697, 0.757] |
|
| 96 |
+
| Ghana CCMT macro-F1 (new source) | 0.559 [0.534, 0.587] |
|
| 97 |
+
| Expected calibration error, internal → CCMT | 0.02 → 0.21 |
|
| 98 |
+
| Latency, 1 CPU thread: Galaxy S24 / Pixel 3 / laptop | 19.8 / 85.8 / 6.2 ms |
|
| 99 |
+
|
| 100 |
+
All results, and the per-image predictions behind them:
|
| 101 |
+
[docs/RESULTS.md](https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/docs/RESULTS.md).
|
| 102 |
+
|
| 103 |
+
## Limitations
|
| 104 |
+
|
| 105 |
+
- **Accuracy drops on images from new sources**, and the model's confidence does not signal it.
|
| 106 |
+
- On Ghanaian cassava, most missed blight leaves were called healthy, the costliest error for a grower.
|
| 107 |
+
- Abstention does not detect unfamiliar inputs: other diseases, pests and other crops are often accepted with high confidence (AUROC 0.52).
|
| 108 |
+
- **Background shortcut:** in one test source, healthy leaves were mostly photographed on paper. Photograph leaves where they grow.
|
| 109 |
+
- **No Nigerian or other West African farm images with expert labels** were available for training or testing.
|
| 110 |
+
|
| 111 |
+
Intended for research on offline plant-disease classification. It is not a diagnostic or
|
| 112 |
+
advisory service and has not been validated for any farm or region. Before use in a new
|
| 113 |
+
region, evaluate on a small set of expert-labelled local images and fine-tune on them; in
|
| 114 |
+
this study, tens of labelled images per class recovered most of the cross-source loss.
|
| 115 |
+
|
| 116 |
+
## Citation
|
| 117 |
+
|
| 118 |
+
```bibtex
|
| 119 |
+
@software{anietie_2026_ocdf,
|
| 120 |
+
author = {Anietie, Aniekan Winner},
|
| 121 |
+
title = {{OCDF}: offline cassava and maize leaf-disease classifiers with a
|
| 122 |
+
pre-registered cross-source evaluation},
|
| 123 |
+
year = {2026},
|
| 124 |
+
version = {1.0.0},
|
| 125 |
+
doi = {10.5281/zenodo.24546864},
|
| 126 |
+
url = {https://doi.org/10.5281/zenodo.24546864}
|
| 127 |
+
}
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
To cite whichever version is latest, use the concept DOI
|
| 131 |
+
[10.5281/zenodo.24546863](https://doi.org/10.5281/zenodo.24546863).
|
SHA256SUMS
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
c8a9ae66b0a219af132aca8b297df9224f27ded858768e4e6377dde08f8d9bad cassava_EfficientNetB0_s42_fp16.tflite
|
| 2 |
+
8dd5eab0feb47c0004d6e090ace5f6d351243ddfa06f3c55169c8223da46e722 comparison/cassava_EfficientNetB0_s42_int8.tflite
|
| 3 |
+
f6aba7501107b8effa4aea21cb6de2bad25ba52b46027f45266de97e20267146 comparison/cassava_shift_EfficientNetB0_fp16.tflite
|
| 4 |
+
52d118e7f4f1a58c080c11a158b4f23959f16bd295a0fb4b861d7db8ad0d8501 comparison/cassava_shift_EfficientNetB0_int8_k0.tflite
|
| 5 |
+
1b193f9f4fff9e44ec6a5d42f433e228d1c4c899cacd714ceb03b1caaae724f6 comparison/cassava_shift_MobileNetV2_int8.tflite
|
| 6 |
+
bbd6a8385b58d895ddbc78a960d3b000c2a5d74a6370cb22d7837a4a452adf28 config.json
|
cassava_EfficientNetB0_s42_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c8a9ae66b0a219af132aca8b297df9224f27ded858768e4e6377dde08f8d9bad
|
| 3 |
+
size 8151428
|
comparison/cassava_EfficientNetB0_s42_int8.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8dd5eab0feb47c0004d6e090ace5f6d351243ddfa06f3c55169c8223da46e722
|
| 3 |
+
size 4946608
|
comparison/cassava_shift_EfficientNetB0_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f6aba7501107b8effa4aea21cb6de2bad25ba52b46027f45266de97e20267146
|
| 3 |
+
size 8156640
|
comparison/cassava_shift_EfficientNetB0_int8_k0.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52d118e7f4f1a58c080c11a158b4f23959f16bd295a0fb4b861d7db8ad0d8501
|
| 3 |
+
size 4950664
|
comparison/cassava_shift_MobileNetV2_int8.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1b193f9f4fff9e44ec6a5d42f433e228d1c4c899cacd714ceb03b1caaae724f6
|
| 3 |
+
size 2743376
|
config.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model": "cassava_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 |
+
"C01",
|
| 24 |
+
"C02",
|
| 25 |
+
"C03"
|
| 26 |
+
],
|
| 27 |
+
"label_names": {
|
| 28 |
+
"C01": "Cassava bacterial blight",
|
| 29 |
+
"C02": "Cassava mosaic disease",
|
| 30 |
+
"C03": "Healthy cassava"
|
| 31 |
+
},
|
| 32 |
+
"temperature_T": 1.0873,
|
| 33 |
+
"abstain_if_max_probability_below": 0.85,
|
| 34 |
+
"postprocessing": "p = softmax(logits / temperature_T); abstain if max(p) < threshold",
|
| 35 |
+
"sha256": "c8a9ae66b0a219af132aca8b297df9224f27ded858768e4e6377dde08f8d9bad",
|
| 36 |
+
"frozen_record": "https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/protocol/frozen_choices_v2.json",
|
| 37 |
+
"phase2_settings": "https://github.com/DevaWinner/ocdf-cassava-maize/blob/v1.0.0/protocol/frozen_choices_v3.json",
|
| 38 |
+
"doi": "10.5281/zenodo.24546864",
|
| 39 |
+
"license": "cc-by-nc-4.0"
|
| 40 |
+
}
|