FACIAL RECOGNITION USING DEEP NEURAL NETWORK
How Deep Neural Networks handles complex data and patterns to extract Facial Features?
Deep Neural Networks captures facial features leading to highly accurate recognition.
DNN's learn patterns and features from the Unstructured dataset trained with the Model while simultaneously Improving Model Performance.
This also extracts features such as names to identify an Image.
The Dataset for training the facial recognition model was gotten from kaggle.com. This Dataset contains images of 18 Hollywood Celebrities with 100 images of each Celebrity.
https://www.kaggle.com/datasets/vishesh1412/celebrity-face-image-dataset/data
The Celebrities in the Dataset are:
Angelina Jolie
Brad Pitt
Denzel Washington
Hugh Jackman
Jennifer Lawrence
Johnny Depp
Kate Winslet
Leonardo DiCaprio
Megan Fox
Natalie Portman
Nicole Kidman
Robert Downey Jr.
Sandra Bullock
Scarlett Johansson
Tom Cruise
Tom Hanks
Will Smith
#plotting libraries that are required for the model training
import numpy as np import cv2 import sklearn import pickle from django.conf import settings import os
#setting the static directory
STATIC_DIR = settings.STATIC_
#DNN Models
# face detection face_detector_model = cv2.dnn.readNetFromCaffe(os.path.join(STATIC_DIR,'models/deploy.prototxt.txt'), os.path.join(STATIC_DIR,'models/res10_300x300_ssd_iter_140000.caffemodel')) # feature extraction face_feature_model = cv2.dnn.readNetFromTorch(os.path.join(STATIC_DIR,'models/openface.nn4.small2.v1.t7')) # face recognition face_recognition_model = pickle.load(open(os.path.join(STATIC_DIR,'models/machinelearning_face_person_identity.pkl'), mode='rb'))
#Creating the Pipeline Model Function for the feature extraction for the face name and face score.
def pipeline_model(path): # pipeline model img = cv2.imread(path) image = img.copy() h,w = img.shape[:2] # face detection img_blob = cv2.dnn.blobFromImage(img,1,(300,300),(104,177,123),swapRB=False,crop=False) face_detector_model.setInput(img_blob) detections = face_detector_model.forward() # machcine results machinlearning_results = dict(face_detect_score = [], face_name = [], face_name_score = [], count = []) count = 1 if len(detections) > 0: for i , confidence in enumerate(detections[0,0,:,2]): if confidence > 0.5: box = detections[0,0,i,3:7]*np.array([w,h,w,h]) startx,starty,endx,endy = box.astype(int) cv2.rectangle(image,(startx,starty),(endx,endy),(0,255,0)) # feature extraction face_roi = img[starty:endy,startx:endx] face_blob = cv2.dnn.blobFromImage(face_roi,1/255,(96,96),(0,0,0),swapRB=True,crop=True) face_feature_model.setInput(face_blob) vectors = face_feature_model.forward() # predict with machine learning face_name = face_recognition_model.predict(vectors)[0] face_score = face_recognition_model.predict_proba(vectors).max() text_face = '{} : {:.0f} %'.format(face_name,100*face_score) cv2.putText(image,text_face,(startx,starty),cv2.FONT_HERSHEY_PLAIN,2,(255,255,255),2) cv2.imwrite(os.path.join(settings.MEDIA_ROOT,'ml_output/process.jpg'),image) cv2.imwrite(os.path.join(settings.MEDIA_ROOT,'ml_output/roi_{}.jpg'.format(count)),face_roi) machinlearning_results['count'].append(count) machinlearning_results['face_detect_score'].append(confidence) machinlearning_results['face_name'].append(face_name) machinlearning_results['face_name_score'].append(face_score) return machinlearning_results
The DNN Model Pipeline is then utilized in creating a User-Friendly Application that enables users to upload an Image of their favourite Celebrity listed in the dataset above. This will display the Face Score accuracy as well as their Identity.
In other to achieve the model pipeline integration, Django Framework will be utilized to create the Web application which includes the SQLite Database.
Features of the Application:
Image Input
Capabiility to upload photos of 15 different Celebrities.
Face Detection
This step invovles identifying and recognising the Celebrities faces with the image that has been uploaded.
Once the faces are extracted, specific facial features are extracted to create a unique representation of each face. Also, Name features are extracted to identify the celebrity.
When a new face is uploaded, its features are extracted , encoded and compared against the trained data. The application matches the features with those in the database. Once a match is found, the celebrity is recognised.
The encoded face data is stored in SQL Lite Database. This database contains all the information about the celebrities that was trained by the recognition model.
Video demonstration of the DNN model integrated with Django Framework for a User Friendly Application.
Facial Recognition Web Application
There are no models linked
There are no models linked