VIETNAM NATIONAL UNIVERSITY HO CHI MINH CITY UNIVERSITY OF INFORMATION TECHNOLOGY ADVANCED PROGRAM IN INFORMATION SYSTEMSVU NGOC HAO NGUYEN CONG PHUONG NAM GRADUATION THESIS DEPLOYING A
Trang 1VIETNAM NATIONAL UNIVERSITY HO CHI MINH CITY UNIVERSITY OF INFORMATION TECHNOLOGY ADVANCED PROGRAM IN INFORMATION SYSTEMS
VU NGOC HAO NGUYEN CONG PHUONG NAM
GRADUATION THESIS
DEPLOYING A FACE RECOGNITION API ON KUBERNETES AND MOBILE APPLICATION FRAME
USING REACT-NATIVE
Trang 2VIETNAM NATIONAL UNIVERSITY HO CHI MINH CITY UNIVERSITY OF INFORMATION TECHNOLOGY
ADVANCED PROGRAM IN INFORMATION SYSTEMS
Trang 3ASSESSMENT COMMITTEE
The Assessment Committee is established under the Decision , date
" by Rector of the University of Information Technology.
1 - Chairman.
H1 - Secretary.
Trang 4ĐẠI HỌC QUỐC GIA TP HO CHÍMINH CONG HOA XÃ HỘI CHỦ NGHĨA VIỆT NAM
TRƯỜNG ĐẠI HỌC a ra Ũ
CÔNG NGHỆ THÔNG TIN Độc Lập - Tự Do - Hạnh Phúc
TP HCM, ngay thang ndm
NHAN XET KHOA LUAN TOT NGHIEP
CUA CAN BO HUONG DAN
Tên khóa luân:
DEPLOYING A FACE RECOGNITION API ON KUBERNETES AND MOBILE
APPLICATION FRAME USING REACT-NATIVE
Nhóm SV thực hiện: Cán bộ hướng dẫn:
Vii Ngọc Hào - 17521299 TS Đỗ Trọng Hợp
Nguyễn Công Phương Nam - 17520778
Đánh giá Khóa luận
1 Vé cuôn báo cáo:
Số bảng số liệu: - Số hình vẽ:
Số tài liệu tha Sản phẩm:
Một số nhận xét về hình thức cuốn báo cáo:
Trang 54 Về thái độ làm việc của sinh viên:
Danh gid Chung? 0
Điểm từng sinh viên:
Trang 6ĐẠI HỌC QUÓC GIA TP HÒ CHÍMINH CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM
TRƯỜNG ĐẠI HỌC Ty „
CÔNG NGHỆ THÔNG TIN Độc Lập - Tự Do - Hạnh Phúc
TP HCM, ngày tháng năm
NHẬN XÉT KHÓA LUẬN TÓT NGHIỆP
CUA CÁN BO PHAN BIEN
DEPLOYING A FACE RECOGNITION API ON KUBERNETES AND MOBILE
APPLICATION FRAME USING REACT-NATIVE Nhóm SV thực hiện: Cán bộ phản biện:
Vũ Ngọc Hào - 17521299 TS Lê Kim Hùng
Nguyễn Công Phương Nam - 17520778
Đánh giá Khóa luận
1 Vé cuôn báo cáo:
SỐ trang: ccccecccccrrrrree Số chương:
-Số bảng số liệu: - -Số hình
vẽ: Số tài liệu tham khảo Sản phẩm: -+
3 Về chương trình ứng dụng:
Trang 74 Về thái độ làm việc của sinh viên:
Danh gid Chung? 0
Điểm từng sinh viên:
Trang 8Thank You
The graduation thesis is the result of the author's work, research and study during his
time in the lecture hall of the University of Information Technology The author could not
have completed the graduation thesis well without the care and dedicated help of teachers, friends and family.
First of all, the team would like to express our sincere thanks to the staff of the
University of Information Technology - Vietnam National University, Ho Chi Minh City.
Ho Chi Minh and the Faculty of Information Systems have created a favorable environment and conditions, helping the author to have the basic knowledge as a basis to carry out the thesis.
In particular, the author would like to express deep gratitude and deepest gratitude to the instructor — Ph.D Do Trong Hop He directly guided, corrected and contributed many valuable comments to help the author successfully complete his graduation thesis.
Besides, the author would like to thank his family, relatives and friends of the same course
for encouraging, encouraging and supporting the author mentally during the completion of the graduation thesis.
During one semester of project implementation, the author has applied the accumulated background knowledge, combined with learning and researching new knowledge to complete a project report best way However, in the implementation process, the author cannot avoid shortcomings Therefore, the author is looking forward to receiving
suggestions from the teachers in order to improve the knowledge that the author has studied
and to be a preparation for the author to carry out other topics in the future.
Thank you very much, teachers!
Ho Chi Minh City, February 2023
Vu Ngoc Hao
Trang 9UNIVERSITY OF INFORMATION TECHNOLOGY
THESIS TITLE: DEPLOYING A FACE RECOGNITION API ON KUBERNETES AND
MOBILE APPLICATION FRAME USING REACT-NATIVE.
Advisor: Ph.D D6 Trong Hop
- Building a frame of mobile application face recognition based on a large user face registration.
- Basic functionality of the application:
o Provide a demo application for the face recognition.
©_ Provide 2 options:
® Mobile application for demo.
e Register and recognition api.
Scope:
Based on Face Detection, Face Recognition, Minio for high performance search and saved image Based on frameworks Tensorflow, React Native, Fastapi, py-torch, torch-lighting.
Trang 10- Selecting the suitable machine learning model.
© Goal: Selecting the right model that has fast convergence rates and light-weight.
o Content: Based on Triplet Loss, Arcface, Cosface for evaluating and selecting models.
co Expected results: Model selected and weights saved of the model.
- Selecting the inputs is crucial.
© Goal: Aim to high convergence for the model.
© Content: Based on test train, famous face recognition paper.
co Expected results: model extracts facial features and encodes it into vector.
- Al-Backend server will be deployed, application will be built on physical mobile device.
° Goal: Deploy AI - Backend server as a restful-api server, and application can run on a
physical mobile device.
o Content:
® Design AI- Backend server and deploy using Docker.
® Design Mobile applications that interact with AI-Backend servers, register,
recognition face api
co Expected results: Successfully building a mobile application for demonstration.
- Result:
© Provide an implementable apis and tracking mobile application frame.
Methodology:
- Parallel research and implementation.
- Distributed system design.
Result:
- Building a successful mobile application on a physical mobile device for demonstration.
- This system can deal with a large face register and high availability.
Research timelines:
- Research about Tensorflow modeling, Fastapi, py-torch, torch-lighting and integrate them
together (2 weeks).
- Research about flutter, building an example react native application (1,5 weeks).
- Selecting machine learning model (1,5 weeks).
Trang 11Research training input types for suggestion models, developing models for training (3 weeks) Training in data enrichment from Ifw (3 weeks).
Deploy backend server using docker (1 weeks).
Prepare a document for the thesis report (4 week).
References Document:
o Machine learning model:
* face recognition: https://arxiv.org/abs/2103.14983
* triplet loss for face embedding: https://arxiv.org/abs/1503.03832
Approved by the advisor
Trang 12Face detection Face recognition Minlo storage RESTfull API
Nginx proxy manager:
Research about React Native
Research about Ngrok Research about Expo
Research about Expo Camera
Research about Expo FaceDetector
Research about Expo ImageManipulator Research about Canvas
Overview 3.1.2 Workflow
Trang 133.3.1 Overview
3.3.2 Workflow
3.4.1 OV€TVÏ€W HH2 HH HH HH 1 1 11g 3.4.2 WorkflowW co th HH H111 re Chapter 4 IMPLEMENTATION 2t 2t 2t 2t tt thi 4.1 Face recognition API cú HH” HH HH gi 4.2 DepÏOyI€IIK - 1t HH” 22121121 1.121 HH gà ngư 4.3 L0ggÏng: tt 1 1 HH 1 01 1101011 1e 4.4 Swagger
4.4.1 APT face reC0gTnÏfÏOI nh ngHnH ng Ho TH ng tr 4.4.2 Face searching:
4.4.3 Getting all faC€s cọ HH1 1g 4.4.4 Deletting a FaCe: co co nh HH 1 re 4.4.5 Deleting a S€T- St th HH1 re 4.5 Minio console UI for manager S1 3t >Ev tr g rngg gtrrư 4.6 User ÍnferÍaCe 22t 2t t2 221122 2211211211111211 11 1 11111 1 1.10111011011011 ke 4.6.1 Structure
4.6.2 Demo fun€fiOIS - ¿5 522 2 2E 3E t2 211 1111.21.11.11 111.11 Chapter 5 CONCLUSION AND FUTURE VISION ¿5-55-5222 St E2 2E 1E 212210112111 11.111 11g tri 5,1 AdVanAg6 nh HH HH HT TH TH HH1 HT HH0 T1 T111 11k rkrk 5.2 Disadvanfage - cách 0H 101.11 01001011 11100 Š.3 Future YisÏ0n tt tinh 11 1 H01 101.111
REFERENCES
Trang 14List of figures
2.1 Workflow FAISS library work
2.2 The components of a Kubernetes cluster
2.3 Dataset sample English
2.4 Dataset sample challenge
2.5 Face checking process
2.6 Recognition process
2.7 Algorithm comparison image
2.8 Minlo provides storage space
2.9 Minlo architecture
2.10 Network architecture
1 Example Nginx proxy manager UI usage
2 Example nginx gateway status
3 Example nginx route config
Overview system architecture
3.2 Restful-API-core overview
3.3 Connection checking
3.4 Register workflow
3.5 Recognition workflow
3.6 Face tracking general workflow
3.7 Face processing detail workflow
3.8 Face processing detail workflow
3.9 Apply nginx in Kubernetes for management
4.1 Build process
4.2 Build process (cont)
4.3 API logging after start service manually
20
21 22
23 24
25 26
27
27 29
31
31
35
38 39 40
42
44
46 47
49
50 50
Trang 154.4 Swagger UI
4.5 Test register url
4.6 Test Search url
4.7 Test get all registered faces API
4.8 Test delete a registered face
4.9 Test delete a registered user
4.10 Minio manager storage
4.11 Minio manager storage (cont’s)
4.12 Function handle crops face
4.13 Function handle face identify
4.14 The main page return result
Trang 16Chapter 1 PROBLEM STATEMENT
1.1 Overview
Nowadays, information technology is developing day by day The application of
information technology in business is very popular Today's businesses are too familiar with
the application of information technology to their activities from simple or complex jobs
The world of technology is still changing every day and is increasingly simplifying
everything, finding the fastest solution to any problem To keep up with the times, we must
constantly adapt to the world and develop ourselves The more businesses grow, the more
employees there are, gradually making the job of managing employees more and more
difficult To ensure personal interests and to control more easily Therefore, it is very
important to build an attendance program to suit the situation.
Current timekeepers mainly use fingerprints, or some places use face recognition
fixed in one place Using these technologies still has certain limitations
Therefore, we chose the research topic of face recognition that can be used on the
phone to replace fixed attendance in one place
“Deploying a face recognition api on Kubernetes and Mobile application frame
The reason this thesis does not use available libraries for processing for facerecognition is because of limitations in personalization, management and system
implementation:
© Cannot separate the database and the system API separately, difficult to
expand the system It also reduces the availability of the whole system
© It is not possible to increase or decrease local resources when a small part of
the system needs excessive resources
Trang 17© Can't integrate faiss to find use gpu to speed up when data becomes big data.
1.2.2 Scope
With this graduate thesis, the main goal that I aim for when doing this is as follows:
o Provide an implementable apis and tracking mobile application frame
o Based on face detection, Face recognition, Minio for high performance search
and saved image
o Based on frameworks Tensorflow, react native, fastapi, py-torch,
torch-lighting
o Deployment environment: Docker-compose or Docker-swarm or K8s.
1.2.3 Objective
- Selecting the suitable machine learning model
o Goal: Selecting the right model that has fast convergence rates and
light-weight
o Content: Based on triplet loss, arcface, cosface for evaluating and selecting
models
o Expected results: Model selection and weights saved of the model
- Selecting the inputs is crucial
o Goal: Aim to high convergence for the model
o Content: Based on test train, famous face recognition paper
o Expected results: model extracts facial features and encodes it into vector
- AI-Backend server will be deployed, application will be built on physical mobile
device
o Goal: Deploy AT - Backend server as a restful-API server, and application can
run on a physical mobile device
o Content:
® Design AI- Backend server and deploy using Docker
e Design Mobile applications that interact with AI-Backend servers,
register, recognition face API
Trang 18o Expected results: Successfully building a mobile application for
Chapter 2: Literature review and theoretical background
Chapter 3: Model architecture
Trang 1902/11/2022 - 23/11/2022 Training data enrichment from Hào
lfw
24/11/2022 — 01/12/2022 Deploy backend sersver using Nam
docker
02/12/2022 — 28/12/2022 Prepare a document for the Hao
thesis report Nam
Trang 20Chapter 2 LITERATURE REVIEW AND THEORETICAL BACKGROUND
2.1 FAISS
FAISS stands for Facebook AI Similarity Search [1] This is a library that makes it
easy for developers to find extended versions of various informational content It addresses
the limitations of conventional query search methods designed with hash-based search in
mind and allows many other search engines to expand further
With FAISS, developers will search this content set in a variety of methods that are
not useful or impossible to use with standard database (SQL) engines alone It involves
implementing a search around closest to database pages in the millions to several billions in
size to ensure a balance of storage performance and accuracy FAISS aims to ensure high
performance for almost any important content, and these sites are also a big plus when your
access is slow or expensive
In this article, we will choose a FAISS-CPU library in python to index data and find
the latest data In addition, we also developed the FAISS interface for ease of working with
Trang 21We are using the FAISS library for N-dimensional vector data and storing it in ram
to simplify the search
2.2 Kubernetes
Kubernetes is a free, open source platform that allows extensive control over the
amount of products and data available in the storage area, including management and
automation functions [2] It has a large and fast-growing ecosystem Kubernetes services,
applications and tools are developed for free
The name Kubernetes comes from the Greek word, meaning rider or driver K8 is another
name for the eight letter calculation between the letter "K" and the letter "s” Google made
the official source code of the Kubernetes project available in 2014 Kubernetes combines
over 15 years of Google's experience in running this workload on a global scale with the
best ideas and methods from society
A dataset is a collection of data In other words, a data set fits the theme of a database
table or large dataset, where each of its columns represents a particular variable and rows
equate to a certain member of the dataset in question In Machine Learning projects, we
need a training dataset This is a dataset that can be used to train and practice a variety of
Trang 22activities Data sets are classified into three types that can be used for machine learning:
training set, validation set, and test set
Currently on the internet there are quite a few datasets showing how to recognize
Fake News Covid, but is using such datasets really useful and effective? Therefore, using
the dataset for actual training is one of the biggest challenges worth considering
The dataset collected and used by their team
- https://www.kaggle.com/competitions/face-recognition2/data
= kaggle a Kế xử
4 Create
@ Home
© Comet | Face recognition
Use non-parametric density estimation
+ trainJaffe.csv - the training set
+ testJaffe.csv - the test set
+ sample.Jaffe.csv - a sample submission file in the correct format + trainJaffelabels,csv - file containing labels
Figure 2.3 Dataset sample English
Trang 23- https://www.kaggle.com/datasets/atulanandjha/Ifwpeople
= kaggle Q search son GED
LFW - People (Face Recognition)
Create
† l a boo! +DataCard Code (26) Discussion (2) hàm) Newt Notetcor + Rownicad (24a) Tae
@ Home Welcome to Labeled Faces in the Wild, a database of face photographs designed for studying the problem of unconstrained License
face recognition The data set contains more than 13,000 images of faces collected from the web Each face has been labeled GNU Lesser General Public Lice.
© Competitions with the name of the person pictured 1680 of the people pictured have two or more distinct photos in the data set The only
constraint on these faces is that they were detected by the Viola-Jones face detector Expected update frequency
Keyword-based artificial intelligence (AI) computing technology (commonly known as
face recognition) is used to search for and recognize human faces in digital images Facial
recognition technology can be used in various aspects: from medical to biometrics, law
enforcement, entertainment and personal security to enhance control and surveillance of
people in the community real time
Face recognition has evolved from basic computer vision techniques to the advancement
of machine learning (ML) to highly sophisticated artificial neural networks (ANNs) and
many other technologies, and as a result, improved significant productivity improvement It
now plays an important role as the forerunner of other technologies - including face
monitoring, face analysis and facial recognition Facial recognition is closely related to how
this will work in the future
In face tracking, facial recognition that identifies the color of an image or video can be
added to determine age, gender and mood using facial expressions In a facial recognition
system that builds a map of each individual's facial features and stores them as faces, facial
recognition data is the basis that allows algorithms to determine the degree of Images or
Trang 24videos are suitable for face modeling Once identified, the new fingerprint can be compared
with the stored fingerprint to determine if there is a match
In this paper, we are using the face recognition database in python to determine if the
face retrieved from the user interface is suitable or not
incomming face image
Trang 252.5 Face recognition
Facial recognition is a way of identifying or confirming an individual's identity
through the use of their face Facial recognition systems can be used to identify things in
images, videos, or in real time
Facial recognition is a type of biometric authentication Various forms of biometrictechnology also include voice recognition, internal fingerprint recognition, and iris or eyelid
recognition The technology is mostly used for security and legal compliance, but there are
also people who focus on some private uses
pecs)
v
incomming face image
v
2S»
“cheœk
number of exist face
Trang 26The figure above is how the register for new faces works in the backend.
There are many algorithms to apply to face recognition such as: ArcFace [3],
ArcOrthFace, ArcCentFace, MagFace, In this article , I am using the ArcFace algorithm
to apply to my face recognition system because based on this research
(https://www.researchgate.net/publication/363062634 Additive Orthant Loss for Deep_
Face_Recognition ) you can see the best accuracy is ArcFace
Loss Function Rank1 Accuracy Verification Accuracy
MinIO 1s an advanced, high-performance object storage system [4] It is built by
operating system, based on industry standards, and is 100% open source under the license
GNU AGPL v3
MinIO is different in that it was built from the ground up to the standards of
integrated/distributed cloud object storage Because MinIO is purposefully developed to
support every object in a single layer architecture achieving most of the essential features
without being involved The result is a single cloud-native object server that is fast, open,
and lightweight
While MinIO excels in many areas such as legacy object storage for secondary
storage, error correction, and caching, MinIO is unique in experiencing the effects of big
data workloads across the globe cloud, machine learning, and processing
Trang 27My Object
Data My Bucket
Figure 2.9 Minio architecture
Trang 282.7 RESTfull API
A RESTful API is an architectural style for application program interfaces (APIs)
that use HTTP requests to exploit data usage The data api can be used for GET, PUT, POST
and DELETE many types of data, for the analysis, synthesis, compilation and deletion of
necessary information about the environment
The simplest way to use the REST API definition is to first know what an API is API
is an acronym for application programming language that is often used to link applications
together to perform a function built on the exchange of data and perform predetermined
tasks In essence, it allows one piece of software to interact with another The REST API
is one of the two most widely implemented forms of API, and the other is called the Simple
Objects Support (SOAP) API
REST is an enterprise support structure based on a question/answer model The REST
API has become familiar as part of the Web Service implementation approach Developers
using RESTful APIs can send emails and receive replies over many HTTP functions
2.8 Nginx proxy manager:
Authorization is also used in distributing data between several servers to seamlessly
share content from multiple websites with each other or to send processing requests to
application servers through methods outside of HTTP
Nginx is an open source web server with many features including reverse proxy,
caching, content allocation, data delivery, and more It starts with a web server built for
optimal performance and security With many HTTP server features, NGINX has also acted
as a proxy server for email (IMAP, POP3 and SMTP) as well as a reverse proxy and load
balancer on HTTP/2, TCP and UDP protocols.
Nginx uses an event-driven connection that allows multiple requests to be handled
without synchronization It is developed to use asynchronous event-driven connection
handling technology Therefore, the project process allows handling thousands of
connections (requests) through 1 thread These connection handling modules allow Nginx
Trang 29to work extremely quickly and efficiently with small amounts of data In addition, you also
use Nginx which allows to handle more than 10,000 parallel connections with low resources
(CPU & Memory) under heavy requests
The Nginx reverse proxy acts as an intermediary server that processes your requests
and passes the data to the appropriate upstream supporting server and thereby sends the
information from the server to the system Reverse proxies provide the same features as an
abstraction layer above upstream servers
In this article, we are using 2 types of proxies The picture below depicts the
Internal service Internal service Internal service Internal service Internal service Internal service
Figure 2.10 Network architecture
Trang 30Proxy types:
Nginx proxy manager: responsibility for forward traffic for each cluster in local
network Nginx proxy manager is a proxy with UI configuration and can gen cert using
certbot inside and cert is signed by letsencrypt for free
Ộ Nginx Proxy Manager Baristi000
Proxy Hosts luanvan|
Let's a
kubesphere-luanvan.hem ud.a torage-luanvan.hcm.u a lân m.unicloud.ai http://10.30.2.54:31080 Public
e Encrypt Online
Figure 2.11 Example Nginx proxy manager UI usage
Nginx cluster gateway is responsibility for routing traffic to each service inside k8s
cluster Nginx cluster gateway is a k8s gateway and configurable using gateway and route
Each route can be configured via k8s annotation
Trang 31© Getting Started Getting Started ©) How can | use dock Administering secur Umee / Umee Crm- ©) Ubuntu 20.04 LTS (
© Piattorm Workbench 'É% KUBESPHERE 3 xám ~
Figure 2.12 Example nginx gateway status
Baie Routing Rules
+ Set Routing Rules
Trang 322.9 Research about React Native
React Native is a JavaScript framework that can build realistic mobile apps that are
optimally supported on iOS and Android [5] It is based on React and Facebook's JavaScript
library to improve the consumer experience, but instead of focusing on apps, it focuses on
certain android devices
Advantages of React Native:
- Save time when you need fast application development
- Works quite efficiently
- Stable development community
- Save cash.
- Small development team
- Reliable and sustainable application
- Build on different platforms with the least amount of native code
Risks and reductions:
- No native code required.
- Performance will be low compared to apps with native code
- The safety is not high because it is based on JavaScript
- Data management.
- Customization also doesn't really work with some modules
2.10 Research about Ngrok
Ngrok is a tunnel building tool that connects your local computer and the internet [6] It
helps some people on the internet connect to your local computer via Ngrok’'s custom
domain