Flower Prediction Report2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

SRI VENKATESWARA COLLEGE OF ENGINEERIG & TECHNOLOGY

Accredited by NAAC with ''A‟ Grade,(Approved by AICTE,


Affiliated to JNTUV,NH-5, ETCHERLA- 532410, SRIKAKULAM
(Dist.), ANDHRA PRADESH

2020-2024

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

An Internship report On

Flower Classification Using Machine Learning With Python


(Submitted in partial fulfillment for the award of degree)
OF
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE AND ENGINEERING
Submitted by

PALLI BHARGAVI
20MT1A0531

Internship Guide Head of the Department


P.S.S.V.M.RAJU, M. Tech ,Ph.D S.BHASKAR RAO M.Tech,Ph.D

i
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
Accredited by NAAC with ''A‟ Grade,(Approved by AICTE, Affiliated to
JNTUV,NH-5,ETCHERLA- 532410, SRIKAKULAM (Dist.),
ANDHRA PRADESH

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE
This is to certify that the Internship Report on “FLOWER CLASSIFICATION USING
MACHINE LEARNING WITH PYTHON” by P.BHARGAVI(20MT1A0531) is an
authentic work that has been carried out by him under my supervision and guidance Of
Mr.,S.BHASKAR RAO M.Tech,Ph.D is submitted in partial fulfillment for the
requirements for the award of the Bachelor of technology in DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING at Sri Venkateshwara College of
Engineering and Technology during the academic year 2020- 2024.

Internship Guide Head of the department

P.S.S.V.M RAJU M. Tech ,Ph.D S.BHASKAR RAO M Tech,Ph.D

ii
ACKNOWLEDGEMENT

We would like to thank our beloved and respected principal Dr. S.C.V.RAMANA MURTY NAIDU and our
beloved Head of the Department, Mr. S.BHASKAR RAO for providing a great support to us in completing our
project and for giving us an opportunity of doing the project.

It gives an immense pleasure to express deep sense of gratitude to our guide Mr.P.S.S.V.M RAJU
department of computer science and engineering for their whole hearted and valuable guidance throughout the
project. Without their sustained and sincere effort, this project wouldn’t take this shape. They encouraged and
helped us to overcome various difficulties of our project.

We would like to sincerely thank all the faculty members of the DEPARTMENT OF COMPUTER
SCIENCE AND ENGINEERING for their direct or indirect support for helping us in completion of this
project.

Finally we would like to thank all of our staff members and supporting staff for their continuous help and
encouragement.

PALLI BHARGAVI
[20MT1A0531]

iii
ABSTRACT

Beauty is incomplete without flower. India is the land of flower. In our everyday life, On the
way of walking, beside the rail line or in our garden we used to see a lot of flower. But in most
case we have no knowledge about that flower. Even we don’t know its name. In that case we
choose this idea to research and develop our project. That will introduce people about that
unknown flower which they see but don't know about that. Our developed application
recognizes the flower in real time by using mobile camera. This project is an attempt at using
the concepts of neural networks to create an image classifier by Tensorflow on Android
platform. Convolutional neural networks are a popular realm of machine learning, and are
widely used in image classification. So that we choose this topic to research about image
classification by CNN and Tensorflow. Though we developed an application of our research
project but we have a lot of plan to do more research to upgrade our system.

iv
TABLE OF CONTENTS
CONTENTS PAGE
Acknowledgement iii
Abstract iv
CHAPTER 1: INTRODUCTION 1-2
1.1 Introduction 1
1.2 Motivation 1
1.3 Rationale of the Study 1
1.4 Research Questions 2
1.5 Expected Outcome 2
CHAPTER 2: BACKGROUND 3-5
2.1 Introduction 3
2.2 Related Works 3
2.3 Research Summary 4
2.4 Scope of the Project 4
2.5 Challenges 5
CHAPTER3:RESEARCH METHODOLOGY & IMPLEMENTATION 6-12
3.1 Introduction to Machine Learning 6
3.2 Convolutional Neural Network 7
3.3 Design of Dataset 8
3.4 Data Collection Procedure 9
3.5 Statistics of Data 10
3.6 Implementation Requirements 11
3.7 Implementation of Network Design 11
3.8 Design Development 12
CHAPTER 4: EXPERIMENTAL RESULTS AND DISCUSSION 13-18
4.1 Experimental Input And Datasets 13
4.2 Experiment output 13
4.3 Experiment summary 18
CHAPTER 5: SUMMARY, CONCLUSION RECOMMENDATION 19-20
AND IMPLICATION FOR FUTURE RESEARCH
5.1 Summary of the Study 19
5.2 Future work 20
5.3 Conclusion 20

v
vi
CHAPTER 1
1.1 INTRODUCTION

Flower is a very important part of nature. Mostly we identify a plant through flower. Experienced
botanists do this identification of flower but a naive person will have to consult flower guidebooks
or browse any relevant web pages on the Internet through keywords searching. Our system can
recognizes the flower in real time using mobile camera. Currently this Android app can identify
around 10 flowers. Most important thing is that this app can fully works in offline. We are
continuously working to add more flowers to identify. Everyday we see a huge number of flower
species in our house, parks, roadsides, in farms, on our rooftop but we have no knowledge of that
flower species or their origin. Even we have no idea about its name. There are several guidebooks
for flowers knowledge but it becomes quite difficult to find the name when have the picture. Even
the Internet sometimes is not useful. But it is quite difficult for human brain to memorize all the
species they see. Even some flower is similar to look at. This application recognizes the flower in
real time by using mobile camera.
The purpose of this project is to use Tensorflow, an open-source dataflow and machine learning
library, to build an image classifying Convolutional Neural Network (CNN) for classifying the flower
image. Tensorflow, in addition to providing developers a simple way to build neural network layers,
can also be run on mobile platforms such as Android. The ultimate goal of this project is to design
and optimize a convolutional neural network for use with flower classification, and eventually build
a simple classification app for mobile devices around the trained network. The mobile app will allow
users to try and classify flowers while outdoors or offline.
1.2 MOTIVATION
There have a special motivation behind this research and project work. Me and my cousin used to
walk along the railway line in afternoon. That time we used to observed a lot of unknown flower
around the area. We were curious about that flowers but we could not recognize it. That time we
discussed about an idea to make a system which can identify our desired flower automatically. Since
then our journey has started and dream have come true now. We developed an android application
which can introduce people about that unknown flower which they see but don't identify that. Hope
our research & developed project will be helpful for the curious people.
1.3 RATIONALE OF THE STUDY
At the primary stage of our journey looked for research paper and tools related with our idea. Even
we deeply searched the Internet to find if there any system that can identify flower automatically.
But unfortunately we found very few resources. There exists a handful papers in there. That time
we take this as a challenge and start our research to make a system which can recognize flower in
1
real time. After a lot of hard work our project now come to light finally. Now our application can
identify around 10 Indian common flowers with some foreign flowers also. The most unique
feature of project is it can identify flower in real time. For some kind of flower it provides 100%
accuracy rate. Different flower is same to look at we know. If this occur during identification time
that time our application shows 3 or 2 most similar result. Convolutional Neural Network (CNN)
and Image Classification technique used in our project which can identify flower with the
confidence level from 0 to 1. We use Tensorflow an open source library for training process.
1.4 RESEARCH QUESTIONS
1.Can a machine identify flower before the human eye?
2.Can a system recognize different color of same flower using machine learning? Ex: Pink Rose / White
Rose
3. Is convolutional neural network (CNN) technique is perfect to identify flower accurately?
1.5 EXPECTED OUTCOME
1.Identify flower in real time which include native Indian flowers along with some foreign flowers
also.

2.Produce a convolutional neural network which is capable correctly classifying images of flowers
with an average confidence level of 95% or more. Sometimes it provides 100% accuracy rate for
some kind of flowers.
3.Collected a dataset of over 5000 images of flowers using their genus-species classification as the
Google Image search term.
The following figure showing the output of the application which identify Rose with highest confidence
value by using mobile camera.
Sun Flower Identification with highest confidence value

2
CHAPTER 2
BACKGROUND
2.1 INTRODUCTION
Since the invention of computer, it has begun to change our daily life. It improves the quality of our
lives. An impressive idea is to let a computer think and learn as like human being. Basically machine
learning developed skills to develop the computer itself with the knowledge given. There are many
applications of CNNs, one of the most popular of which is image classification, and CNNs have even
been used specifically for flower classification. These flower classification neural networks, however
generally use datasets with very specific details. Thus, this project is explorative and aimed at
learning how to design a neural network using Tensorflow, but ultimately has practical applications
for developers, botanists, or nature enthusiasts. The dataset used for training was collected through
Google Images, and the images of the plants themselves are very general, rather than of specific
characteristics of the plants, and typically include most of the identifying characteristics of a flower.
2.2 RELATED WORKS
Convolutional Neural Network (CNN) and Image Classification is the most used technique in
machine learning. On the other hand Tensorflow an open source library developed by Google Brain
team is the hot topic nowadays in the field of machine learning. There are some good publications
of Tensorflow. But It is very little compared to the importance. In the following overview of the
related works, we try to cover the works that are mostly related to ours to our best knowledge. Image
Classification by Tensorflow is a relatively new topic. But the idea of reliable classification has made
it increasingly important.
Recent history of modern software technology we can see lots of use of machine learning and image
processing in our day to life. Like Police using face detection technology to identify criminal.
Facebook using AI technology to match your face ID with any photo of you that has been uploaded.
Pinterest use this technology to find similar photos. Traffic police also find out vehicles by using this
technology. There is so many big projects on this topic, those are given below,

>>PICTURE THIS

PictureThis application feature graphic image


Among the popular software This is a Plant identification software developed by “Glority Software
limited” running on both Android and IOS. This Software let you identify plant by taking a picture
with 90% accuracy rate less than a second.

3
» PLANTSNAP

PlantSnap application feature graphic image

This is also a popular software like PictureThis, developed by PlantSnap INC. This software let
us to identify plants, flowers, cacti, mushrooms etc. by taking a picture of that plant. There are
585,000 species of plants and trees in their database. So their accuracy rate is 90% accurate.
2.3 RESEARCH SUMMARY
The purpose of this project is to use Tensorflow, an open-source dataflow and machine learning
library, to build an image classifying Convolutional Neural Network (CNN) for classifying the flower
image. Tensorflow, in addition to providing developers a simple way to build neural network layers,
can also be run on mobile platforms such as Android. The ultimate goal of this project is to design
and optimize a convolutional neural network for use with flower classification, and eventually build
a simple classification app for mobile devices around the trained network. The mobile app will allow
users to try and classify flowers while outdoors or offline. After examining, inquiring, researching
and comparing all the related works on Flower Identification, we come to have different and many
types of conclusion. First of all, none of them are using real time object detection and identification.
All of them are just stuck into by taking picture of object and search through their database to identify
the object. Secondly is accuracy rate, most of the big project hit the accuracy rate up to 90% so they
say. But the community feedback shows the different color. Users complain about the miss detection
of plants and less information about it. It also take long time for analyzing and searching their
database. Because of our real time flower identification, it is more like instant detection of flower
2.4 SCOPE OF THE PROJECT
Developers
The project is complete ready for practical use, someone who wishes to learn the basics of CNNs
and Tensorflow, substituting their own classes. The project is essential for anyone that wants to
improve their project. It have scope to improve both the dataset and the CNN architecture, however,
this will require more research and knowledge of CNN design. Additionally, someone who is

4
interested in Tensorflow and Android development or front end development can be benefited from
this work.
Scientist or Botanist

This research and project will be helpful for botanists or biologists, although any scientist would
likely wish to use their unique dataset. The project would most likely be useful to scientists for
classifying large amounts of data and generating statistics for the dataset. Using our Android
application Botanists or other scientists dealing with flowers to identify easily.

Traveler or Nature Enthusiasts


Our developed project will be much helpful while spending time outdoors to identify flowers by a
mobile application. This application works completely in offline which use mobile camera to identify
flowers. It will be really helpful for Traveler, Hiker and Nature Enthusiasts.
2.5 CHALLENGES
Duplicate flower identification is the main challenge of our project. Some flowers are same to look at by size
and shape. That time it is so tough to provide the accurate result. We are continue our research to solve this
problem.
Another challenge is to identify same flower of different specific color. Ex- White Rose, Pink
Rose. This is a tough work to identify color using convolutional neural network. But we take it as a
challenge.
Other challenge is achieving accurate data. In the market of false and duplicate data, it is very
hard to get all of the things right. But we are trying are heart and soul to do better.

5
CHAPTER 3
RESEARCH METHODOLOGY AND IMPLEMENTATION

3.1 BASIC INTRODUCTION TO MACHINE LEARNING


In Artificial Intelligence Learning is a very important feature. Many scientists tried to give a proper
definition for learning. Many computer scientists, sociologists, logicians and others discussed about
this for a long time. Some scientists think that learning is an adaptive skill that can perform the same
process better later on (Simon 1987). Others claim that learning is a process of collecting knowledge
(Feigenbaum 1977). Although there is no definite definition for learning skills, we still have to define
machine learning. In general, machine learning has to be identified on how to improve the computer
algorithm automatically through experience (Mitchell 1997).
Machine learning is one of the important field of Artificial Intelligence. At the beginning of
development of Artificial Intelligence (AI), the system does not have a thorough learning ability so
the whole system is not perfect. For instance when the computer faces problems, it can not be self-
adjusting. Moreover, the computer cannot automatically collect and discover new knowledge.
Therefore, computer only can conducted by already existing truths. It does not have the ability to
discover a new logical theory, rules and so on.

Environment Learning Knowledge Execution

Learning System Structure


Machine Learning
Machine learning is a subset of AI, which enables the machine to automatically learn from data, improve
performance from past experiences, and make predictions. Machine learning contains a set of algorithms that
work on a huge amount of data. Data is fed to these algorithms to train them, and on the basis of training, they
build the model & perform a specific task.

1
TYPES OF MACHINE LEARNING
These ML algorithms help to solve different business problems like Regression, Classification, Forecasting,
Clustering, and Associations, etc.
Based on the methods and way of learning, machine learning is divided into mainly four types, which are:
1. Supervised Machine Learning
2. Unsupervised Machine Learning
3.Semi-Supervised Machine Learning
4.Reinforcement Learning

2
Categories of Supervised Machine Learning
Supervised machine learning can be classified into two types of problems, which are given below:
 Classification
 Regression
Classification:
Classification algorithms are used to solve the classification problems in which the output variable is categorical,
such as "Yes" or No, Male or Female, Red or Blue, etc. The classification algorithms predict the categories
present in the dataset. Some real-world examples of classification algorithms are Spam Detection, Email filtering,
etc.
Some popular classification algorithms are given below:
Random Forest Algorithm
Decision Tree Algorithm
Logistic Regression Algorithm
Support Vector Machine Algorithm
Regression:
Regression algorithms are used to solve regression problems in which there is a linear relationship between input
and output variables. These are used to predict continuous output variables, such as market trends, weather
prediction, etc.
Some popular Regression algorithms are given below:
Simple Linear Regression Algorithm
Multivariate Regression Algorithm
Decision Tree Algorithm
Lasso Regression
Advantages of Supervised Learning:
 Since supervised learning work with the labelled dataset so we can have an exact idea about the
classes of objects.
 These algorithms are helpful in predicting the output on the basis of prior experience.
Disadvantages of Supervised Learning:
 These algorithms are not able to solve complex tasks.
 It may predict the wrong output if the test data is different from the training data.
 It requires lots of computational time to train the algorithm.
Applications of Supervised Learning:
Some common applications of Supervised Learning are given below:
Image Segmentation:
Supervised Learning algorithms are used in image segmentation. In this process, image classification is
performed on different image data with pre-defined labels.

3
Medical Diagnosis:
Supervised algorithms are also used in the medical field for diagnosis purposes. It is done by using medical
images and past labelled data with labels for disease conditions. With such a process, the machine can identify a
disease for the new patients.
Fraud Detection
Supervised Learning classification algorithms are used for identifying fraud transactions, fraud customers, etc.
It is done by using historic data to identify the patterns that can lead to possible fraud.
Spam detection
In spam detection & filtering, classification algorithms are used. These algorithms classify an email as spam or
not spam. The spam emails are sent to the spam folder.
Speech Recognition
Supervised learning algorithms are also used in speech recognition. The algorithm is trained with voice data,
and various identifications can be done using the same, such as voice-activated passwords, voice commands, etc
2. Unsupervised Machine Learning:
Unsupervised learning is different from the Supervised learning technique; as its name suggests, there is no need
for supervision. It means, in unsupervised machine learning, the machine is trained using the unlabeled dataset,
and the machine predicts the output without any supervision.
In unsupervised learning, the models are trained with the data that is neither classified nor labelled, and the model
acts on that data without any supervision.
The main aim of the unsupervised learning algorithm is to group or categories the unsorted dataset according to
the similarities, patterns, and differences. Machines are instructed to find the hidden patterns from the input
dataset.
Let's take an example to understand it more preciously; suppose there is a basket of fruit images, and we input it
into the machine learning model. The images are totally unknown to the model, and the task of the machine is to
find the patterns and categories of the objects.
So, now the machine will discover its patterns and differences, such as colour difference, shape difference, and
predict the output when it is tested with the test dataset.
Categories of Unsupervised Machine Learning
Unsupervised Learning can be further classified into two types, which are given below:
 Clustering
 Association
1) Clustering:
The clustering technique is used when we want to find the inherent groups from the data. It is a way to group the
objects into a cluster such that the objects with the most similarities remain in one group and have fewer or no
similarities with the objects of other groups. An example of the clustering algorithm is grouping the customers
by their purchasing behaviour.
Some of the popular clustering algorithms are given below:
K-Means Clustering algorithm
Mean-shift algorithm

4
DBSCAN Algorithm
Principal Component Analysis
Independent Component Analysis
2) Association
Association rule learning is an unsupervised learning technique, which finds interesting relations among variables
within a large dataset. The main aim of this learning algorithm is to find the dependency of one data item on
another data item and map those variables accordingly so that it can generate maximum profit. This algorithm is
mainly applied in Market Basket analysis, Web usage mining, continuous production, etc.
Some popular algorithms of Association rule learning are Apriori Algorithm, Eclat, FP-growth algorithm.
Advantages of Unsupervised Learning Algorithm:

 These algorithms can be used for complicated tasks compared to the supervised ones because these
