research

All research

Cucumber

Cucumber disease classification with EfficientNet-B5

Type
Training notebook
Task
Image classification, 7 classes
Model
EfficientNet-B5
Built with
TensorFlow and Keras, on Google Colab

Read it

Prefer the files? Download the EfficientNet-B5 notebook (3.9 MB).

Two confusion matrices for the 1,235 test images across seven classes, one with counts and one as shares of each class. Almost every image is on the diagonal. The weakest classes are anthracnose, 41 of 48 correct, and gummy stem blight, 22 of 24.
From the notebook: what the model predicted for each test image, against the true class, as counts and as shares.

What the notebook does

This notebook trains an image classifier that sorts photos of cucumber plants into seven classes: five diseases (anthracnose, bacterial wilt, downy mildew, gummy stem blight and powdery mildew), plus fresh cucumber and fresh leaf.

There are 8,223 images, split class by class into 5,755 for training, 1,233 for validation and 1,235 for testing (70, 15 and 15 percent). The classes are uneven, from 160 images to 3,086, so the notebook weights the classes, uses a focal loss, and augments the smaller classes more heavily.

The model is EfficientNet-B5 with ImageNet weights, fully fine-tuned at 456 × 456 pixels in mixed precision, with a small head of average pooling, dropout and a softmax layer. It trains with AdamW and a warm-up and cosine-decay learning rate for up to 50 epochs. The best checkpoint by validation accuracy is kept, which is epoch 9 in the saved run, and training stopped early at epoch 19.

In the saved run, accuracy on the 1,235 test images is 97.98% and the macro-F1 is 0.9579. The notebook ends with a classification report, confusion matrices, and a helper that predicts the class of a single image.

Where the images come from

The images were gathered from seven published datasets and mixed together for training. Five are on Mendeley Data, under a CC BY 4.0 licence, and two are on Kaggle. Where the same dataset is posted on both sites, only the Mendeley original is listed here. Some of them cover other crops, such as watermelon, luffa and white cabbage, as their titles show.

Changes made: the images were mixed into one folder, split into training, validation and test sets, resized to 456 × 456 pixels, and augmented while training, more heavily for the smaller classes. The notebook reads one combined folder, so it does not show which image came from which source. The images are not included here.

In the notebook

Files and links

Good to know

  • The notebook was run on Google Colab with an A100 GPU, as the file records.
  • The images are not included here: the notebook reads them from a folder on Google Drive.
  • The notebook is shown as it was saved: cells in file order, with the output stored in the file. Its execution counts are not in sequence, because some cells were run more than once. Nothing is re-run here, so the numbers you see are the ones it saved.