AI-Powered Face Shape Detection for Personalized Hairstyle Recommendations Using Deep Learning Model

Page 1


International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 04 | Apr 2025 www.irjet.net p-ISSN: 2395-0072

AI-Powered Face Shape Detection for Personalized Hairstyle Recommendations Using Deep Learning Models.

123Bachelor of Technology in Department of Data Science, Usha Mittal Institute of Technology, Mumbai, India

Abstract - Thisresearchintroducesanovelmethodtoface shape detection in order to better recommend hairstyles. Preciserecognitionoftheshapeoftheface whetheroval, round,heart,squareoroblongisessentialinrecommending hairstylesthatmatchasnearlyaspossibleanindividual's personal characteristics. Our method combines advanced imageprocessingandmachinelearningalgorithmswithAI integratingdeeplearningmodelsthathavebeenpre-trained, suchasaCNN-basedarchitecturelikeVGG16orMobileNet. It identified facial landmarks using deep learning models trained on a comprehensive data set of face images. In addition, to combat variations in facial expressions and lighting conditions, we have extended the system with artificial intelligence techniques that help it better handle thesedifferentcircumstances.Empiricalresultsdemonstrate thatwhenourfaceshapedetectionmodelisintegratedwith a hair do counseling system, the system offers hair suggestionstailoredaccordingtofaceshapeasdetermined by the headband. Methodology efficiency and accuracy demonstrated by experiment will directly indicate the potentialapplicationprospectsforpersonalgroomingmode plusVirtualStylingTools.

Key Words: Face shape detection, hairstyle recommendation, deep learning, convolutional neural networks (CNN), VGG16, MobileNet, image processing, facial landmarks, machine learning, virtual styling, personalgrooming.

1.INTRODUCTION

Choosing an appropriate hairstyle in the current era of personalcareandstylecanbedaunting,giventhemultitude of choices available. Many people find it challenging to identify a look that suits their particular facial structure, often resorting to experimentation or seeking expert guidance,whichcanbebothtime-consumingandpotentially unsuccessful.Thisresearchinvestigatesthecreationofan artificial intelligence-driven system that identifies face shapesandsuggeststailoredhairstylestoaddressthisissue. Conventional approaches to hairstyle selection often lack accuracy, as they rely on subjective judgments or generic recommendations.Althoughsomedigitalapplicationsclaim toofferhairstyleadvice,manyfailtopreciselyevaluateface shapes or provide truly personalized suggestions. This underscoresthenecessityforasmart,user-friendlysolution thatemployscutting-edgetechnologytoaccuratelyanalyze facial characteristics. Our study examines the potential of

utilizing deep learning models, such as CNN-based architectures like VGG16 and MobileNet, to enhance face shape classification. By training the system on a varied collection of facial images, we aim to develop a model capable of consistently recognizing different face shapes. Furthermore, we concentrate on creating an easy-to-use interface that enables users to effortlessly upload their photosandreceivehairstylerecommendationstailored to theirfacialfeatures.Ultimately,thisresearchaimstoconnect technologywithpersonalstyling,simplifyingtheprocessof hairstyleselection.

2. LITERATURE SURVEY