algorithms work on the unlabeled dataset.
 Unsupervised algorithms are preferable for various tasks as getting the unlabeled dataset is easier as
compared to the labelled dataset.
Disadvantages of Unsupervised Learning Algorithm:
 The output of an unsupervised algorithm can be less accurate as the dataset is not labelled, and algorithms
are not trained with the exact output in prior.
 Working with Unsupervised learning is more difficult as it works with the unlabelled dataset that does
not map with the output.

Applications of Unsupervised Learning:


Network Analysis: Unsupervised learning is used for identifying plagiarism and copyright in document network
analysis of text data for scholarly articles.
Recommendation Systems: Recommendation systems widely use unsupervised learning techniques for
building recommendation applications for different web applications and e-commerce websites.
Anomaly Detection: Anomaly detection is a popular application of unsupervised learning, which can identify
unusual data points within the dataset. It is used to discover fraudulent transactions.
Singular Value Decomposition: Singular Value Decomposition or SVD is used to extract particular information
from the database. For example, extracting information of each user located at a particular location.
3. Semi-Supervised Learning
Semi-Supervised learning is a type of Machine Learning algorithm that lies between Supervised and
Unsupervised machine learning. It represents the intermediate ground between Supervised (With Labelled
training data) and Unsupervised learning (with no labelled training data) algorithms and uses the combination of
labelled and unlabeled datasets during the training period.

