Prediction Of Flora Disease And Suggested Remedies Using Machine Learning
Create New

Prediction Of Flora Disease And Suggested Remedies Using Machine Learning

Project period

08/26/2019 - 11/20/2019

Views

26

3



Prediction Of Flora Disease And Suggested Remedies Using Machine Learning
Prediction Of Flora Disease And Suggested Remedies Using Machine Learning

Agriculture plays a vital role in the present global economy. Continuous pressure on the agricultural system results in increased expansion of the human population. Continuous researches have been performed in our past, to study the interactions between plant immune responses and pathogens. Previously, researchers usually applied large-scale genetic screening and genomic approaches to identify genes and proteins of interest. But now, the event of machine learning algorithms, which are a group of analytic methods that modify model building process and iteratively learn from information to gain knowledge without expressly programming, provides additional powerful and best tools to classify plant diseases from images of infected leaves.

Machine learning is considered as one of the branches in Artificial Intelligence to work automatically or to predict information or to give instructions to a system to perform an action. The aim of Machine Learning is to explain the structure of the data and fit that data into models that can be utilized by the researchers. This project work involves analysis of various machine algorithms which is applied to plant disease prediction. Machine Learning technology can accurately find out the presence of pests and disease in the leaves of a plant. Upon this Machine learning algorithm, one can predict the chance of any disease and pest attacks in the future. 

Why: Problem statement

Normal manpower for monitoring will not be possible to predict the exact amount and intensity of pests and disease attacked on the farm for spraying fertilizers/pesticides. Usually in India,  farmers manually observe and use some applications which have huge database limitations. According to a proverb, prevention is better than cure, our project aims at the prediction of flora disease and suggests remedies using machine learning. 

How: Solution description

This project helps farmers to protect their farmyard from all kinds of pests and disease attacks and fix them.

In this project, folded neural network models were created to predict plant disease detection and diagnosis using only the leaves images diseased plants, through deep learning methodologies. 

Machine learning has become prominent with big data technologies and high-performance computing to create new opportunities for data-intensive science. In this project, we present a comprehensive review of research applications of machine learning in agricultural systems. The prediction and diagnosis in this project demonstrate how agriculture will benefit from machine learning technologies. By using machine learning to sensor data, farm management systems are entering into real-time artificial intelligence. hence these enabled programs provide rich recommendations and insights for farmer decision support and action.

Using python code, the first step is to collect samples and feed the data, then we train the received sample as healthy and unhealthy. if it is predicted as unhealthy we are suggested with remedies then exit.

 

We have used python software to obtain the solution for this project. the packages required are listed below:

  • Numpy
  • Tqdm
  • TensorFlow
  • OpenCV
  • Matplotlib

How is it different from competition

The infection of leaves by pests affects the agricultural production of the country. But usually, farmers or experts observe the leaves with the naked eye for detection and identification of disease. But applying this method, it may be time-consuming, high cost and inaccurate. Automatic detection or prediction using image training techniques gives us quick and accurate results. This paper is concerned with a new idea to the development of the plant disease recognition model, based on leaf image classification, and simultaneously gives us remedies. The existing plant disease prediction project helps us only to predict if the leaf is infected or not. But in this project, we will be able to predict the disease and suggest remedies as well.

Who are your customers

  • Agriculture department
  • Farmers
  • Agriculture student for research purpose

Project Phases and Schedule

Phase 1: Data Collection(plant images)

Phase 2: Processing and segmentation

Phase 3: Feature extraction and selection

Phase 4: Analyse image
 
Phase 5: Disease prediction and suggested remedies

Resources Required

Software required:

  • Anaconda
  • Python 3.7
  • Jupyter notebook

