Coffee Leaf Nutrient-Deficiency Classification with OFA-Tiny
This repository contains a fine-tuned OFA-Tiny checkpoint for classifying coffee-leaf images into nine dataset labels.
Research prototype: This model is not validated for agronomic diagnosis. Predictions should not be used as the sole basis for fertilizer, pesticide, or crop-management decisions.
Model
The project fine-tunes OFA (One For All), a sequence-to-sequence vision-language model, for image classification. The OFA-Tiny family uses a ResNet-50 visual backbone and a Transformer encoder-decoder (33M parameters in the original released configuration). The classifier generates a text label for an image, using the prompt What does the image describe? and constrained label decoding in the training/evaluation pipeline.
Original OFA implementation: https://github.com/OFA-Sys/OFA
Paper: https://arxiv.org/abs/2202.03052
Labels
- boron deficiency
- calcium deficiency
- healthy
- iron deficiency
- magnesium deficiency
- manganese deficiency
- nitrogen deficiency
- phosphorus deficiency
- potassium deficiency
The exact label mapping and constrained decoding must match the training run. Keep the original ans2label.pkl from the training workspace; do not recreate its numeric ordering by hand.
Checkpoint
The fine-tuned checkpoint is named checkpoint_best.pt and is hosted in this private Hugging Face repository. It is approximately 469 MB.
Training setup and reported evaluation
- Base model: OFA-Tiny, initialized from the official pretrained OFA-Tiny checkpoint.
- Fine-tuning environment: Google Colab, NVIDIA Tesla T4.
- Training: 30 epochs; learning rate
1e-4; training set included 36 augmented variants of healthy leaves in addition to the original training examples. - Validation set size: 163 images.
- Validation accuracy: 0.706.
- Validation macro-F1 across nine classes: 0.645.
- Validation macro-F1 excluding the healthy class: 0.663.
These are results from the reported validation run, not a guarantee of performance on new farms, cultivars, cameras, lighting conditions, or field conditions. Do not present the previously observed test result as an unbiased final estimate if test examples were used to guide model changes.
Important limitations
- The validation split contains only one healthy example. Healthy-class metrics are highly unstable and cannot establish reliable healthy-leaf performance.
- The healthy class was augmented from only six collected original images. Augmentation does not replace collecting independent examples across plants, farms, seasons, and capture conditions.
- Nutrient symptoms can overlap with disease, pests, water stress, soil pH issues, leaf age, and environmental stress. Image-only predictions cannot confirm the underlying cause.
- Severity labels in the dataset were randomly assigned and are not expert-validated ground truth. This project does not predict validated severity.
- A prediction is a model output, not a calibrated probability or an agricultural recommendation unless separately validated.
Inference and demo
The app.py interface is a lightweight Gradio front end. The OFA inference adapter depends on the exact OFA/Fairseq task configuration and decoding settings used during fine-tuning. These must be carried over from the original training workspace before deployment. See DEPLOYMENT.md.
License
Review the original OFA license, checkpoint terms, and dataset permissions before distributing this checkpoint or making the demo public. This README does not grant additional rights to model weights or images.