Python 3 Deepface AI Script to Detect & Analyze Faces in Images in Terminal
3K views
Jun 3, 2025
Buy the full source code of application here:
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:03
so in this video I will show you a
0:04
Python
0:05
script which will analyze the face
0:10
inside images it will give you more
0:12
information about uh what expressions
0:15
what emotions are there inside a
0:17
particular face if the face is a woman
0:20
or a man or it's a emotion what kind of
0:23
emotion it's angry or happy so it's a
0:26
facial recognition and analysis uh
0:29
Python script I've written right here
0:32
and it will show you all these results
0:34
inside a JSON file so let me run this
0:36
Python script and let me give this
0:39
image 1 JPG as this is you can see it's
0:43
a guy image and let me just provide this
0:47
uh image for
0:49
example so if I run this script here so
0:52
what it will do it will run this Python
0:55
facial recognition system here which by
0:59
deface which is a third party module so
1:02
it will analyze this actual image based
1:05
upon the facial recognition what sort of
1:08
features that this image has and it will
1:10
now create this JSON file right here and
1:13
it will see it will analyze various
1:15
information regarding this image such as
1:17
age facial confidence what is the gender
1:20
you can see man
1:22
96% dominant gender man so emotion as
1:25
well what is the facial expression angry
1:30
sad everything it will tell
1:32
dominant emotion what is the race here
1:34
you will
1:37
see each and everything you can see it
1:41
will give you this JSON
1:43
file you can analyze any image for
1:46
example so the module that I'm talking
1:49
about is deep face just go to
1:53
your Python and here just search for
1:57
this library deep face just wait let me
2:01
just
2:03
open so this is actually the package
2:05
here deep
2:07
face command is very simple simply
2:10
execute this command to actually install
2:12
this deep face apart from that uh
2:16
we so now just make a simple app py file
2:21
uh so I will just show you how
2:24
to do this
2:28
so first of all we need to import this
2:31
deep face module so from deep face we
2:36
need to import deep face this is actual
2:39
package for analyzing the facial
2:42
expressions of an image and then we
2:44
initialize this so deep face and it
2:48
contains this function analyze and here
2:50
you provide your image actual image that
2:53
you want to provide let me provide this
2:56
angry
2:58
image a girl which is angry so then we
3:03
also
3:05
provide so this will be coming in the
3:07
image path so it takes this image path
3:11
and inside this you will provide your
3:13
image after that the second argument is
3:17
the actions that you need to explore so
3:20
here you can give parameters on which
3:23
you want to analyze your image so I want
3:25
to find out the age of the person the
3:28
gender and the
3:30
emotion also find out the emotion inside
3:33
the image and the
3:35
race what is the race of the person so
3:39
after that if I print out this object it
3:42
will analyze this image you will see it
3:46
will analyze this
3:48
image and give you the response in the
3:51
command line it's very simple
3:53
module you provide the actual image then
3:56
you provide the
3:58
actions and then it will give you the it
4:01
will analyze it based upon these various
4:04
factors and then it will give you this
4:06
response here the JSON response so what
4:09
we can do we can store this response in
4:11
a JSON
4:13
file so for saving this response in a
4:16
JSON we can use the open function so we
4:19
create this file here let me call this
4:21
as results dojson so it will actually
4:24
store all the results inside this file
4:26
results do.json so let me delete
4:28
everything and start from
4:31
scratch and if I run this Python script
4:33
now you will see it will analyze the
4:35
image and then on the left hand side it
4:38
will create that results.json file which
4:40
will hold the information regarding this
4:42
image
4:45
so just wait for it to complete so in
4:47
this way it is saying that uh the JSON
4:50
module is
4:54
not so let me just paste all the full
4:57
script here uh for for making the JSON
5:01
file we do need to import the JSON
5:03
module so this script I have given guys
5:05
in the description of this
5:07
video so you can
5:11
actually get the script the link is
5:14
given in the description so it will you
5:16
basically pass any sort of image then it
5:19
it will analyze that image and it will
5:22
store those observations inside this
5:25
JSON file so you will
5:28
see it will find out age
5:31
everything dominant gender emotion every
5:35
sort of information will be returned in
5:36
this JSON response so in this way guys
5:39
you can use this deep face package
5:42
facial recognition and analysis
5:44
framework for images and please hit that
5:47
like button subscribe the channel and
5:49
also check out my website
5:51
freemediattools.com which contains
5:53
thousands of tools
#Programming