Inthisitinvolvessegmentingtheheadandidentifyingthe face plane to minimize shadows. It uses an algorithm that treats 3D body points as evaluation features, employing Eigenvectors for refinement and techniques like Ellipsoid Fitting and Mahalanobis distance for segmentation. The HaarCascadeClassifieranddlibfunctionsareusedforrealdata detection, improving classification accuracy[1]. Face recognition has advanced over 30 years, widely used in commercialandlawenforcementsectors.Despiteprogress, challenges like lighting and angle variations remain. Face shape detection benefits industries like fashion and ecommerce.CNNsarehighlyeffectiveforfaceclassification, automaticallyidentifyingfeatureswithminimaltraining.Key challengesincludeadaptingtovariedconditions,improving real-timeprocessing,andenhancingpersonalization.Future improvements focus on robustness, real-time capabilities, and integrating multimodal data for more accurate recognition[2] Recentadvancesinfaceshapeclassification, mainlyusingCNNs,haveimprovedaccuracyinfashionand healthcare. Challenges like image quality and expressions remain, requiring stronger algorithms and real-time improvements[3]. Advancements in hairstyle recommendation use CNNs to analyze face shapes and suggestsuitablestyles.Real-timesimulationsimproveuser experience,butchallengeslikelighting,hairdiversity,and processing speed remain, requiring better datasets and personalization [4]. Hybrid models combining CNNs with other techniques improve hairstyle recommendations. Challengeslikelighting,expressions,andhairtypespersist. Augmentedrealityandreal-timesimulationsenhanceuser experience,drivingpersonalized,data-drivenadvancements [5].TheCelebAdataset,knownforitsdiversecelebrityfacial images with annotations, has been adapted for hairstyle recommendation.Researchersuseit totrainCNN models,

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 04 | Apr 2025 www.irjet.net p-ISSN: 2395-0072

improvingaccuracyinmatchinghairstylestofacialfeatures. Techniques like transfer learning and data augmentation helpaddresschallengeslikelighting,expressions,andhair variations.Thisshifttowardslarge-scale,high-qualitydata enhancespersonalizedhairstylesuggestions[6]

3. METHODOLOGY

3.1 Overview of System/Project

 Frontend:

ConceptualOverview

Thefrontpage(homepage)inthisprojectservesseveral purposes:

Introduction: It introduces the app's purpose and functionality.ImageUpload:Itprovidesawayforusersto uploadtheirprofilepicture.FaceDetection(Initiation):It initiatesthefacedetectionandhairstylerecommendation process.

1.Setting up the Basic React App

CreateReactApp:CreateanewReactapplicationusingthe followingcommandintherootdirectoryofyourproject: npx create-react-app frontend Navigate: Move into the frontenddirectorycdfrontendInstallDependencies:Install thefollowingdependencies whichyouwill needtobuild thefrontendforyourapplication:npminstallaxiosreactrouter-domaxiosisusedformakinghttprequeststoyour backend. react-router-dom for creating routes and navigationinthefrontend.

Building the Header

CreateComponent:Createa newfilenamedHeader.jsin thesrc/componentsfolder.

Building the Hero Section

Create Component: Create a file named HeroSection.js insidethesrc/componentsfolder.

ImportComponents:

Importtheuploadformtouploadimage.

Import Result Display component to display image with landmarksandfaceshapeinformation.

ImportuseNavigatehookforrouting.

JavascriptimportReact,{useState}from'react'; importUploadFormfrom'./UploadForm'; importResultDisplayfrom'./ResultDisplay'; import{useNavigate}from'react-router-dom';

This component implements a carousel that contains introductorytext,imageuploadanddetectionbuttons,and theresultsiftheimageisuploaded.

ItusesauseNavigatehooktoperformroutingandredirect tothenextpage.

Building the Upload Form

CreateComponent:CreateanewfilenamedUploadForm.js inthesrc/componentsfolder.

Thiscomponentprovidesanimageuploadelementanda "DetectNow"button.

It makes an API call to the Flask server using the /detect_face_shapeendpoint.

Itdisplaystheerrorsiftheuploadfails.

Face shape name detected Section

Byexaminingtheuser'sface,thesystemidentifiesitsshape inthisparticularinstanceitis"oval".

Fig3.1Uploadform
Fig3.2Detectnowbutton
Fig3.3Faceshapenamedetected
Fig3.4Gethairstylerecommendation

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 04 | Apr 2025 www.irjet.net p-ISSN: 2395-0072

Get hairstyle recommendation Section

It will gives you hairstyle ideas that suit your face shape. Afterdetectingyourfaceshape

