0% found this document useful (0 votes)
9 views2 pages

CNN Plant Disease Detection Model

Uploaded by

Sanjay J.r
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

CNN Plant Disease Detection Model

Uploaded by

Sanjay J.r
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Code Implementation (Working Model)

# Plant Disease Detection Using CNN

import tensorflow as tf
from [Link] import ImageDataGenerator
from [Link] import Sequential
from [Link] import Conv2D, MaxPooling2D, Flatten,
Dense, Dropout
from [Link] import Adam
import [Link] as plt

# Data preprocessing
datagen = ImageDataGenerator(rescale=1./255, validation_split=0.2,
rotation_range=20, zoom_range=0.2,
horizontal_flip=True, shear_range=0.2)

train_data = datagen.flow_from_directory('PlantVillage',
target_size=(128, 128),
batch_size=32,
class_mode='categorical',
subset='training')

val_data = datagen.flow_from_directory('PlantVillage',
target_size=(128, 128),
batch_size=32,
class_mode='categorical',
subset='validation')

# CNN Model
model = Sequential([
Conv2D(32, (3,3), activation='relu', input_shape=(128,128,3)),
MaxPooling2D(2,2),
Conv2D(64, (3,3), activation='relu'),
MaxPooling2D(2,2),
Flatten(),
Dense(128, activation='relu'),
Dropout(0.3),
Dense(train_data.num_classes, activation='softmax')
])

[Link](optimizer=Adam(learning_rate=0.001),
loss='categorical_crossentropy',
metrics=['accuracy'])

# Model Training
history = [Link](train_data, validation_data=val_data, epochs=10)

# Plot Accuracy
[Link]([Link]['accuracy'], label='train acc')
[Link]([Link]['val_accuracy'], label='val acc')
[Link]()
[Link]()
# Evaluate
loss, acc = [Link](val_data)
print(f"Validation Accuracy: {acc*100:.2f}%")

# Save model
[Link]('plant_disease_model.h5')

This project can be implemented end-to-end using TensorFlow and the


PlantVillage dataset. The generated model can later be integrated with a
simple Flask web app for real-time prediction.

You might also like