Flower Recognition with Python

Flower recognition uses the edge and colour characteristics of flower images to classify flowers. In this article, I will introduce you to a machine learning project on flower recognition with Python.

What is Flower Recognition?

There are many species of flowers in the world. Some species have many colours, such as roses. It is difficult to remember all the names of flowers and their information. Additionally, someone may be confused with similar flower species.

Also, Read – 100+ Machine Learning Projects Solved and Explained.

For example, white champaka and champak have similar names and petal shapes, but they have different colours and petal lengths.

At present, it is almost impossible to identify any particular flower or flower species in any way other than to seek information based on personal knowledge and expert experience. The availability of such experts can be an obstacle to this search for information.

Searching for such information on the Internet today is very limited to keyword research; word processor. Even then, the searcher has to come up with sufficiently useful keywords, which they cannot do, which is the crux of the matter.

This article will walk you through the machine learning approach to the task of recognizing flowers with Python.

Machine Learning Project on Flower Recognition with Python

The dataset I am using here for the flower recognition task contains 4242 flower images. Data collection is based on Flickr data, google images, Yandex images. You can use this data set to recognize the flowers in the photo.

The images are divided into five classes: chamomile, tulip, rose, sunflower, dandelion. For each class, there are approximately 800 photos. The photos are not in high resolution, approximately 320×240 pixels. Photos are not reduced to one size, they have different proportions.

Now let’s import the necessary Python libraries to get started with the task of Flower Recognition with Python:

Now the next step is to read each image in the data and create a label for each with the name of the folder:

Now let’s convert the data into numerical values:

data_arr = np.array(data)
label_arr = np.array(label)

Now let’s use the Label encoder and normalize the data:

encoder = LabelEncoder()
y = encoder.fit_transform(label_arr)
y = to_categorical(y,5)
X = data_arr/255

The next step is to split the dataset into 80% training and 20% test sets:

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=10)

Now let’s build a neural network model for the task of Flower Recognition:

Before compiling the model we need to create more training images to prevent overfitting:

Now let’s compile the neural network model:

Now let’s let the model if it recognize flowers properly:

flower recognition

I hope you liked this article on Machine Learning Project on Flower Recognition with Python programming language. Feel free to ask your valuable questions in the comments section below.

Articles: 77


Leave a Reply