5
Although Semi-supervised learning is the middle ground between supervised and unsupervised learning and
operates on the data that consists of a few labels, it mostly consists of unlabeled data. As labels are costly, but
for corporate purposes, they may have few labels. It is completely different from supervised and unsupervised
learning as they are based on the presence & absence of labels.
To overcome the drawbacks of supervised learning and unsupervised learning algorithms, the concept of Semi-
supervised learning is introduced. The main aim of semi-supervised learning is to effectively use all the available
data, rather than only labelled data like in supervised learning. Initially, similar data is clustered along with an
unsupervised learning algorithm, and further, it helps to label the unlabeled data into labelled data. It is because
labelled data is a comparatively more expensive acquisition than unlabeled data.
We can imagine these algorithms with an example. Supervised learning is where a student is under the supervision
of an instructor at home and college. Further, if that student is self-analysing the same concept without any help
from the instructor, it comes under unsupervised learning. Under semi-supervised learning, the student has to
revise himself after analyzing the same concept under the guidance of an instructor at college.
Advantages of Semi-supervised Learning:
 It is simple and easy to understand the algorithm.
 It is highly efficient.
 It is used to solve drawbacks of Supervised and Unsupervised
Learning algorithms.
Disadvantages of Semi-supervised Learning:
 Iterations results may not be stable.
 We cannot apply these algorithms to network-level data.
 Accuracy is low.
