Package: kadita
Kadita CVKadita CV is a lightweight face recognition and facial attribute analysis (age,gender,emotionandrace) framework for python. It is a hybrid face recognition framework wrappingstate-of-the-artmodels:VGG-Face,Google FaceNet,OpenFace,Facebook DeepFace,DeepID,ArcFace,DlibandSFace.Experiments show that human beings have 97.53% accuracy on facial recognition tasks whereas those models already reached and passed that accuracy level.
It's worth mentioning that Kadita CV is not limited to face recognition alone; it can also be used for object detection with YOLO, OpenCV, SVM, CNN, and TensorFlow Lite.By incorporating multiple leading models, Kadita CV has the potential to deliver highly accurate face recognition solutions. With the inclusion of these models, it may be able to meet or even exceed the accuracy achieved by humans in facial recognition tasks.Additionally, its ability to perform object detection with YOLO, OpenCV, and TensorFlow Lite makes it a versatile tool for a wide range of computer vision applications.InstallationThe easiest way to install kadita is to download it fromPyPI. It's going to install the library itself and its prerequisites as well.$pipinstallkaditaSecondly, you can install kadita from its source code.$gitclonehttps://github.com/Kastara-Digital-Technology/KaditaCV.git
$cdkadita
$pipinstall-e.Then you will be able to import the library and use its functionalities.fromkaditaimportDeepFaceFace Recognition-DemoA modernface recognition pipelineconsists of 5 common stages:detect,align,normalize,representandverify. While Kadita CV handles all these common stages in the background, you don’t need to acquire in-depth knowledge about all the processes behind it. You can just call its verification, find or analysis function with a single line of code. In this below this is code for Face Recognition.fromkaditaimportDeepFaceDeepFace.stream("dataset")1 face in frameFace Recogniton function can also handle many faces in the face pairs, example when 2 people face a webcam it will detect 2 people.2 face in frameFace Recognition models-DemoKadita CV is ahybridface recognition package. It currently wraps manystate-of-the-artface recognition models:VGG-Face,Google FaceNet,OpenFace,Facebook DeepFace,DeepID,ArcFace,DlibandSFace. The default configuration uses VGG-Face model.models=["VGG-Face","Facenet","Facenet512","OpenFace","DeepFace","DeepID","ArcFace","Dlib","SFace",]#Face Recognitiondfs=kadita.find(img_path="Rafi.jpg",db_path="D:\Kumpulan Projek\Library CV KDT\Kadita CV - Face Recogntion DeepFace\tests\dataset",model_name=models[1])FaceNet, VGG-Face, ArcFace and Dlib areoverperformingones based on experiments. You can find out the scores of those models below.ModelLFW ScoreYTF ScoreFacenet51299.65%-SFace99.60%-ArcFace99.41%-Dlib99.38 %-Facenet99.20%-VGG-Face98.78%97.40%Human-beings97.53%-OpenFace93.80%-DeepID-97.05%Result LFW and YTF scoreThe "LFW score" refers to the performance metric or measurement of face recognition algorithms tested using the Labeled Faces in the Wild (LFW) dataset.The "YTF score" is an abbreviation for "YouTube Face Dataset score." This dataset is used in face recognition research, and the "YTF score" typically refers to the performance measurement of face recognition algorithms tested using the YouTube Face (YTF) dataset.SimilarityFace recognition models are regularconvolutional neural networksand they are responsible to represent faces as vectors. We expect that a face pair of same person should bemore similarthan a face pair of different persons.Similarity could be calculated by different metrics such asCosine Similarity, Euclidean Distance and L2 form. The default configuration uses cosine similarity.metrics=["cosine","euclidean","euclidean_l2"]#face verificationresult=DeepFace.verify(img1_path="img1.jpg",img2_path="img2.jpg",distance_metric=metrics[1])#face recognitiondfs=DeepFace.find(img_path="img1.jpg",db_path="D:\Kumpulan Projek\Library CV KDT\Kadita CV - Face Recogntion DeepFace\tests\dataset",distance_metric=metrics[2])Euclidean L2 formseemsto be more stable than cosine and regular Euclidean distance based on experiments.Facial Attribute Analysis-DemoKadita CV also comes with a strong facial attribute analysis module includingage,gender,facial expression(including angry, fear, neutral, sad, disgust, happy and surprise) andrace(including asian, white, middle eastern, indian, latino and black) predictions. Result is going to be the size of faces appearing in the source image.objs=DeepFace.analyze(img_path="img4.jpg",actions=['age','gender','race','emotion'])Age, Gender, Race, Emotion ExampleAge model got ± 4.65 MAE; gender model got 97.44% accuracy, 96.29% precision and 95.05% recall as mentioned.Face Detection Haar Cascade OpenCV-DemoFace detection and alignment are important early stages of a modern face recognition pipeline. Experiments show that just alignment increases the face recognition accuracy almost 40%.OpenCV, andYOLOv8 Facedetectors are wrapped in KaditaCV.All deepface functions accept an optional detector backend input argument. You can switch among those detectors with this argument. OpenCV is the default detector.frommodules.imageimportVisionfrommodules.routineimportFaceRecognitionfrommodules.routineimportFaceRecognitionTrainingfrommodules.routineimportImgBusterasYolofromutility.dataimportYAMLDataHandlerif__name__=="__main__":try:whileTrue:try:frame=cam.read(640,True)face_detect=face.predict(frame)face_condition=1ifface_detectelse0condition=1if(face_condition)else0data.update("face-condition",str(condition))yolo.draw(frame,face_detect)cam.show(frame,"frame")ifcam.wait(1)==ord('q')orface.isStop():ifface.isTraining():t=FaceRecognitionTraining()t.process()breakexceptExceptionaserr:print(err)cam.release()cam.destroy()exceptExceptionase:print(f"[INFO]{time.time()}Main Initialize Failed:\n{e}")Face Detection Haar cascade OpenCV models are actually the simplest way to face recognition models, because they don't have any model like CNN but his a just simple algorithm Local Binary Pattern Histograms (LBPH). So here the result of OpenCV :Open CVFace Detection YOLOV8-DemoFace detection and alignment are important early stages of a modern face recognition pipeline. Experiments show that just alignment increases the face recognition accuracy almost 100%.OpenCV,SSD,Dlib,MTCNN,RetinaFace,MediaPipe,YOLOv8 FaceandYuNetdetectors are wrapped in deepface.All deepface functions accept an optional detector backend input argument. You can switch among those detectors with this argument. Yolov8 is the default detector and here the result :fromultralyticsimportYOLOimportcv2model=YOLO('assets/models/yolov8n-face.pt')cap=cv2.VideoCapture(0)whilecap.isOpened():success,frame=cap.read()ifsuccess:results=model(frame)annotated_frame=results[0].plot()cv2.imshow("YOLOv8 Face",annotated_frame)ifcv2.waitKey(1)&0xFF==ord("q"):breakelse:breakcap.release()cv2.destroyAllWindows()Face recognition models are actually CNN models and they expect standard sized inputs. So, resizing is required before representation. To avoid deformation, Kadita CV adds black padding pixels according to the target size argument after detection and alignment. If you think Dlib and RetinaFace is hard, you can use the Yolov8 algorithm instead of the default like RetinaFace, Dlib, and OpenCV.Yolov8 FaceRetinaFace and MTCNN seem to overperform in detection and alignment stages but they are much slower. If the speed of your pipeline is more important, then you should use opencv, ssd, and YoloV8. On the other hand, if you consider the accuracy, then you should use retinaface or mtcnn.The performance of RetinaFace is very satisfactory even in the crowd as seen in the following illustration. Besides, it comes with an incredible facial landmark detection performance. Highlighted red points show some facial landmarks such as eyes, nose and mouth. That's why, alignment score of RetinaFace is high as well.RetinaFaceYou can find out more about RetinaFace on thisrepo.Real time Kadita CV-DemoYou can run Kadita CV for real time videos as well. Stream function will access your webcam and apply both face recognition and facial attribute analysis. The function starts to analyze a frame if it can focus a face sequentially 1 frame. Then, it shows results in a frame.fromkaditaimportDeepFaceDeepFace.stream(db_path="../tests/dataset")Even though face recognition is based on one-shot learning, you can use multiple face pictures of a person as well. You should rearrange your directory structure as illustrated below.user
├──database
│├──Iwan
││├──Iwan1.jpg
││├──Iwan2.jpg
│├──Rafi
││├──Rafi1.jpg
││├──Rafi2.jpg
│├──Firza
││├──Firza1.jpg
││├──Firza2.jpgAlso, if you use Kadita CV in your GitHub projects, please addKaditaCVin therequirements.txt.LicenceKadita CV is licensed under the MIT License - seeLICENSEfor more details.