Javatpoint Logo
Javatpoint Logo

Flower Recognition Using Convolutional Neural Network


Flowers have always been a source of fascination and inspiration for humans. The beauty and diversity of the natural world are something that has been celebrated in art, literature, and science for centuries. With the advancements in machine learning and computer vision, we now can recognize and classify different species of flowers automatically. We will talk about the application of convolutional neural networks (CNNs) for flower recognition in this post.

What is a Convolutional Neural Network (CNN)?

Convolutional Neural Networks (CNNs) are a particular kind of neural network that are made for applications requiring image recognition. They are made up of several layers that work together to extract and learn features from images. CNNs are particularly good at recognizing patterns in images, which makes them ideal for tasks such as object recognition, face detection, and, of course, flower recognition.

In the realm of computer vision, convolutional neural networks (CNNs) have gained popularity in recent years. They are a type of neural network that is specifically designed for image recognition tasks, but they can also be used for other types of data, such as audio and text.

A CNN's basic design is made up of several layers, each of which serves a particular purpose. Typically, a convolutional layer serves as the initial layer. It applies several filters to the input image in order to extract features. The filters are small matrices of weights that slide over the input image, and each filter produces an output that represents the presence of a particular feature in the input image.

After the convolutional layers, the network typically includes one or more pooling layers, which reduce the size of the output by aggregating the information in neighbouring pixels. As a result, fewer parameters need to be learned, which increases the network's efficiency.

The network's last layer, which is often a fully connected layer, receives the output from the layer before it and generates a vector of probabilities that shows the likelihood that each of the input's many classes it belongs to. Backpropagation is a method that uses the gradient of the loss function with respect to the network parameters to update the weights in a way that minimises the loss. Backpropagation is used to adjust the weights of the filters in the convolutional layers and the weights of the fully connected layers during training. One of the advantages of CNNs is that they are able to learn hierarchical representations of the input data, with each layer learning more abstract features than the previous layer. This is because the filters in the early layers of the network are sensitive to low-level features such as edges and corners, while the filters in the later

How does a CNN work?

For CNNs to function, an input image must travel through several convolutional layers. A set of filters are applied by each convolutional layer to the input picture in order to identify various features like edges, corners, and textures. A non-linear activation function, such as the Rectified Linear Unit (Relu), is then applied to the output of each convolutional layer to help bring non-linearity into the network and enhance its capacity to learn complex features.

The network usually contains one or more fully connected layers after the convolutional layers, which are used to categorise the input image into one of several classes. Backpropagation is used during training to update the weights of the filters in the convolutional layers and the weights of the completely connected layers and gradient descent, in order to train the network to identify the various characteristics of the input images and classify them appropriately.

Flower Recognition using CNN:

Flower recognition is a challenging task due to the large number of different flower species, as well as the subtle variations in appearance between different individuals of the same species. However, CNNs have been shown to be highly effective for this task, achieving state-of-the-art results on several benchmark datasets.

One such dataset is the Oxford Flowers 102 dataset, which contains images of 102 different flower species. To train a CNN for flower recognition on this dataset, we first need to pre-process the images to ensure that they are all the same size and format. This is important because CNNs require input images to have a fixed size and number of channels. Once the images have been pre-processed, we can train the CNN using a technique called transfer learning. Transfer learning involves using a pre-trained CNN that has been trained on a large dataset, such as ImageNet, and fine-tuning it for our specific task. The idea is that the pre-trained network has already learned to recognize many different features that are useful for image recognition tasks, and so we can use it as a starting point for our own network.

To fine-tune the pre-trained network for flower recognition, we need to replace the final fully connected layer with a new layer that has the same number of output nodes as the number of flower species in our dataset. We can then train the network on the Oxford Flowers 102 dataset using a technique called stochastic gradient descent (SGD).


The first step in developing a flower recognition system is to collect a dataset of flower images. There are many datasets available for flower recognition, including the Oxford Flower dataset, the Flower-102 dataset, and the TACoS Multi-label Flower dataset. In this article, we will use the Flower-102 dataset, which contains 102 flower categories with 20 to 258 images per category, totalling 8,189 images.