Fig3.5AboutServices

ServicesSection.js (Services Section)

Purpose: Implements the services section.

Explanation:Displaystheservicesthatthisapplicationoffers in a clear manner using cards. The cards have headings, descriptionsandthecalltoactions.

Fig3.6Testimonials

Testimonials.js (Testimonials Section)

Purpose: Displays the testimonials from different users. Explanation: Displays a list of testimonials with the person'sname,avatar,andtext.

3.7Contactus

ContactSection.js (Contact Section)

Purpose:Displaysthecontactinformationandthe newslettersignupsection.

Explanation:Displayscontactinformationandasimple newslettersubscriptionform.

Includesthecopyrightinformationforthewebsite.

2. Building the Result Display

Create Component: Create a new file named ResultDisplay.js in the src/components folder. This component receives the result from Hero Section and rendersthefaceshapeandtheimagewithlandmarks.

3. Implementing the Main App Component

ImportComponents:ImporttheHeaderandHeroSection componentsalongwithallotherrelevantcomponentsin App.js.

Thissetsuptheroutingandrendersallthecomponents. Header renders at the top, below the header, a router renderseitherHeroSection,RecommendationPageorTry On Page based on the path. The other components like ServicesSection,TestimonialsandandContactSectionare renderedbelow.

4. Adding Styles

CreateFile:Createastyles.cssfileinthesrcfolder.

5. Rendering the Main App

ImportApp:Importthemainappcomponentinindex.js

 Backend:

Themaindutiesofthebackendare: Handle image uploads from the frontend: handles and uploadsimagestotheserverfromthefrontend. UsetheDliblibrarytoidentifyfacesintheimageandextract faciallandmarks.FaceDetectionandLandmarkPrediction: FaceShapeClassification:Usethepre-trainedTensorFlow/ KerasCNNmodeltoclassifytheuser'sfaceshape. Withthefaceshapedetermined,givebacksomehairstyles thatarerecommendedbymatchingittouserpreferences.Q: Recommendation for Hairstyles Written as a function underneaththeclassesthatcallsitselfdependingonstate changes

APIEndpoints:ExposeAPIendpointsforthesefunctionsso thatthefrontendcaninteractwiththem.

 Backend Code Files:

app.py:MasterFlaskapplicationthatsetstheAPIendpoints andhandlesloadingmodelsandrequests. utils.py: Containing helper functions to load the Dlib face detector,performlandmarkdetectionandgeneratehairstyle recommendations. face_shape_classifier.py: This file defines the Face Shape Classifier class for loading the trained CNN model and makingfaceshapepredictions. requirements.txt: The required Python packages for the backendareonesspecifiedheretorunitright.MakeYour Back-endCollectionStep-by-Step

Fig

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 04 | Apr 2025 www.irjet.net p-ISSN: 2395-0072

 Python Environment Configuration:

Createavirtualenvironmentforthebackend.SamplePython

EnvironmentVariableFile

pipinstallUsualPKGname

ModelLoadingandAPIStart(app.py):

In the Flask app, the trained component of face shape classificationmodelface_shape_classifier.h5isstartedup. Again,Dlibfacedetectorandfaciallandmarkpredictormust beloaded.

All models are loaded during initialization by calling load_dlib_modelfunction.Theloadingisdoneinapp.pyand relatedfilestoavoidclutteringuputils.pywithapp-specific codethatisnotreusable.

Specifically, error handling techniques should be used for model loading. Of course if you do not know these techniquesthenfeelfreetoaskquestionshereaboutthem./ detect_face_shapeAPIEndpoints(app.py):

Imageupload:imagedatauploadedto/detect_face_shape, aPOSTrequestrouteintheFlaskapp,shouldcontainan imagefile.

 Image Processing:

A read is made from the subsequent drop down window requestinganimage.

TheimageisputintoOpenCVformat.

