AI is one of the main buzzwords in 21st century which is most intriguing in terms of its applications and usage. Nowadays, AI is used in each and every aspect of modern life – from ordering food to autonomously driving cars. AI can be classified into many sub-categories. But the main concerning categories are Machine Learning and Deep Learning.
The traditional affair: Machine Learning vs Deep Learning
Machine Learning is a type of AI in which the features are already given to a model. If a model is supposed to detect an image, training it as a machine learning model would result in less accuracy as there are ton of features we have to provide the model. In this scenario, Deep Learning is used. Deep Learning is a subset of machine learning in which the features are not provided to a model. It basically tries to mimic human brain.
CNN
Every neural network in a deep learning model is connected with the help of a neuron. These neurons are interconnected in such a way that these mimic the structure of the human brain. A deep learning network design that learns directly from data is a convolutional neural network (CNN or ConvNet). CNNs are very helpful for recognising objects, classes, and categories in photos by looking for patterns in the images. Today, we will see how to implement CNN in binary and multiclass classification using Keras.
About Keras
Keras is a high-level, open-source neural network library written in Python. It provides a user-friendly API for defining and training deep learning models. Google created the high-level Keras deep learning API to implement neural networks. Keras acts as an interface for the TensorFlow library, which provides the low-level operations for training and running neural networks. With its ease of use and built-in support for common neural network architectures, Keras has quickly become a popular choice for deep learning practitioners.
Binary Classification
In binary classification, a model is trained on a labeled dataset, where each instance is assigned a label of 0 or 1, and the model's goal is to learn a mapping from input features to the binary outputs. Once trained, the model can be used to make predictions on new, unseen instances. Binary classification is used to solve problems such as spam detection, image classification (e.g., is this picture a cat or not), and medical diagnosis (e.g., does a patient have a disease or not).
Binary classification can be implemented in Keras.In this illustration, it is assumed that the input data is kept in the X train and X test arrays, while the binary labels are kept in the Y train and Y test arrays. First, a fully connected (Dense) layer with 32 units and a ReLU activation function receives the input data. A single unit with a sigmoid activation function receives the output of this layer and outputs a binary prediction in the [0, 1] range.
The Adam optimizer and binary cross-entropy loss are used in the model's construction, while the fit method is used for training. Finally, the evaluate method is used to assess the model's performance on the test data, and the predict method is used to make predictions about future occurrences.
Multiclass Classification:
A sizable database of handwritten numbers called the MNIST database (Modified National Institute of Standards and Technology database) is frequently used to train different image processing systems. The database is frequently used for machine learning training and testing. Multiclass classification of numbers using the MNIST database can be accomplished in Keras by training a deep learning model to recognize handwritten digits. The MNIST database contains 60,000 training images and 10,000 test images of handwritten digits (0-9).
In this example, the input data is loaded using the mnist.load_data function, which returns the training and test images as arrays. The data is preprocessed by reshaping the images into a 1D array of 784 pixels and normalizing the pixel values to be between 0 and 1. The binary labels are one-hot encoded using the to_categorical function.
The model consists of a flattening layer to convert the 2D image data into a 1D array, followed by two fully connected (Dense) layers. The output layer has 10 units, one for each possible digit, and uses a softmax activation function to produce multiclass predictions.
The model is compiled with categorical cross-entropy loss (as it is a multiclass classification example) and the Adam optimizer, and trained using the fit method. Finally, the model's performance on the test data is evaluated using the evaluate method, and predictions can be made on new instances using the predict method.
0 Comments