4. Reinforcement Learning
Reinforcement learning works on a feedback-based process, in which an AI agent (A software component)
automatically explore its surrounding by hitting & trail, taking action, learning from experiences, and improving
its performance. Agent gets rewarded for each good action and get punished for each bad action; hence the goal
of reinforcement learning agent is to maximize the rewards.
In reinforcement learning, there is no labelled data like supervised learning, and agents learn from their
experiences only.
The reinforcement learning process is similar to a human being; for example, a child learns various things by
experiences in his day-to-day life. An example of reinforcement learning is to play a game, where the Game is
the environment, moves of an agent at each step define states, and the goal of the agent is to get a high score.
Agent receives feedback in terms of punishment and rewards.
Due to its way of working, reinforcement learning is employed in different fields such as Game theory, Operation
Research, Information theory, multi-agent systems.
A reinforcement learning problem can be formalized using Markov Decision Process(MDP). In MDP, the agent
constantly interacts with the environment and performs actions; at each action, the environment responds and
generates a new state.
Categories of Reinforcement Learning
Reinforcement learning is categorized mainly into two types of methods/algorithm
Positive Reinforcement Learning: Positive reinforcement learning specifies increasing the tendency that the
required behaviour would occur again by adding something. It enhances the strength of the behaviour of the

6
agent and positively impacts it.
Negative Reinforcement Learning: Negative reinforcement learning works exactly opposite to the positive RL.
It increases the tendency that the specific behaviour would occur again by avoiding the negative condition.

