Disease Detection in Plants
By: Manan Patel
Tags: Data Science, Convolutional Network, Disease Detection

Introduction

The primary occupation in India is agriculture. More than 50% of people depend on it & shares a major part of the GDP. Here in India, farmers cultivate a great variety of crops. Many factors such as climatic/soil conditions, various diseases affect the production of the crops. The existing method for plant disease detection is very simple and it requires more man labour, equipped laboratories, expensive devices. There are few challenges including Symptom Segmentation, Symptom variation, Image background, Image capture condition, which are very crucial.

Dataset

I have used public and very famous, the PlantVilage dataset. It was published by crowdAI during one challenge named “PlantVillage Disease Classification”

Link of dataset:

https://www.crowdai.org/challenges/plantvillage-disease-classification-challenge

The dataset contains around 54k images of plant leaves. These plant images include following 14 types of different species:

Apple, Blueberry, Cherry, Corn, Bell Pepper, Potato, Raspberry, Grape, Orange, Peach, Soybean, Squash, Strawberry, and Tomato

Following is a list of 38 classes of plant disease,

1. Apple Scab

2. Apple Black Rot

3. Apple Cedar Rust

4. Apple healthy

5. Blueberry healthy

6. Cherry healthy

7. Cherry Powdery Mildew

8. Corn Gray Leaf Spot

9. Corn Common Rust

10. Corn healthy

11. Corn Northern Leaf Blight

12. Grape Black Rot

13. Grape Black Measles

14. Grape Leaf Blight

15. Grape healthy

16. Orange Huanglongbing

17. Peach Bacterial Spot

18. Peach healthy

19. Bell Pepper Bacterial Spot

20. Bell Pepper healthy

21. Potato Early Blight

22. Potato healthy

23. Potato Late Blight

24. Raspberry healthy

25. Soybean healthy

26. Squash Powdery Mildew

27. Strawberry Healthy

28. Strawberry Leaf Scorch

29. Tomato Bacterial Spot

30. Tomato Early Blight

31. Tomato Late Blight

32. Tomato Leaf Mold

33. Tomato Septoria Leaf Spot

34. Tomato Two Spotted Spider Mite

35. Tomato Target Spot

36. Tomato Mosaic Virus

37. Tomato Yellow Leaf Curl Virus

38. Tomato healthy

As there are numerous advantages to train model in the cloud because training requires huge computation power. (If you have a good GPU then you are good to go and you can train in your local computer as well)

I will use Google colab but you can use as per your choice.

(Google colab is a free cloud service which offers free graphics processing units (GPU — 12 GB RAM). It’s one of the fastest ways to train model)

Download the plant village dataset and Upload it to Google Drive.

Sign-in to Colab and Create a new IPython Notebook (ipynb)

Switch to GPU and get ready to fly!

Mount data from google drive.

from google.colab import drive

drive.mount(‘/content/your path’)

Import Libraries

Now, create a function to convert or resize the input dataset images so that they can be fit for training.

After that, iterate through dataset folder, resize the images from each folder and load them to numpy array.

Since there are thousands of images, it will take time to load. After loading dataset, map each plant disease to a unique value for training task. Also, Save this transform to a pickle file.

TRAIN — TEST — SPLIT

Then we split our loaded dataset with train and test set with 0.2 split ratio.

(i.e., 80% Training & 20% Testing)

Data Augmentation

Data Augmentation is used to artificially expand the size of a training dataset by creating modified versions of images (such as rotation, zoom, flip rotation) in the dataset. It will help model to learn features efficiently. Moreover, it can perform better on validation data.

Model

Now, create a sequential model for the classification task.

Model — Hyper Parameters

Define all the hyperparameters. Keep it separate in individual cell so that It will be easier to edit it later on.

Model — Training

Select optimization technique and compile it.

Take a break guys…!!!

Model Evaluation

Performance is great but, [what] has the model learnt?

From the above plot, we can see that we can train model little bit more for as the trend for accuracy is rising in last few epochs.

From the above plot of loss, we can see that initially validation loss was high but finally loss decreased to a great extent.

By looking at the both above graphs, it is clearly visible that, as the training accuracy increases, validation accuracy increases. Likewise, as the training loss decreases, the validation loss decreases.

Evaluate() and check

BOOM!

Accuracy: 95.31% !!

The model has great performance on unseen data as well.

It’s time for a REAL TEST

Choose random images from the dataset and try predicting disease of the plant image.

Model — Reuse

Save model using,

model.save(“modelname.h5”)

load model,

This is how, one can load model and use trained model for prediction.

References:

http://www.ijareeie.com/upload/2019/march/14_Plant.pdf

https://towardsdatascience.com/plant-ai-plant-disease-detection-using-convolutional-neural-network-9b58a96f2289