Download:
Project Code Code copy
/* Your file Name : Plant_disease_detection.ipynb */
/* Your coding Language : python */
/* Your code snippet start here */
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tkinter as tk\n",
    "from tkinter.filedialog import askopenfilename\n",
    "import shutil\n",
    "import os\n",
    "import sys\n",
    "from PIL import Image, ImageTk\n",
    "\n",
    "window = tk.Tk()\n",
    "\n",
    "window.title(\"Dr. Plant\")\n",
    "\n",
    "window.geometry(\"500x510\")\n",
    "window.configure(background =\"lightgreen\")\n",
    "\n",
    "title = tk.Label(text=\"Click below to choose picture for testing disease....\", background = \"lightgreen\", fg=\"Brown\", font=(\"\", 15))\n",
    "title.grid()\n",
    "def bact():\n",
    "    window.destroy()\n",
    "    window1 = tk.Tk()\n",
    "\n",
    "    window1.title(\"Dr. Plant\")\n",
    "\n",
    "    window1.geometry(\"500x510\")\n",
    "    window1.configure(background=\"lightgreen\")\n",
    "\n",
    "    def exit():\n",
    "        window1.destroy()\n",
    "    rem = \"The remedies for Bacterial Spot are:\\n\\n \"\n",
    "    remedies = tk.Label(text=rem, background=\"lightgreen\",\n",
    "                      fg=\"Brown\", font=(\"\", 15))\n",
    "    remedies.grid(column=0, row=7, padx=10, pady=10)\n",
    "    rem1 = \" Discard or destroy any affected plants. \\n  Do not compost them. \\n  Rotate yoour tomato plants yearly to prevent re-infection next year. \\n Use copper fungicites\"\n",
    "    remedies1 = tk.Label(text=rem1, background=\"lightgreen\",\n",
    "                        fg=\"Black\", font=(\"\", 12))\n",
    "    remedies1.grid(column=0, row=8, padx=10, pady=10)\n",
    "\n",
    "    button = tk.Button(text=\"Exit\", command=exit)\n",
    "    button.grid(column=0, row=9, padx=20, pady=20)\n",
    "\n",
    "    window1.mainloop()\n",
    "\n",
    "\n",
    "def vir():\n",
    "    window.destroy()\n",
    "    window1 = tk.Tk()\n",
    "\n",
    "    window1.title(\"Dr. Plant\")\n",
    "\n",
    "    window1.geometry(\"650x510\")\n",
    "    window1.configure(background=\"lightgreen\")\n",
    "\n",
    "    def exit():\n",
    "        window1.destroy()\n",
    "    rem = \"The remedies for Yellow leaf curl virus are: \"\n",
    "    remedies = tk.Label(text=rem, background=\"lightgreen\",\n",
    "                      fg=\"Brown\", font=(\"\", 15))\n",
    "    remedies.grid(column=0, row=7, padx=10, pady=10)\n",
    "    rem1 = \" Monitor the field, handpick diseased plants and bury them. \\n  Use sticky yellow plastic traps. \\n  Spray insecticides such as organophosphates, carbametes during the seedliing stage. \\n Use copper fungicites\"\n",
    "    remedies1 = tk.Label(text=rem1, background=\"lightgreen\",\n",
    "                         fg=\"Black\", font=(\"\", 12))\n",
    "    remedies1.grid(column=0, row=8, padx=10, pady=10)\n",
    "\n",
    "    button = tk.Button(text=\"Exit\", command=exit)\n",
    "    button.grid(column=0, row=9, padx=20, pady=20)\n",
    "\n",
    "    window1.mainloop()\n",
    "\n",
    "def latebl():\n",
    "    window.destroy()\n",
    "    window1 = tk.Tk()\n",
    "\n",
    "    window1.title(\"Dr. Plant\")\n",
    "\n",
    "    window1.geometry(\"520x510\")\n",
    "    window1.configure(background=\"lightgreen\")\n",
    "\n",
    "    def exit():\n",
    "        window1.destroy()\n",
    "    rem = \"The remedies for Late Blight are: \"\n",
    "    remedies = tk.Label(text=rem, background=\"lightgreen\",\n",
    "                      fg=\"Brown\", font=(\"\", 15))\n",
    "    remedies.grid(column=0, row=7, padx=10, pady=10)\n",
    "\n",
    "    rem1 = \" Monitor the field, remove and destroy infected leaves. \\n  Treat organically with copper spray. \\n  Use chemical fungicides,the best of which for tomatoes is chlorothalonil.\"\n",
    "    remedies1 = tk.Label(text=rem1, background=\"lightgreen\",\n",
    "                         fg=\"Black\", font=(\"\", 12))\n",
    "    remedies1.grid(column=0, row=8, padx=10, pady=10)\n",
    "\n",
    "    button = tk.Button(text=\"Exit\", command=exit)\n",
    "    button.grid(column=0, row=9, padx=20, pady=20)\n",
    "\n",
    "    window1.mainloop()\n",
    "\n",
    "\n",
    "def analysis():\n",
    "    import cv2  # working with, mainly resizing, images\n",
    "    import numpy as np  # dealing with arrays\n",
    "    import os  # dealing with directories\n",
    "    from random import shuffle  # mixing up or currently ordered data that might lead our network astray in training.\n",
    "    from tqdm import \\\n",
    "        tqdm  # a nice pretty percentage bar for tasks. Thanks to viewer Daniel BA1/4hler for this suggestion\n",
    "    verify_dir = 'testpicture'\n",
    "    IMG_SIZE = 50\n",
    "    LR = 1e-3\n",
    "    MODEL_NAME = 'healthyvsunhealthy-{}-{}.model'.format(LR, '2conv-basic')\n",
    "\n",
    "    def process_verify_data():\n",
    "        verifying_data = []\n",
    "        for img in tqdm(os.listdir(verify_dir)):\n",
    "            path = os.path.join(verify_dir, img)\n",
    "            img_num = img.split('.')[0]\n",
    "            img = cv2.imread(path, cv2.IMREAD_COLOR)\n",
    "            img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))\n",
    "            verifying_data.append([np.array(img), img_num])\n",
    "        np.save('verify_data.npy', verifying_data)\n",
    "        return verifying_data\n",
    "\n",
    "    verify_data = process_verify_data()\n",
    "    #verify_data = np.load('verify_data.npy')\n",
    "\n",
    "    import tflearn\n",
    "    from tflearn.layers.conv import conv_2d, max_pool_2d\n",
    "    from tflearn.layers.core import input_data, dropout, fully_connected\n",
    "    from tflearn.layers.estimator import regression\n",
    "    import tensorflow as tf\n",
    "    tf.reset_default_graph()\n",
    "\n",
    "    convnet = input_data(shape=[None, IMG_SIZE, IMG_SIZE, 3], name='input')\n",
    "\n",
    "    convnet = conv_2d(convnet, 32, 3, activation='relu')\n",
    "    convnet = max_pool_2d(convnet, 3)\n",
    "\n",
    "    convnet = conv_2d(convnet, 64, 3, activation='relu')\n",
    "    convnet = max_pool_2d(convnet, 3)\n",
    "\n",
    "    convnet = conv_2d(convnet, 128, 3, activation='relu')\n",
    "    convnet = max_pool_2d(convnet, 3)\n",
    "\n",
    "    convnet = conv_2d(convnet, 32, 3, activation='relu')\n",
    "    convnet = max_pool_2d(convnet, 3)\n",
    "\n",
    "    convnet = conv_2d(convnet, 64, 3, activation='relu')\n",
    "    convnet = max_pool_2d(convnet, 3)\n",
    "\n",
    "    convnet = fully_connected(convnet, 1024, activation='relu')\n",
    "    convnet = dropout(convnet, 0.8)\n",
    "\n",
    "    convnet = fully_connected(convnet, 4, activation='softmax')\n",
    "    convnet = regression(convnet, optimizer='adam', learning_rate=LR, loss='categorical_crossentropy', name='targets')\n",
    "\n",
    "    model = tflearn.DNN(convnet, tensorboard_dir='log')\n",
    "\n",
    "    if os.path.exists('{}.meta'.format(MODEL_NAME)):\n",
    "        model.load(MODEL_NAME)\n",
    "        print('model loaded!')\n",
    "\n",
    "    import matplotlib.pyplot as plt\n",
    "\n",
    "    fig = plt.figure()\n",
    "\n",
    "    for num, data in enumerate(verify_data):\n",
    "\n",
    "        img_num = data[1]\n",
    "        img_data = data[0]\n",
    "\n",
    "        y = fig.add_subplot(3, 4, num + 1)\n",
    "        orig = img_data\n",
    "        data = img_data.reshape(IMG_SIZE, IMG_SIZE, 3)\n",
    "        # model_out = model.predict([data])[0]\n",
    "        model_out = model.predict([data])[0]\n",
    "\n",
    "        if np.argmax(model_out) == 0:\n",
    "            str_label = 'healthy'\n",
    "        elif np.argmax(model_out) == 1:\n",
    "            str_label = 'bacterial'\n",
    "        elif np.argmax(model_out) == 2:\n",
    "            str_label = 'viral'\n",
    "        elif np.argmax(model_out) == 3:\n",
    "            str_label = 'lateblight'\n",
    "\n",
    "        if str_label =='healthy':\n",
    "            status =\"HEALTHY\"\n",
    "        else:\n",
    "            status = \"UNHEALTHY\"\n",
    "\n",
    "        message = tk.Label(text='Status: '+status, background=\"lightgreen\",\n",
    "                           fg=\"Brown\", font=(\"\", 15))\n",
    "        message.grid(column=0, row=3, padx=10, pady=10)\n",
    "        if str_label == 'bacterial':\n",
    "            diseasename = \"Bacterial Spot \"\n",
    "            disease = tk.Label(text='Disease Name: ' + diseasename, background=\"lightgreen\",\n",
    "                               fg=\"Black\", font=(\"\", 15))\n",
    "            disease.grid(column=0, row=4, padx=10, pady=10)\n",
    "            r = tk.Label(text='Click below for remedies...', background=\"lightgreen\", fg=\"Brown\", font=(\"\", 15))\n",
    "            r.grid(column=0, row=5, padx=10, pady=10)\n",
    "            button3 = tk.Button(text=\"Remedies\", command=bact)\n",
    "            button3.grid(column=0, row=6, padx=10, pady=10)\n",
    "        elif str_label == 'viral':\n",
    "            diseasename = \"Yellow leaf curl virus \"\n",
    "            disease = tk.Label(text='Disease Name: ' + diseasename, background=\"lightgreen\",\n",
    "                               fg=\"Black\", font=(\"\", 15))\n",
    "            disease.grid(column=0, row=4, padx=10, pady=10)\n",
    "            r = tk.Label(text='Click below for remedies...', background=\"lightgreen\", fg=\"Brown\", font=(\"\", 15))\n",
    "            r.grid(column=0, row=5, padx=10, pady=10)\n",
    "            button3 = tk.Button(text=\"Remedies\", command=vir)\n",
    "            button3.grid(column=0, row=6, padx=10, pady=10)\n",
    "        elif str_label == 'lateblight':\n",
    "            diseasename = \"Late Blight \"\n",
    "            disease = tk.Label(text='Disease Name: ' + diseasename, background=\"lightgreen\",\n",
    "                               fg=\"Black\", font=(\"\", 15))\n",
    "            disease.grid(column=0, row=4, padx=10, pady=10)\n",
    "            r = tk.Label(text='Click below for remedies...', background=\"lightgreen\", fg=\"Brown\", font=(\"\", 15))\n",
    "            r.grid(column=0, row=5, padx=10, pady=10)\n",
    "            button3 = tk.Button(text=\"Remedies\", command=latebl)\n",
    "            button3.grid(column=0, row=6, padx=10, pady=10)\n",
    "        else:\n",
    "            r = tk.Label(text='Plant is healthy', background=\"lightgreen\", fg=\"Black\",\n",
    "                         font=(\"\", 15))\n",
    "            r.grid(column=0, row=4, padx=10, pady=10)\n",
    "            #button = tk.Button(text=\"Exit\", command=exit)\n",
    "            button.grid(column=0, row=9, padx=20, pady=20)\n",
    "\n",
    "def openphoto():\n",
    "    dirPath = \"testpicture\"\n",
    "    fileList = os.listdir(dirPath)\n",
    "    for fileName in fileList:\n",
    "        os.remove(dirPath + \"/\" + fileName)\n",
    "    fileName = askopenfilename(initialdir='test/test', title='Select image for analysis ',\n",
    "                           filetypes=[('image files', '.jpg')])\n",
    "    dst = \"testpicture\"\n",
    "    shutil.copy(fileName, dst)\n",
    "    load = Image.open(fileName)\n",
    "    render = ImageTk.PhotoImage(load)\n",
    "    img = tk.Label(image=render, height=\"250\", width=\"500\")\n",
    "    img.image = render\n",
    "    img.place(x=0, y=0)\n",
    "    img.grid(column=0, row=1, padx=10, pady = 10)\n",
    "    title.destroy()\n",
    "    button1.destroy()\n",
    "    button2 = tk.Button(text=\"Analyse Image\", command=analysis)\n",
    "    button2.grid(column=0, row=2, padx=10, pady = 10)\n",
    "button1 = tk.Button(text=\"Get Photo\", command = openphoto)\n",
    "button1.grid(column=0, row=1, padx=10, pady = 10)\n",
    "\n",
    "\n",
    "\n",
    "window.mainloop()\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
View on Github
Flora_disease_prediction

Comments

Leave a Comment

Post a Comment