Real-world Use cases of Reinforcement Learning


Video Games:
RL algorithms are much popular in gaming applications. It is used to gain super-human performance. Some
popular games that use RL algorithms are AlphaGO and AlphaGO Zero.
Resource Management:
The "Resource Management with Deep Reinforcement Learning" paper showed that how to use RL
in computer to automatically learn and schedule resources to wait for different jobs in order to minimize average
job slowdown.
Robotics:
RL is widely being used in Robotics applications. Robots are used in the industrial and manufacturing area, and
these robots are made more powerful with reinforcement learning. There are different industries that have their
vision of building intelligent robots using AI and Machine learning technology.
Text Mining:
Text-mining, one of the great applications of NLP, is now being implemented with the help of Reinforcement
Learning by Salesforce company.

Advantages of Reinforcement Learning:

 It helps in solving complex real-world problems which are difficult to be solved by general techniques. o
The learning model of RL is similar to the learning of human beings; hence most accurate results can be
found.
 Helps in achieving long term results.
Disadvantages of Reinforcement Learning:
 RL algorithms are not preferred for simple problems.
 RL algorithms require huge data and computations.
 Too much reinforcement learning can lead to an overload of states which can weaken the results.
3.2 CONVOLUTIONAL NEURAL NETWORK
Convolutional neural networks are a class of machine learning networks which are commonly applied to
image visualization problems such as classification. CNNs were inspired by the connections of the
neurons and synapses in the brain. The design of these networks is made up of series of

