finplnt
finplnt
INTRODUCTION
This project focuses on developing an AI-powered plant disease detection system using
Convolutional Neural Networks (CNNs) in PyTorch. The system allows users to upload a leaf
image, which is then analyzed to detect whether the plant is affected by fungus or other
diseases. The model is trained on the Plant leaf dataset, which contains images of plant leaves
classified into 39 different categories of diseases and healthy plants.
Once the disease is identified, the system displays the disease name, provides a brief
description, and suggests appropriate medicines or treatments to cure it. Additionally, the
platform includes a medicine purchase module, enabling users to buy relevant treatments
directly.
This project aims to assist farmers and agricultural professionals by providing an easy-to-
use web-based or mobile solution for real-time plant disease detection, reducing crop losses
and improving productivity. This technology not only helps in reducing dependency on
manual inspection but also minimizes the use of unnecessary pesticides, promoting sustainable
farming practices. the system can be expanded to support multiple crops and regions, further
enhancing its impact on global agriculture.
The system leverages deep learning and image processing techniques to enhance the
accuracy of disease classification, ensuring reliable results. By automating the disease
detection process, it helps farmers make quick and informed decisions, ultimately improving
crop health. Future enhancements may include real-time detection using Edge AI devices,
multi-language support for accessibility, and a chatbot-based assistant for disease-related
queries. This AI-driven approach has the potential to revolutionize precision agriculture,
making plant disease diagnosis faster, easier, and more efficient.
1
1.2 PROBLEM DEFINITION
Agriculture plays a vital role in global food production, but plant diseases pose a serious threat
to crop yield and quality. Millions of farmers, especially in rural areas, lack access to agricultural
experts, making it difficult to diagnose plant diseases accurately. Traditional disease detection
methods, such as manual inspection, are time-consuming, subjective, and often inaccurate. While
laboratory-based testing provides precise results, it is expensive and not feasible for small-scale
farmers. Additionally, different plant diseases may exhibit similar symptoms, further increasing
the chances of misdiagnosis and ineffective treatment, which ultimately impacts the health of crops
and food supply chains.
Incorrect or excessive use of pesticides due to misdiagnosis not only increases farming costs but
also harms the environment by contaminating soil and water. To address these challenges, there is
a need for an AI-powered, automated system that can accurately detect plant diseases from leaf
images and suggest appropriate treatments. By leveraging deep learning and computer vision, such
a system can help farmers quickly identify diseases, take preventive measures, and improve overall
agricultural productivity, ultimately supporting sustainable and efficient farming practices.
Furthermore, integrating such a system into web and mobile applications can make disease
detection easily accessible to farmers, even in remote areas. With real-time analysis and treatment
recommendations, farmers can take immediate action to protect their crops, preventing large-scale
infections. The system can also be expanded to include multiple crop types and different
environmental conditions, increasing its usability across various agricultural sectors.
2
CHAPTER 2
SYSTEM STUDY
In the existing system, plant disease detection primarily relies on manual inspection by
farmers or agricultural experts, which is time-consuming, subjective, and prone to human
error. Farmers often depend on their own experience or visual observations to identify
diseases, leading to misdiagnosis and improper pesticide use. In some cases, laboratory testing
is used for disease identification, but it is expensive, requires specialized equipment, and is not
easily accessible to small-scale farmers. Additionally, some existing image-based disease
detection systems lack accuracy, scalability, and real-time processing capabilities, making
them ineffective for large-scale agricultural applications. Due to these limitations, farmers
struggle to detect plant diseases early, resulting in significant crop losses, lower productivity,
and increased farming costs.
The proposed system introduces an AI-powered plant disease detection model using
Convolutional Neural Networks (CNNs) in PyTorch, capable of classifying leaf images into
39 different categories of plant diseases with high accuracy. The system allows users to upload
a leaf image, which is then analyzed by a deep learning model trained on the PlantVillage
dataset. Once the disease is identified, the system displays the disease name, provides a brief
description, and suggests appropriate medicines or treatments. Additionally, the platform
includes a medicine purchase module, allowing users to buy the recommended treatments
directly. This automated approach eliminates the need for manual disease identification,
enabling real-time, accurate, and accessible disease detection for farmers. By integrating deep
learning, web, and mobile technologies, the system helps farmers prevent crop losses, reduce
dependency on experts, and promote sustainable farming practices, ultimately improving
agricultural productivity and food security.
3
2.3 PROBLEM DESCRIPTION
The Plant diseases are a major concern in agriculture, leading to significant crop losses and
affecting farmers' livelihoods and food security. Early detection and accurate diagnosis of
plant diseases are crucial for effective treatment and prevention, but traditional methods of
disease identification rely heavily on manual inspection by farmers or agricultural experts.
This process is time-consuming, subjective, and prone to human error, often resulting in
misdiagnosis and improper pesticide usage. Additionally, laboratory-based testing, while
accurate, is expensive, not easily accessible, and impractical for small-scale farmers. The lack
of an efficient, scalable, and automated disease detection system further exacerbates the
problem, leading to delayed treatment and reduced agricultural productivity. In many cases,
farmers apply excessive pesticides, which not only increases costs but also harms the
environment, affecting soil quality and biodiversity.
With advancements in Artificial Intelligence (AI) and Deep Learning, an automated solution
can help overcome these challenges by providing real-time, accurate, and accessible disease
detection. This project aims to develop an AI-powered plant disease detection system using
Convolutional Neural Networks (CNNs) in PyTorch. The system will allow users to upload
leaf images, detect the presence of fungus or other diseases, and provide treatment
recommendations. By automating disease detection and integrating it with e-commerce and
mobile/web platforms, this system will help farmers take immediate action, reduce crop losses,
and promote sustainable farming practices. The use of machine learning algorithms ensures
that the system continuously improves its accuracy, making it a reliable tool for farmers.
Future enhancements can include multi-language support, chatbot assistance, and real-time
field monitoring, making the solution even more accessible and practical for global agriculture.
4
2.4 TECHNOLOGIES ADOPTED
Convolutional Neural Networks (CNNs): Used for feature extraction and classification
of plant diseases.
PyTorch – A deep learning framework for building and training the CNN model.
NumPy & Pandas – For handling image data and model inputs.
Flask (Python Framework): Used as the backend to handle image uploads, process
requests, and run the AI model.
Flask API: To integrate the trained CNN model with the web application.
Google Colab / Local GPU: For training the deep learning model efficiently.
TensorFlow Lite: Allows the model to run on mobile devices without requiring an internet
connection.
5
CHAPTER 3
SYSTEM DESIGN AND DEVELOPMENT
6
3.2 SYSTEM FLOW DIAGRAM
7
3.3 INPUT DESIGN
1. User Input Method – Users can upload a leaf image through a file selection button or a
drag-and-drop interface, making the process simple and efficient. The interface is designed to
be intuitive and mobile-friendly, ensuring that users from different backgrounds, including
farmers with minimal technical knowledge, can use it with ease.
2. Accepted Input Formats – The system supports commonly used image formats such as
JPG, PNG, and JPEG, allowing flexibility for images taken from various devices like
smartphones, digital cameras, and scanned documents. This ensures that users do not face
compatibility issues when uploading images for disease detection.
3. Input Validation & Constraints – The system performs checks to ensure that only valid
image files are uploaded. It restricts file sizes to an optimal limit, preventing large images
from slowing down processing. If a user tries to upload an incorrect format or an excessively
large file, the system prompts a clear error message, guiding them to correct their input.
4. Preprocessing of Input Data – After the image is uploaded, automated preprocessing
techniques are applied, including image resizing, contrast enhancement, and noise reduction
using OpenCV. These steps help in improving the clarity of the image, allowing the deep
learning model to extract features more effectively. This ensures that even low-quality or
unevenly lit images are standardized for accurate classification.
5. Error Handling & Feedback – If an invalid file is uploaded, the system instantly notifies
the user with a descriptive error message such as "Invalid file format, please upload a JPG or
PNG image." Additionally, if the image is blurry or unrecognizable, the system may prompt
users to upload a clearer image for better results. Providing real-time feedback ensures a
smooth user experience, reducing frustration and improving usability.
8
3.4 OUTPUT DESIGN
Once the image is analyzed, the system displays the detected disease name (e.g., "Tomato
Leaf Mold" or "Healthy Leaf"). The detection process is fast and efficient, ensuring real-time
feedback for immediate action.
Based on the detected disease, the system suggests appropriate treatments, such as
fungicides, pesticides, or organic remedies. Additionally, it provides precautionary steps
to prevent further spread, ensuring effective disease management.
4. User-Friendly Report Generation:
The system allows users to download a detailed report of the diagnosis, including the
detected disease, confidence score, treatment suggestions, and preventive measures. This
helps farmers and researchers maintain records for future reference.
9
CHAPTER 4
SYSTEM TESING
Functional testing ensures that all components of the Plant Disease Detection System work
correctly according to the defined requirements. It helps validate the performance of the AI
model, the accuracy of disease detection, and the correctness of medicine recommendations.
The primary objective is to ensure seamless integration between the modules and provide users
with a smooth and efficient experience. Various test cases have been executed to check whether
the system can handle different types of inputs, such as various image formats, different plant
species, and varying lighting conditions in images. The disease detection algorithm was tested
with a dataset containing multiple disease categories to evaluate its precision and recall.
Additionally, error handling mechanisms were tested to ensure the system provides meaningful
feedback when incorrect inputs are uploaded. The recommendation system was also evaluated
to verify if the suggested treatments align with the detected diseases. Overall, the functional
testing phase confirmed that the system meets its intended functionality, ensuring reliability and
accuracy for end users.
10
TEST CASES
Test
Test Case Actual Outcome Status
Case Steps to Expected
Description
ID Execute Outcome
1.Click "Upload The system should Pass
TC-001 Image upload Image" button. accept the image Image uploaded
Functionality 2. Select leaf and proceed to the successfully and
image. processed.
detection phase.
3. Click"Submit".
1.Upload image The system should Disease detected Pass
TC-002 Disease of a diseased correctly identify accurately with
Detection leaf. the disease with a confidence score
Accuracy 2.Click "Submit" confidence score displayed.
3.Observe the above the threshold.
disease name.
Check if relevant The system should Correct medicines Pass
TC-003 Medicine medicines/pesticid provide appropriate recommended based
Recommendatio es are suggested. medicines on detected disease.
corresponding to the
identified disease.
11
TEST CASE REPORT
1. Introduction
This report summarizes the functional testing conducted on the Netflix Data Analysis project,
focusing on validating core functionalities such as page loading, data filtering, and data
visualization. The primary goal was to ensure that the application behaves as expected and meets
user requirements.
TEST SUMMARY
3. Conclusion
All test cases were successfully executed, confirming that the Netflix Data Analysis application
operates as intended. The project meets its functional requirements, and all core functionalities
work correctly. The application is ready for further testing phases and potential deployment.
12
CHAPTER 5
SYSTEM IMPLEMENTATION AND MAINTENANCE
5.1 RESULT
1. Data Insights:
Content Overview: The analysis provided a detailed view of plant diseases detected,
including the types of diseases, their frequency, and severity levels based on the uploaded
images.
2. User Interaction:
Upload : Users could efficiently upload images and receive accurate disease detection
results along with suggested medicines. The interface allowed users to filter results by disease
type for a more focused experience.
Analysis: Identified the most frequent diseases affecting plants, providing insights into
common agricultural challenges.
4. User Feedback:
13
5. Performance Metrics:
Scalability: Tests confirmed that the system could handle multiple concurrent uploads
efficiently.
6. Future Enhancements:
1. Data Encryption:
Ensures all sensitive data, including user details and transaction information, is encrypted
using SSL/TLS protocols during transmission.
Encrypts stored data, especially for payment information in the medicine purchase module.
2. User Authentication:
Implements secure login mechanisms to prevent unauthorized access to the system.
Uses hashed passwords and authentication tokens for user session.
14
4. Input Validation:
Uses whitelisting and sanitization techniques for all input fields to protect against SQL
injection and XSS attacks.
Provides guidelines and tips for users on securely using the system.
Educates users on recognizing and avoiding potential security threats, such as phishing
links during the medicine purchase process.
15
5.3 MODULES
1. Home Module:
2. AI Engine Module:
3. Supplements Module:
16
CONCLUSION
The project Plant Disease Detection System successfully implements deep learning
techniques to identify plant diseases and recommend suitable treatments, enhancing
agricultural efficiency and plant health management. By leveraging Convolutional Neural
Networks (CNNs) for image analysis, the system accurately detects diseases in uploaded leaf
images, providing users with real-time insights into potential infections. This technology helps
farmers, gardeners, and agricultural researchers take immediate corrective actions, reducing
crop losses and improving overall yield. The system offers an intuitive and user-friendly
interface, allowing seamless image uploads and quick disease detection, ensuring accessibility
for users with varying levels of technical expertise. Additionally, the supplements module
provides users with treatment options, enabling them to purchase pesticides and fertilizers
directly through the system. The AI Engine Module ensures accurate and fast processing,
leveraging a structured disease database to enhance future detection accuracy. Future
improvements may include real-time disease monitoring, AI-driven advisory support, and an
expanded training dataset to improve the system’s predictive capabilities. Ultimately, this
project demonstrates the power of AI-driven automation in agriculture, offering a cost-
effective, data-driven approach to plant disease management and contributing to sustainable
farming practices and higher agricultural productivity.
17
CHAPTER 6
BIBLIOGRAPHY AND WEB REFERENCE
import os
import torchvision.transforms.functional as TF
import CNN
import numpy as np
import torch
import pandas as pd
supplement_info = pd.read_csv('supplement_info.csv',encoding='cp1252')
model = CNN.CNN(39)
model.load_state_dict(torch.load("plant_disease_model_1_latest.pt"))
model.eval()
def prediction(image_path):
image = Image.open(image_path)
18
image = image.resize((224, 224))
input_data = TF.to_tensor(image)
output = model(input_data)
output = output.detach().numpy()
index = np.argmax(output)
return index
app = Flask(__name__)
@app.route('/')
def home_page():
return render_template('home.html')
@app.route('/index')
def ai_engine_page():
return render_template('index.html')
def submit():
if request.method == 'POST':
image = request.files['image']
filename = image.filename
image.save(file_path)
print(file_path)
19
pred = prediction(file_path)
title = disease_info['disease_name'][pred]
description =disease_info['description'][pred]
image_url = disease_info['image_url'][pred]
def market():
if __name__ == '__main__':
app.run(debug=True)
20
HOME PAGE :
{% block pagetitle %}
{% endblock pagetitle %}
{% block body %}
<style>
.laptop{
display: none;
.mobile{
display: none;
</div>
</div>
</div>
21
<div class="row mb-5 text-center text-white laptop">
Detection🍁 </b></h1>
</div>
</div>
<center class="laptop">
<a href="/index">
</a>
</center>
</div>
</div>
22
<div class="col">
<img src="https://www.supermarketperimeter.com/ext/resources/0430-
blueberries.png?t=1588260305&width=1080" width="250" height="250">
</div>
</div>
</div>
</div>
</div>
</div>
23
</div>
</div>
</div>
<div class="col">
</div>
</div>
</div
24
<center><p class="lead" style="font-weight: 500;color:
black;">Soybean</p></center>
</div>
</div>
</div>
<center class="laptop">
<img src="https://images.indianexpress.com/2020/02/strawberry-1200.jpg"
width="250" height="250">
</div>
</div>
<div class="col">
25
<img src="https://images-
prod.healthline.com/hlcmsresource/images/AN_images/tomatoes-1296x728-
feature.jpg" width="250" height="250">
</div>
</div>
</div>
</center>
{% endblock body %}
INDEX PAGE :
<html>
{% extends 'base.html' %}
{% block pagetitle %}
{% endblock pagetitle %}
{% block body %}
<div>
<div class="container">
<div class="row mb-5 text-center text-white">
<div class="col-lg-10 mx-auto">
<h1 class="display-4" style="padding-top: 2%;font-weight: 400;color: rgb(4,
54, 4);"><b>🍀AI Engine🍀</b></h1>
<p class="lead" style="font-weight: 500;color: black;">Let AI Engine Will
Help You To Detect Disease</p>
</div>
</div>
26
<!-- End -->
<div class="row ">
<div class="col mx-auto">
<div class="p-5 bg-white shadow rounded-lg" style="height: 95%;">
<h5><b>Why is it necessary to detect disease in plant ?</b></h5>
<p>Plant diseases affect the growth of their respective species. In addition,
some research gaps are
identified from which to obtain greater transparency for detecting
diseases in plants, even
before their symptoms appear clearly.
diagnosis is one of the most important aspects of a plant pathologist's
training. Without proper
identification of the disease and the disease-causing agent, disease
control measures can be a
waste of time and money and can lead to further plant losses. Proper
disease diagnosis is
necessary.
</p>
</div>
<form action="/submit" method="POST" enctype="multipart/form-data">
<div class="custom-file overflow-hidden mb-4">
<input type="file" id="actual-btn" hidden name="image" />
<label for="actual-btn">Choose File</label>
<span id="file-chosen">No file chosen</span>
</div>
<!-- End -->
<h6 class="text-center mb-4 text-muted">
Simply upload your plant's leaf image and then see the magic of AI.
</h6>
<!-- Custom bootstrap upload file-->
<center>
<a class="mx-2"><button type="submit" class="btn btn-outline-
27
success">Submit</button></a>
</center>
</form>
<!-- End -->
</div>
</div>
<div class="col mx-auto">
<div class="p-5 bg-white shadow rounded-lg" style="height: 95%;">
<h5><b>Prevent Plant Disease follow below steps:</b></h5>
<ol>
<li>Follow Good Sanitation Practices.</li>
<li>Fertilize to Keep Your Plants Healthy.</li>
<li>Inspect Plants for Diseases Before You Bring Them Home.</li>
<li>Allow the Soil to Warm Before Planting.</li>
<li>Ensure a Healthy Vegetable Garden By Rotating Crops.</li>
<li>Provide Good Air Circulation</li>
<li>Remove Diseased Stems and Foliage</li>
</ol>
<a target="_blank" href="https://www.thespruce.com/prevent-plant-
diseases-in-your-garden-2539511"
class="mx-2"><button type="button" class="btn btn-outline-
success">More info</button></a>
</div>
</div>
</div>
</div>
</div>
<script>
const actualBtn = document.getElementById('actual-btn');
28
const fileChosen = document.getElementById('file-chosen');
actualBtn.addEventListener('change', function () {
fileChosen.textContent = this.files[0].name
})
</script>
{% endblock body %}
SUPPLEMENT PAGE :
{% extends 'base.html' %}
{% block pagetitle %}
Supplement Market
{% endblock pagetitle %}
{% block body %}
<br>
<div class="row mb-5 text-center text-white">
<div class="col-lg-10 mx-auto">
<h1 class="display-4" style="padding-top: 2%;font-weight: 400;color: rgb(4, 54,
4);"><b>🛒Supplements🛒</b></h1>
<p class="lead" style="font-weight: 500;color: black;">Buy Supplements &
Fertilizer at one place</p>
</div>
</div>
<div class="row p-3">
{% for index in range(0,supplement_name | length) %}
{% if index != 4 %}
<div class="col">
29
<div class=" p-5 bg-white shadow rounded-lg" style="height: 95%;">
<center>
{% if index==3 or index==5 or index==7 or index==11 or index==15 or
index==18 or index==20 or
index==23 or
index==24 or index==25 or index==28 or index==38 %}
<h5>Fertilizer<b style="color: green;"> (Healthy):</b></h5>
{% else %}
<h5>Supplements<b style="color: red;"> (Diseased):</b></h5>
{% endif %}
<br>
<img src={{supplement_image[index]}} width="200" height="250">
<br>
<br>
<h6>For {{disease[index]}}</h6>
<p>{{supplement_name[index]}}</p>
30
6.2 SAMPLE SCREENSHOT
31
32
33
6.2 WEB REFERENCES
https://www.tensorflow.org/tutorials/images/cnn.
Provides an in-depth guide on building CNN-based models for image classification, which
was utilized for plant disease detection.
https://www.sciencedirect.com/science/article/pii/S0168169919311872
Research paper discussing various approaches for plant disease detection using deep
learning.
https://www.kaggle.com/datasets
A repository of publicly available datasets for training plant disease detection models.
CSS : https://css-tricks.com/
HTML: https://www.w3schools.com/html/
https://flask.palletsprojects.com/
Official documentation for Flask, which was used for developing the backend of the
project.
34