Importing Libraries and Dataset

  • Pandas This library helps to load the data frame in a 2D array format and has multiple functions to perform analysis tasks in one go.
  • Numpy Numpy arrays are very fast and can perform large computations in a very short time.
  • Matplotlib This library is used to draw visualizations.
  • Sklearn – This module contains multiple libraries having pre-implemented functions to perform tasks from data preprocessing to model development and evaluation.
  • OpenCVThis is an open-source library mainly focused on image processing and handling.
  • Tensorflow – This is an open-source library that is used for Machine Learning and Artificial intelligence and provides a range of functions to achieve complex functionalities with single lines of code.

Python3




import numpy as np
import pandas as pd
import seaborn as sb
import matplotlib.pyplot as plt
  
import cv2
from glob import glob
import tensorflow as tf
from tensorflow import keras
from keras import layers
  
from tqdm.notebook import tqdm, trange
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, StandardScaler
  
import warnings
warnings.filterwarnings('ignore')


Now let’s create a data frame of the image path and the classes from which they belong. Creating a data frame helps us to analyze the distribution of the data across various classes.

Python3




images = glob('images/train/*/*.jpg')
len(images)


Output:

28821

Python3




df = pd.DataFrame({'image_path': images})
df.head()


Output:

 

Python3




df['label'] = df['image_path'].str.split('/', expand=True)[2]
df.head()


Output:

 

Python3




df.groupby('label').count().plot.bar()
plt.show()


Output:

Bar Chart to visualize number of images in each class

Hidden Layer Perceptron in TensorFlow

In this article, we will learn about hidden layer perceptron. A hidden layer perceptron is nothing but a hi-fi terminology for a neural network with one or more hidden layers. The purpose which is being served by these hidden layers is that they help to learn complex and non-linear functions for a task.

Hidden Layer Perceptron in TensorFlow

The above image is the simplest representation of the hidden layer perceptron with a single hidden layer. Here we can see that the input for the final layer is the neurons of the hidden layers. So, in a hidden layer perceptron network input for the current layer is the output of the previous layer.

We will try to understand how one can implement a Hidden layer perceptron network using TensorFlow. Also, the data used for this purpose is the famous Facial Recognition dataset.

Similar Reads

Importing Libraries and Dataset

Pandas – This library helps to load the data frame in a 2D array format and has multiple functions to perform analysis tasks in one go. Numpy – Numpy arrays are very fast and can perform large computations in a very short time. Matplotlib – This library is used to draw visualizations. Sklearn – This module contains multiple libraries having pre-implemented functions to perform tasks from data preprocessing to model development and evaluation. OpenCV – This is an open-source library mainly focused on image processing and handling. Tensorflow – This is an open-source library that is used for Machine Learning and Artificial intelligence and provides a range of functions to achieve complex functionalities with single lines of code....

Data Visualization

...

Model Training and Evaluation

...