7
convolutional,pooling, and fully connected layers. The convolutional layer does what its name describes,
it applies a number of convolutional filters to the input images in order to acquire the learning parameters
for the network. Pooling layers are placed in between convolutional layers, and are used to reduce the
number of parameters used for learning, and thus reduce the computation required. Finally, fully
connected layers are full connections to the previous layer, rather than the small window the
convolutional layers are connected to in the input. Convolutional neural networks are commonly used
for image classification, however, there are limitations to this application. A human can identify the
contents of certain images much more quickly than a computer, but CNNs have proven to have a 97.6%
success rate when applied to facial recognition.
The following figure showing the typical design of convolutional neural network.

Typical CNN design

8
3.3 DESIGN OF DATASET

The diagram of dataset design which shows different step of data collection and dataset handler.

Shapla
Shapla Google Image
Noyontara Downloader Noyontara
Aporajita
---
Aporajita

CNN Dataset Handler

Shapla Noyontara Aporajita

9
3.4 DATA COLLECTION PROCEDURE
There are a number of existing datasets which have images of specific flowers. These datasets were
generally collected for very specific uses with neural networks that were designed to classify flowers
based on certain characteristics. The dataset for this project was produced by searching Google Images
using a Python script adapted from a web-crawler created by Kaggle.. As a result, the images of the
flowers are a diverse collection of plants in their natural setting. This adds the benefit of training the
network for use outdoors. The script had to be modified so that it would receive the list of search
keywords from a text file. Google Image Downloader is also helpful to collect specific flower data on
windows platform. The search keywords for the dataset are a long list of flower observations in India.
The search keywords use the full genus-species classification in order to increase the quality of the
dataset. For example, rather than searching for the word
“Gardenia”, which would produce undesired images, the preferred keyword would be “Gardenia
jasminoides”. The labels for classification, however, are grouped by genus so that each class has 400 to
over 1000 images.
The following figure shows the sample dataset image of Sun Flower.

Dataset of Sun Flowers

10
3.5 STATISTICS OF DATA
The following table contains the statistics of raw data

Flower Name Amount of Training


Image
Sun Flower 734
Daisy 769
Dandelion 1052
Rose 784
Tulip 984
Statistics of Raw Data
3.6 IMPLEMENTATION REQUIREMENTS (Minimum)
Software
 Windows / Linux / Mac OS
 Python pip package / Anaconda
 Tensorflow
 Android Studio
Hardware
 Intel i3 Processor
 4 GB RAM
 1TB Hard Disk