Dlibfacedetectorandlandmarkpredictorareusedtofind the face and extract landmark points from it (detect_face_and_landmarksfunctionfromutils.py).

 Face Shape Prediction:

Topredictthefaceshape,theextractedfaceisbeingpassed toFaceShapeClassifier.

FaceShapeClassifierpre-processestheimage,andthenuses itstrainedCNNmodelforfaceshapeprediction.

Response Generation: Then this API returns to front end JSON response, and such data detects the face shape, landmarksandfaceco-ordinates,atthesametimealsothe base-64image.

/recommend_hairstyleAPIEndpoint(app.py):

FaceShapeReception:ThisAPIroutereceivesaJSONPOST requestcontainingthedetectedfaceshapefromfrontend. recommend the get hairstyle: The face shape api recommendshairstylesforthegivenfaceshape.

ResponseGeneration:TheAPIsendsaJSONresponse(back) containingalistofrecommendedhair-stylestothefrontend. utils.py-HelperFunctions

load_dlib_model:LoadstheDlibfacedetectorandlandmark predictor.

detect_face_and_landmarks:thisfunctiontakesanimagethe facedetector,andlandmark predictorasaninput,returns theimagewithlandmarksandboundingboxcoordinates. get_hairstyle_recommendations:thisfunctiontakesinaface shape and returns a list of hairstyles from our data dictionary.Alsohandledinhere,areanyexceptioncausedby loadinghairstyleorrecommendationdata.

face_shape_classifier.py-FaceShapeClassifierClass

This class is responsible for loading the model of facial classificationandmakingpredictions.

init: Loads the trained CNN model and prepares the label encoder.

preprocess_image:Themethodprocessesaninputimageto conformwithexpected inputoftheCNN model.Generally this just means resizing, normalization and perhaps some otherhelpfulltransformationaswell.

predict: The face shape that′s being pre-processed is (already)predictedbytheoriginalimage.

 Running the Backend:

Openaterminalandnavigatetotheback-enddirectorythen runthecommandpythonapp.py.

TheFlaskdevelopmentserverisnowrunning.

3.2 Algorithm

Weuseddifferentmachinelearningtechniquestoboostour currentmodel

Random Forest is a fine machine-learning technique that compilesthejudgmentofmanytreesoverturnedforthesake ofobtainingmoreaccurateresults,fromfirstdatasetwegot randomforest47%accuracy.Fromseconddatasetwegot 46%. SVM (Support Vector Machine) finds good ways to erect barriers between different categories where none existedbefore.fromfirstdatasetwegotsvm36%accuracy. From Second dataset we got 47%. Logistic Regression is usedtosolveunknownsintermofhowmuchoneclassbest fitsthem,fromfirst dataset logistic regressionaccuracyis 49%.withSeconddatasetwegotaccuracy52%.Unlikethe others,XGBoostworksinconjunctionwithpastmistakesto makesuremodelsbetterrepresentreality.fromfirstdataset xgboost accuracy is 39%. From Second dataset we got accuracy42%.Vgg16Inaddition,VGG16IsAdeeplearning modelforextractingimagefeaturesthatcanhelpanalyzethe actualoperatingstateofasystemasaccuratelyaspossible. from first dataset accuracy of vgg16 is 47%, from Second dataset accuracy we got 69%. MobileNet MobileNet is a lightweight Convolutional Neural Network (CNN) that is goodforefficientimageclassification,objectdetectionand recognition.fromfirstdatasetMobileNetaccuracyis46%, from Second dataset accuracy we got 47%. Using Dlib to detectfaciallandmarks,harmonizefacesandidentifyfacial featuressuchasdistancefromjawwidthorfacelength.By pre-processing followed by K-means to get rid of outliers, thedataisbalancedusingSMOTE.AlsothroughOptunato find an optimized set of tuning hyperparameters (though XGBoostseemedjustright).Agreatmanymachinelearning algorithmsareexplored.ForexampleRandomForestsare trained; Support vector machines (SVM) are trained in additiontoLogisticRegression(LR)andXGBoostwhichis using deep learning architecture VGG16 Shown 47% Accuracy, and MobileNet with augmented data 46% test accuracy. The results are validated by confusion matrices andclassificationreportswithstandardaccuracies.

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 04 | Apr 2025 www.irjet.net p-ISSN: 2395-0072

