• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer

DRH

My site

Tomato Deases Prediction Using Deep Learning(CNN Algorithm) With Data Set(Complete Project).

February 21, 2020 by Dilip Leave a Comment

Short Introduction
Here, Python programming language, Keras library is used to manipulate raw input image. To train on CNN architecture and creating a machine learning model that can predict the type of diseases, image data is collected from ourselves and the authenticated online source. As the result, few diseases that usually occurs in tomato plants such as Late blight (training 100, test 21), Gray spot (training 95, test 18) and bacterial canker (training 90, test 21) are detected. So, basically this project is a way to digitize the information in an image for the purpose of convenient retrieval and efficient processing of data. Dataset Preparation, Image processing of a certain level and a Convolutional Neural Network as a classifier are the three main areas, in which this project is completely relying on. The prime focus of this project is firstly to design a convolutional neural network with suitable parameters and train it with a dataset of our own. Finally, predicting the classes in an input image by processing the image into a desired format and then feeding it into the trained neural network.

Dataset For the Tomato Deases Prediction:
https://drive.google.com/open?id=1e43UolvmfnPvbTXKcbexDEgdqQT8y7dQ

Code for this project:

import numpy as np  import keras from keras import backend as K from keras.models import Sequential from keras.layers import Activation  from keras.layers.core import Dense,Flatten from keras.optimizers import Adam from keras.metrics import categorical_crossentropy from keras.preprocessing.image import ImageDataGenerator from keras.layers.normalization import BatchNormalization from keras.layers.convolutional import * from matplotlib import pyplot as plt from sklearn.metrics import confusion_matrix import itertools import matplotlib.pyplot as plt %matplotlib inline  

from keras.applications import VGG16#Load the VGG modelvgg_conv = VGG16(weights='imagenet', include_top=False, input_shape=(224, 224, 3)) 
 # Freeze the layers except the last 6 layers
for layer in vgg_conv.layers[:-7]:
    layer.trainable = False
 
# Check the trainable status of the individual layers
for layer in vgg_conv.layers:
    print(layer, layer.trainable) 
vgg_conv.summary() 
from keras import models
from keras import layers
from keras import optimizers
from keras.regularizers import l2
 
# Create the model
model = models.Sequential()
 
# Add the vgg convolutional base model
model.add(vgg_conv)

# Add new layers

model.add(layers.Dropout(0.25))
model.add(layers.Flatten())
model.add(layers.Dropout(0.4))
model.add(layers.Dense(512,kernel_regularizer=l2(0.01), bias_regularizer=l2(0.01),activation='relu'))
model.add(layers.Dense(8,kernel_regularizer=l2(0.01), bias_regularizer=l2(0.01),activation='softmax'))
 
# "Show a summary of the model. Check the number of trainable parameters"
model.summary() 
import tensorflow as tf
tf.test.gpu_device_name() 
# this code to is to connect the google drive with google #colab
from google.colab import drive 
drive.mount('/content/drive') 
import tarfile #importing tarfile to extract the tarfile where dataset is located
 train_path='proj/train'
test_path='proj/test'
valid_path='proj/valid' 
 train_generator=ImageDataGenerator().flow_from_directory(train_path,target_size=(224,224),classes=['anthracnose','calciumdefficiency','healthy','lateblight','bacterialSpot','tomatomosaic','yellowcurved','septorailleafspot'],batch_size=10)
validation_generator=ImageDataGenerator().flow_from_directory(valid_path,target_size=(224,224),classes=['anthracnose','calciumdefficiency','healthy','lateblight','bacterialSpot','tomatomosaic','yellowcurved','septorailleafspot'],batch_size=10)
test_batches=ImageDataGenerator().flow_from_directory(test_path,target_size=(224,224),classes=['anthracnose','calciumdefficiency','healthy','lateblight','bacterialSpot','tomatomosaic','yellowcurved','septorailleafspot'],batch_size=10) 

 from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True 

 train_datagen = ImageDataGenerator(
      rescale=1./255,
      rotation_range=20,
      width_shift_range=0.2,
      height_shift_range=0.2,
      horizontal_flip=True,
      fill_mode='nearest')
 
validation_datagen = ImageDataGenerator(rescale=1./255)
 
# Change the batchsize according to your system RAM
train_batchsize = 62
val_batchsize = 10
  
 # Compile the model
model.compile(loss='categorical_crossentropy',
              optimizer=optimizers.RMSprop(lr=1e-5),
              metrics=['acc'])
# Train the model
history = model.fit_generator(
      train_generator,
      steps_per_epoch=train_generator.samples/train_generator.batch_size ,
      epochs=25,
      validation_data=validation_generator,
      validation_steps=validation_generator.samples/validation_generator.batch_size,
      verbose=1)
 
# Save the model
model.save('trainedmodel_10.h5') 
 test_eval = model.evaluate(test_batches, verbose=0) 

print("Test Loss:",test_eval[0])
print("Test Accuracy:",test_eval[1])

print("Test Loss:",test_eval[0])
print("Test Accuracy:",test_eval[1])

 


Filed Under: Uncategorized

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • TypeScript common Syntax
  • Setting Up Ngrx store with the Ngrx schematics
  • AngularPipe
  • To create repository in github
  • Adding Bootstrap and JQuery in angular

Recent Comments

  • Dilip on Understanding Angular Versioning
  • Dilip on Understanding Angular Versioning
  • Sagar on error: No such host is known. While installing Dot net packages
  • Sagar on Digitalization Program in Province no. 1 Nepal
  • Dilip on error: No such host is known. While installing Dot net packages

Archives

  • June 2020
  • May 2020
  • April 2020
  • February 2020
  • January 2020

Footer

Artificial Intelligence And Machine Learning

Artificial intelligence is the Huge interdisplinery field which includes the social science,psychology and all in cognitive with the computer.Artificial intelligence means human like intelligence wich can think and process logic and gives decision.

Web Application Development

Web applications are those like websites wich is opend by browsers. Nowadays more than desktop application web application is growing because of internet available in all the remote places and data is managed easily.

Internet of things(IOT)

Internet of things is the technology wich are main technolgy to make smart home,smart city,and smart profession.You can make your work comfortable with remote sensors internet and many networking interface.like microcontroller,bluetooth module ethernet module internt,web technology

Copyright © 2021 · Genesis Sample on Genesis Framework · WordPress · Log in

  • Education
  • Computer Technology