3.7 IMPLEMENTATION OF NETWORK DESIGN
Convolutional Layer 1
PROGRAM FOR CNN CLASSIFIER:
from tkinter import messagebox
from tkinter import *
from tkinter import simpledialog
import tkinter
from tkinter import filedialog
from tkinter.filedialog import askopenfilename import
cv2 import random import numpy as np
from keras.utils.np_utils import to_categorical from
keras.layers import MaxPooling2D
from keras.layers import Dense, Dropout, Activation, Flatten from
keras.layers import Convolution2D from keras.models import Sequential
from keras.models import model_from_json import pickle import os
main.title("Non-Binary Image Classification using Convolution Neural
Networks") main.geometry("1300x1200")

11
global filename global
classifier global
labels
def readLabels(filename):
global labels labels = [] for root, dirs, directory in
os.walk(filename): for j in range(len(directory)): name
= os.path.basename(root) if name not in labels:
labels.append(name)
def uploadDataset(): global
filename global labels
labels = []
filename = filedialog.askdirectory(initialdir=".")
pathlabel.config(text=filename) text.delete('1.0', END)
text.insert(END,filename+" loaded\n\n"); readLabels(filename)
text.insert(END,"Types of flowers found in dataset is :
"+str(labels)+"\n")
def trainCNN():
global classifier text.delete('1.0', END)
X_train = np.load('model/X.txt.npy') Y_train =
np.load('model/Y.txt.npy') text.insert(END,"CNN is training
on total images :
"+str(len(X_train))+"\n")
if os.path.exists('model/model.json'):
with open('model/model.json', "r") as json_file:
loaded_model_json = json_file.read() classifier =
model_from_json(loaded_model_json)

classifier.load_weights("model/model_weights.h5")
classifier._make_predict_function()
print(classifier.summary()) f = open('model/history.pckl',
'rb') data = pickle.load(f)
f.close() acc =
data['accuracy'] accuracy =
acc[9] * 100
text.insert(END,"CNN Flower
Training Model Prediction
Accuracy = "+str(accuracy)) else:
classifier = Sequential()
classifier.add(Convolution2D(32, 3, 3, input_shape = (64,
64, 3), activation = 'relu')) classifier.add(MaxPooling2D(pool_size = (2,
2))) classifier.add(Convolution2D(32, 3, 3, activation =
'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Flatten())
classifier.add(Dense(output_dim = 256, activation =
'relu')) classifier.add(Dense(output_dim = 5, activation =

12
'softmax')) print(classifier.summary())
classifier.compile(optimizer = 'adam', loss =
'categorical_crossentropy', metrics = ['accuracy']) hist =
classifier.fit(X_train, Y_train, batch_size=16, epochs=10, shuffle=True,
verbose=2) classifier.save_weights('model/model_weights.h5')
model_json = classifier.to_json() with open("model/model.json", "w")
as json_file:
json_file.write(model_json)
f = open('model/history.pckl', 'wb') pickle.dump(hist.history, f)
f.close() f = open('model/history.pckl',
'rb') data = pickle.load(f)
f.close()
acc = data['accuracy'] accuracy =
acc[9] * 100
text.insert(END,"CNN Flower Training Model Prediction Accuracy =
"+str(accuracy)
def classifyFlower():
filename = filedialog.askopenfilename(initialdir="testImages") image =
cv2.imread(filename)
img = cv2.resize(image, (64,64))
im2arr = np.array(img)
im2arr = im2arr.reshape(1,64,64,3)
img = np.asarray(im2arr)
img = img.astype('float32')
img = img/255 preds = classifier.predict(img)
predict = np.argmax(preds)
img = cv2.imread(filename)
img = cv2.resize(img, (400,400))
cv2.putText(img, 'Flower Classified as : '+labels[predict],
(10, 25), cv2.FONT_HERSHEY_SIMPLEX,0.7, (255, 0, 0), 2) cv2.imshow('Flower
Classified as : '+labels[predict], img) cv2.waitKey(0)
def close():
main.destroy()
font = ('times', 16, 'bold')
title = Label(main, text='Non-Binary Image Classification using
Convolution Neural Networks',anchor=W, justify=CENTER)
title.config(bg='yellow4', fg='white') title.config(font=font)
title.config(height=3, width=120) title.place(x=0,y=5)
font1 = ('times', 14, 'bold')
upload = Button(main, text="Upload Flowers Dataset",
command=uploadDataset) upload.place(x=50,y=100)
upload.config(font=font1)
pathlabel = Label(main)
pathlabel.config(bg='yellow4', fg='white')
pathlabel.config(font=font1) pathlabel.place(x=50,y=150)

13
markovButton = Button(main, text="Train Dataset with Flower Images Using CNN",
command=trainCNN) markovButton.place(x=50,y=200) markovButton.config(font=font1)
lexButton = Button(main, text="Upload Test Image & Classify Flower
Name", command=classifyFlower) lexButton.place(x=50,y=250)
lexButton.config(font=font1)
predictButton = Button(main, text="Exit", command=close)
predictButton.place(x=50,y=300) predictButton.config(font=font1)
font1 = ('times', 12, 'bold') text=Text(main,height=15,width=78)
scroll=Scrollbar(text)
text.configure(yscrollcommand=scroll.set)
text.place(x=450,y=100) text.config(font=font1)
main.config(bg='magenta3') main.mainloop()
Training Step
{"class_name": "Sequential", "config": {"name": "sequential_1",
"layers": [{"class_name": "Conv2D", "config": {"name": "conv2d_1",
"trainable": true, "batch_input_shape": [null, 64, 64, 3], "dtype":
"float32", "filters": 32, "kernel_size": [3, 3], "strides": [1, 1],
"padding": "valid", "data_format": "channels_last",
"dilation_rate": [1, 1], "activation": "relu", "use_bias": true,
"kernel_initializer": {"class_name": "VarianceScaling", "config":
{"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}},
"bias_initializer": {"class_name": "Zeros", "config": {}},
"kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer":
null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name":
"MaxPooling2D", "config":
{"name": "max_pooling2d_1", "trainable": true, "dtype": "float32",
"pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format":
"channels_last"}}, {"class_name": "Conv2D", "config": {"name": "conv2d_2",
"trainable": true, "dtype":
"float32", "filters": 32, "kernel_size": [3, 3], "strides": [1, 1],
"padding": "valid", "data_format": "channels_last",
"dilation_rate": [1, 1], "activation": "relu", "use_bias": true,
"kernel_initializer": {"class_name": "VarianceScaling", "config":
{"scale": 1.0, "mode": "fan_avg", "distribution": "uniform",
"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}},
"kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer":
null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name":
"MaxPooling2D", "config":
{"name": "max_pooling2d_2", "trainable": true, "dtype": "float32",
"pool_size": [2, 2], "padding": "valid", "strides": [2, 2],
"data_format": "channels_last"}}, {"class_name": "Flatten", "config":
{"name": "flatten_1", "trainable": true, "dtype":
"float32", "data_format": "channels_last"}}, {"class_name":

14
"Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32",
"units": 256, "activation": "relu", "use_bias": true, "kernel_initializer":
{"class_name": "VarianceScaling", "config":
{"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}},
"bias_initializer": {"class_name": "Zeros", "config": {}},
"kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer":
null, "kernel_constraint": null,
"bias_constraint": null}}, {"class_name": "Dense", "config":
{"name": "dense_2", "trainable": true, "dtype": "float32", "units": 5,
"activation": "softmax", "use_bias": true, "kernel_initializer":
{"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode":
"fan_avg", "distribution": "uniform", "seed": null}},
"bias_initializer": {"class_name": "Zeros", "config": {}},
"kernel_regularizer": null, "bias_regularizer": null,
"activity_regularizer": null, "kernel_constraint": null,
"bias_constraint": null}}]}, "keras_version": "2.3.1", "backend":
"tensorflow"}
3.8 DESIGN DEVELOPMENT
The initial step of this project was to research the available machine learning libraries, convolutional neural
network design, and collect datasets. Though there exist some other libraries, but Tensorflow was chosen
because there are many tutorials and documentation for the library. After began to have a basic
understanding of the Tensorflow library, we retrained the MobileNet model with our own dataset, which
proved to be very successful in testing, however, the goal of this project was to learn how to develop and
optimize a neural network. The initial designs of the CNN for this project were based on several different
tutorials about how to use Tensorflow to design an image classifier. The next step was to begin modifying
the initial network to try and find a design that worked for the application of this project. The next step was
implementation of android app using Android Studio. Some open source code of Tensorflow collected from
github which needed in our implementation work. Final Step was set up the pb file and label file with the
application
The design of CNN which we tested is being submit as a deliverable for this project. This model also was
trained using the dataset at the genus-species level, which uses approximately 700 images average per
class, which is almost enough. But we are working to add more images per class. This model is currently
being trained and tested. The parameters of the network such as number of training steps, output directory,
and image input directory can all be specified, however, their defaults will place all the output directory
in the current working directory. The input image directory must be specified, and the contents of the
directory must be folders of images in tf files folder. The Tensorflow trainer will generates two text files:
one containing the labels for the classifier, and the other lists which images were selected for
training,testing, and validation which called pb file. The classifier uses these to read result for each image
classification and show the output result.

15
CHAPTER 4
EXPERIMENTAL RESULTS AND DISCUSSION

4.1 EXPERIMENTAL INPUT AND DATASETS

In this project we have used FLOWERS dataset from KAGGLE website and then used CNN classifier to train
those flowers and to generate CNN model. After training model we can apply any new test image on that model
to classify name of flowers. Below screen shots showing various flowers used to train CNN

In above screen each folder contains its type of flowers and in each folder nearly 1000 images are there and in
below screen we can see images from sunflower folder

4.2 EXPERIMENT OUTPUT


To run project double click on ‘run.bat’ file to get below screen

In above screen click on ‘Upload Flowers Dataset’ button to load flowers folder

16
In above screen selecting and uploading ‘flowers’ folder and then click on ‘Select Folder’ button to load dataset
and to get below screen
In above screen we can see dataset loaded and in dataset application found 5 different types of flowers and now
click on ‘Train Dataset with Flower Images Using CNN’ button to start CNN training on loaded dataset and to
get below screen of CNN details

In above screen we can see CNN trained on total 4323 images and the trained model has prediction accuracy
percentage as 99.09. Now in below console screen we can see CNN model layer details
In above screen to train CNN we have used CONV2D network and we create multiple layers with different
image sizes as 62 X 62, 31 X 31 and many more. Now go back to application screen and then click on ‘Upload
Test Image & Classify Flower Name’ button to upload test image and predict/classify flower name
In above screen while uploading test image I select 1.jpg’ and then click on ‘Open’ button to get below result

17
In above screen we can see flower name predicted as ‘daisy’ and now close above image and then test another
image

In above screen selecting and uploading 3.jpg file and then click on ‘Open’ button to get below result

In above screen application predicted flower name as rose. Similarly you can upload any image and classify
name
4.3 EXPERIMENT SUMMARY
Our developed application can identify local Indian flowers with some foreign flowers also. We deeply focused
on the accuracy level. The accuracy rate depends on the amount of data. So that we use more images with
different angel to improve the confidence level. Currently some flower identify with 100% confidence level. It
is one of the success of our research and project. We used almost 700 images for per flowers for training step.
The dataset contains around 4,400 flower images.

18
19
5.2 FUTURE WORK
This project has plenty of room for future work, by myself or a future interested student.
1. Improved CNN design. There much more research and practice is needed to optimize the design.
2. Improve the dataset and add more data.
3. Specific Identification of duplicate flower which is same to look at.
4. We have plan to release this app on Google Playstore.
5.3 CONCLUSIONS
With the rapid development of technology, AI is being used in various fields. Machine learning is
the most basic method to achieve AI. This research describes the work principle of machine
learning and an application of machine learning. At the beginning of development of Artificial
Intelligence (AI), the AI system does not have a thorough learning ability so the whole system is
not perfect. For instance when the computer faces problems, it can not be self-adjusting. Moreover,
the computer cannot automatically collect and discover new knowledge. Therefore, computer only
can conducted by already existing truths. It does not have the ability to discover a new logical
theory, rules and so on. The ultimate goal of this project is to design and optimize a convolutional
neural network for use with flower classification, and eventually build a simple classification app
for mobile devices around the trained network. The mobile app will allow users to try and classify
plants while outdoors or offline. We will continue our research to make the system more efficient.
36
21
38

You might also like