4. HARDWARE AND SOFTWARE REQUIREMENTS

HardwareRequirements:Processor:Inteli5(min)ori7 RAM:8GB(min)or16GB, Storage:10GBfreespace

SoftwareRequirements:Python-Libraries:OpenCV,dlib, scikit-learn,numpydlibinstallation,IDE:Colab.

5. RESULTS

Wetriedothermachinelearningmodelsonbothofourdata setstoenhanceourexistingmodel.OnthefirstsetRandom Forestachieves47%,inthesecond46%.SVMreached36% and47%whileLogisticRegressiondidbetterwith49%and 52%.XGBoostscored39%and42%.VGG16showedabig jumpfrom47%to69%whileMobileNetgotto46%inthe end.Tovalidateourfindings,weusedconfusionmatrixand classificationreport.Thesereportsensurethattheresults are both accurate and reliable. The accuracy of various models from the viewpoint which model will have better performancelateron.Bycontrast,VGG16 model achieved highestaccuracyamongallthetestedmodelswecalculated and considered. It's mostly better than the other models such as VGG, which is the highest among all models now. This result means that in our study, VGG16 was the most effectivemodel.Withitshigheraccuracy,VGG16willbeable tomakebetterpredictionsthananyoftheothermodelswe tested.

6. CONCLUSION

In this project, we successfully implemented a facial landmark detection and label classifier with machine learningtechniqueswhichincludedstepssuchas:detection ofthefacialfeatures,facialalignmentoperation,extraction of all necessary measurements for creating models to classifyfaceshapes.Datapreprocessingstepsresizingand eliminatingoutliersimproveddatasetquality.Avariety of models,amongwhich wemaynoteMobileNetand VGG16 pushedthelimits,weretested.Themostsuccessfulmodel reached 69% accuracy. In order to improve accuracy, we have concentrate on narrowing the focus of feature extraction techniques, and employing models. Finite hyperparameter optimization and delving into ensemble learning should also augment performance. This will be particularlyhelpfulwheninstalledasareal-timefaceshape classification flow incoming beauty, and virtual try-on solutionscanalsobecreatedwithit.

7. REFERENCE

[1] Kamble,Y.M.,&Kulkarni,R.B.(2024).Recommendation SystemforHairstyleBasedonFaceRecognitionUsingAI andMachineLearning.InternationalJournalofSoftware Innovation(IJSI),12(1),1-10.

[2] Rohan S, Suhas R Vittal, Neeraj H Gowda, Dr. Priya R Sankapal.(2022). Face Shape Classifier Using Deep Learning.InternationalResearchJournalofEngineering andTechnology(IRJET).

[3] Mehta, A., & Mahmoud, T. (2022). Human Face Shape ClassificationwithMachineLearning.Mahmoud,Human FaceShapeClassificationwithMachineLearning.

[4] Rajapaksha,S.V.,&Kumara,B.T.G.S.(2018).Hairstyle Recommendation Based on Face Shape Using Image Processing.

[5] Chen,Y.,Zhang,Y.,Huang,Z.,Luo,Z.,&Chen, J.(2021, August). CelebHair: A new large-scale dataset for hairstyle recommendation based on CelebA. InInternational Conference on Knowledge Science, Engineering and Management(pp. 323-336). Cham: SpringerInternationalPublishing.

[6] Wu,Y.,&Ji,Q.(2015).Discriminativedeepfaceshape modelforfacialpointdetection.InternationalJournalof ComputerVision,113.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.