The Flower-102 dataset is divided into three parts: the training set, the validation set, and the test set. The training set contains 6,149 images, the validation set contains 1,020 images, and the test set contains 2,020 images. The dataset is available for download at

CNN Architecture

The CNN architecture used for flower recognition consists of several layers, including convolutional layers, pooling layers, and fully connected layers. The purpose of the convolutional layers is to extract the features of the input image. The pooling layers reduce the dimensionality of the output of the convolutional layers, which reduces the computational complexity of the network. The fully connected layers classify the input image into one of the flower categories.

The architecture used for flower recognition is based on the VGG16 architecture, which is a popular CNN architecture for image recognition tasks. The VGG16 architecture consists of 13 convolutional layers, 5 pooling layers, and 3 fully connected layers.

The input to the network is an RGB image with dimensions 224x224x3. The first two convolutional layers have 64 filters each with a kernel size of 3x3 and a stride of 1. The next two convolutional layers have 128 filters each with a kernel size of 3x3 and a stride of 1. The next three convolutional layers have 256 filters each with a kernel size of 3x3 and a stride of 1. The next three convolutional layers have 512 filters each with a kernel size of 3x3 and a stride of 1. The last three convolutional layers have 512 filters each with a kernel size of 3x3 and a stride of 1The pooling layers appear after the first two convolutional layers and then every subsequent pair of two convolutional layers. The pool size is 2x2 and the stride is 2, and the pooling levels are maximum pooling layers. The three fully connected layers have 4096, 4096, and 1024 units, respectively. The output of the last fully connected layer is passed through a softmax activation function, which gives the probability of each flower category.

Training Process

The training process involves feeding the training data into the CNN and adjusting the weights of the network to minimize the loss function. The loss function used for flower recognition is the categorical cross-entropy loss function, which is commonly used for multi-class classification problems.

The training process consists of the following steps:

  • Data pre-processing: The first step in the training process is to pre-process the data. This involves resizing the images to a fixed size (in this case, 224x224), normalizing the pixel values to be between 0 and 1, and augmenting the data by randomly applying transformations such as rotation, flipping, and zooming to the images.
  • Initializing the weights: The weights of the network must then be initialised. In most cases, a normal distribution with a mean of 0 and a standard deviation of 0.1 is used to set the weights.
  • Forward pass: The following action is to run a forward scan across the network. The input image is fed into the network, and the output of each layer is computed using the current weights of the network. The output of the last layer is a probability distribution over the flower categories.
  • Compute the loss: The next step is to compute the loss function. The categorical cross-entropy loss function is used to measure the difference between the predicted probability distribution and the true probability distribution. The true probability distribution is a one-hot encoding of the flower category label.
  • Backward pass: The following action involves making a backward run through the network. The chain rule of calculus is used to compute the gradients of the loss function about the weights of the network. In the following phase, the network's weights are updated using the gradients.
  • Update the weights: With the help of an optimization method like stochastic gradient descent, the network's weights are updated (SGD). The SGD update criterion is:
    w = w - learning_rate * gradient
    where w is a weight, learning_rate is a hyperparameter that controls the step size of the update, and gradient is the gradient of the loss function with respect to the weight.
  • Repeat: The above steps are repeated for a fixed number of epochs or until the performance on the validation set stops improving.


After training the CNN on the Flower-102 dataset for 50 epochs, the performance on the test set was evaluated. The accuracy of the model was 86.1%, which is a significant improvement over the traditional method of flower recognition based on human experts' knowledge.

Results and Conclusion:

Using this approach, we can achieve very high accuracy on the Oxford Flowers 102 dataset. For instance, a current study's precision was 98.23% using a CNN with a ResNet-50 architecture and transfer learning.

In conclusion, CNNs are a powerful tool for flower recognition, and have been shown to achieve state-of-the-art results on several benchmark datasets. By using transfer learning, we can take advantage of pre-trained networks that have already learned to recognize many useful features and fine-tune them for our specific task. We used the Flower-102 dataset and the VGG16 architecture to train a CNN to recognize flower images. The results showed that the CNN was able to achieve a significantly higher accuracy than the traditional method of flower recognition based on human experts' knowledge. T The CNN learned features that are pertinent for flower identification and that are transferable to other image recognition tasks.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA