SlideShare a Scribd company logo
1 of 15
Finding Faces:
a Kaggle Competition
Facial Keypoint Detection Using R
May 12th, 2016
Geneva Porter
Porter, Porter & Porter Inc.
270 C Street Suite B18
(619) 376-9793
geneva.porter@gmail.com
Abstract
Currently, there are demands for advancement in facial recognition
software. This report focuses on the submission process for the Kaggle Competition
“Facial Keypoints Detection.” This competition asks for an algorithm that can detect
keypoints around the eyes, nose and mouth in images with faces. After using a training
set of images to establish a baseline for keypoint location, R was used to extract a vector
that combined these averages into a composite image. By comparing this vector to the
area around each keypoint, specifically the tone of individual pixels, we were able to
approximately predict the location of these same keypoints in test images.
While our results were adequate for the purposes of this Kaggle Competition, far
more complex analysis would be needed for application in larger software such as facial
tracking, expression analysis, medical diagnosis, and face recognition. While such an
algorithm can be a useful tool for these applications, for the purposes of this report we
will keep it simple. Looking at small vectors and evaluating similarities within each
image is just a starting point for a more advanced facial keypoint detection method.
Kaggle Project & Background
The problem presented here is to form an algorithm that accurately predicts
keypoints on a face given an image containing one. We can use mathematical models to
detect subtle changes in tone variation and location of facial features in order to
formulate a process that can detect the eyes, brows, nose and mouth present in an
image. Given training data and test data, we can “train” our algorithm to evaluate an
average location and tonal area for each keypoint, and see how well it predicts keypoints
in our “test” data. Since facial features are significantly different from one person to
another, finding these needed keypoints can be very challenging. Here, we will create a
simple algorithm for detecting these keypoints based on the competition outlined on
Kaggle.com.
Data, Method & Results
Our algorithm will be “trained” using basic data provided by Dr. Yoshua Bengio
from the University of Montreal, via the Kaggle Competitions website. The data consists
of 7,049 images that have already been tagged for facial keypoints, and is considered
highly reliable. In addition, there are a series of “test” images that can be used for
evaluating the effectiveness of our constructed algorithm. Our objective is to use this
data to form a model that can identify the presence of faces as well as distinguish unique
faces from one another. This project had many applications, like social media, law
enforcement, and genealogy.
To formulate our model, we must first establish which keypoints we will be using
for facial detection. We will begin with a simple model of 15 keypoints, using the
following descriptors:
left_eye_center
right_eye_center
left_eye_inner_corner
left_eye_outer_corner
right_eye_inner_corner
right_eye_outer_corner
left_eyebrow_inner_end
left_eyebrow_outer_end
right_eyebrow_inner_end
right_eyebrow_outer_end
nose_tip
mouth_left_corner
mouth_right_corner
mouth_center_top_lip
mouth_center_bottom_lip
Here is an example of an image that highlights these keypoints. Note that green
point indicate the right eye, blue points indicate the left eye, yellow points indicate the
right brow, purple points indicate the left brow, the red point indicates the nose and the
white points indicate the mouth.
Fig.[1] A 96-square
pixel test image for keypoint
detection
Our “training data” has already identified these points on our sample images, and
we will start by finding the average location of each feature. This will tell us an
approximation of where to expect these features when processing images for facial
recognition. Here is a visual representation of where all the eyes (center), noses, and
mouths (center bottom) in
our sample images are
located:
Fig.[2] keypoints
for eyes, nose, and mouth
for all test images
As we can see, the results form an image of a scary clown. Although these results
are quite widespread, they tell us valuable information. We now have the mean location
of each feature. Once we have established this baseline, we must manipulate our
algorithm to detect outliers. Few images in the real world will be featured with a
forward, centered face that is easy to identify. Notice that in Fig.[2], there is a clear
outlier face in the bottom left corner. This face corresponds to the following image (the
keypoint for the mouth is in black, for clarity).
Fig.[3] keypoints
for an outlier face
Clearly, the location of these facial features are far from the mean. Our solution
will be to evaluate facial features relative to average tone, rather than relative to the
average location. In order to do this, we will use R coding language to evaluate images.
Our first step in creating an algorithm for reading facial recognition keypoints is
to construct a data frame in R. This is a matrix that categorizes our 30 facial recognition
keypoints into columns, and 7049 images into numbers for each row. We begin by
implementing this process with our “training” file, created with keypoints already set.
We can create a variable “im.train” that will hold the values of each image row when
split into 9,216 columns (92 x 92 = 9,216), each representing a single pixel and its
grayscale tone for each 92 x 92 pixel image.
d.train <- read.csv(train.file, stringsAsFactors=F)
im.train <- foreach(im = im.train, .combine=rbind) %do% {
as.integer(unlist(strsplit(im, " ")))}
We can convert these 9,216 numbers from each row into a 92 x 92 matrix to give
us a visual picture of what we are working with. Using the “image” function in R, we
plotted keypoints on one of our training images (Fig.[1,2]) to show an example and the
average location of important keypoints. Our primary basic algorithm simply uses these
average locations as a guide for finding facial keypoints in all other images. Using the
“colMeans” function, we can get these averages from our training images (see
Table[1]). However, these averages will not be very accurate. They will guess the
position of the eyes, nose and face regardless of the image at hand. To go further, we
must use more information--like the expected tone of each keypoint pixel--to improve
our recognition algorithm.
Table [1] Average Locations of Facial Keypoints
Keypoint X-axis Location Keypoint Y -axis Location
left_eye_center_x 66.35902 left_eye_center_y 37 .65123
right_eye_center_x 30.30610 right_eye_center_y 37 .97694
left_eye_inner_corner_x 59.15934 left_eye_inner_corner_y 37 .94475
left_eye_outer_corner_x 7 3.33048 left_eye_outer_corner_y 37 .70701
right_eye_inner_corner_x 36.65261 right_eye_inner_corner_y 37 .98990
right_eye_outer_corner_x 22.38450 right_eye_outer_corner_y 38.03350
left_eyebrow_inner_end_x 56.06851 left_eyebrow_inner_end_y 29.33268
left_eyebrow_outer_end_x 7 9.48283 left_eyebrow_outer_end_y 29.7 3486
right_eyebrow_inner_end_x 39.32214 right_eyebrow_inner_end_y 29.50300
right_eyebrow_outer_end_x 15.87118 right_eyebrow_outer_end_y 30.42817
nose_tip_x 48.37419 nose_tip_y 62.71588
mouth_left_corner_x 63.28574 mouth_left_corner_y 7 5.97071
mouth_right_corner_x 32.90040 mouth_right_corner_y 7 6.17977
mouth_center_top_lip_x 47 .97541 mouth_center_top_lip_y 7 2.91944
mouth_center_bottom_lip_x 48.56947 mouth_center_bottom_lip_y 7 8.97015
Our next building block uses image patches to add precision to our method.
Using each keypoint as an anchor, we can look at a field of pixels around an average
keypoint location and extract this area as a vector. This gives us an expected image for
that keypoint, and we can compare this amalgamation with keypoint areas on our test
images.
coord <- "nose_tip"
patch_size <- 10
coord_x <- paste(coord, "x", sep="_")
coord_y <- paste(coord, "y", sep="_")
patches <- foreach (i = 1:nrow(d.train), .combine=rbind) %do% {
im <- matrix(data = im.train[i,], nrow=96, ncol=96)
x <- d.train[i, coord_x]
y <- d.train[i, coord_y]
x1 <- (x-patch_size)
x2 <- (x+patch_size)
y1 <- (y-patch_size)
y2 <- (y+patch_size)
if ( (!is.na(x)) && (!is.na(y)) && (x1>=1) && (x2<=96) && (y1>=1)
&& (y2<=96) )
{as.vector(im[x1:x2, y1:y2]) } else {NULL}}
mean.patch <- matrix(data = colMeans(patches), nrow=2*patch_size+1,
ncol=2*patch_size+1)
This means that we can tell R to “look” for a similar vector around each average
keypoint location in our test images and adjust the keypoint to better resemble the
defined vector. We can call this our “average patch,” to represent the keypoint image
average. For example, looking at the average of the 10 pixels surrounding the nose
keypoint (giving us a 21-pixel square from 10 + 1 + 1) for each training image, we get
Fig.[4].
Fig.[4] Average image for
“nose tip” keypoints.
This looks like a good
approximation of an average nose.
By finding the position that best
matches our average patch, our algorithm becomes much more precise. For our desired
algorithm, each keypoint on each image must go through this process. Luckily, we need
not do this task for each of the 15 keypoints individually. We can make use of our
“foreach” function to compare each image patch to each test image. (See Appendix 2 for
code used.) After computing the average patches and applying them to our test images,
the submission to Kaggle is ready.
Solution & Conclusions
This method proves effective for this simple Kaggle Competition, but does not
take into account more complex situations. Profiles, out-of-focus images, or partial
faces cannot be detected. While the test images were all correctly identified, real-world
images may not be as clear. Images that have no faces, multiple faces, or faces of similar
species may not be correctly sorted, depending on the content. This project turned out
to be moderately successful. Given another test file, I would be curious to see how it this
algorithm measured up. I could definitely improve this ranking by tinkering with more
variations in tonal averages for keypoints, and perhaps implement an algorithm that
took into account keypoints in relation to each other on a single image. There are many
options to explore with this data in the future.
Kaggle Experience
When first logging onto Kaggle Competitions, I was very interested in several of
the challenges: satellite image chronology, predicting the artist of paintings, Reddit
comments, and learning the programming language Julia. However, since I had a
limited amount of time and I wanted to further improve my knowledge of R, I chose the
project “Facial Keypoints Detection.” This project had a tutorial for using R in this
context, and it seemed manageable to complete in 2 weeks.
Going through the tutorial was simple enough. Unfortunately, I don’t have a GPU
at my disposal, so some of the calculations took several minutes. At the end of the
tutorial, there were several links that offered “next steps” for taking this competition
further. I explored these sites and found that many required more powerful computers,
programming language unknown to me, and lengthy discussions on bugs and the merits
of alternative methods. As much as I would have liked to dive deeper into some of these
topics, I simply did not have the hardware, software, or knowledge to implement these
more complex approaches. I did get to explore a few forums that elaborated on this
project, and borrowed from users’ comments and feedback.
Overall, I’m very happy to have been introduced to Kaggle. Perhaps this summer,
I will have the time (and the use of a programmer friend’s computer) to learn a bit more
about the competitions that interest me and gain experience in a few more
programming languages like C++ and Python. Kaggle will definitely be a page that I visit
regularly to see updates and work through tutorials.
References
1. Kaggle Competitions, “Facial Keypoints Detection”, www.kaggle.com
2. Dr. Yoshua Bengio, University of Montreal
3. James Petterson, “Facial Keypoints Detection” (tutorial), Kaggle
4. GitHub Gist, “Code for Kaggle Getting Started with R: Facial Keypoint Detection
Competition”, www.gist.giethub.com
Appendix 1:
Kaggle Competition Results
Appendix 2:
Image Patch Implement Code
im.train <- foreach(im = d.train$Image, .combine=rbind) %do% {
as.integer(unlist(strsplit(im, " ")))}
im.test <- foreach(im = d.test$Image, .combine=rbind) %do% {
as.integer(unlist(strsplit(im, " ")))}
d.train$Image <- NULL
d.test$Image <- NULL
coordinate.names <- gsub("_x", "", names(d.train)[grep("_x",
names(d.train))])
mean.patches <- foreach(coord = coordinate.names) %do% {
cat(sprintf("computing mean patch for %sn", coord))
coord_x <- paste(coord, "x", sep="_")
coord_y <- paste(coord, "y", sep="_")
patches <- foreach (i = 1:nrow(d.train), .combine=rbind) %do%
{im <- matrix(data = im.train[i,], nrow=96, ncol=96)
x <- d.train[i, coord_x]
y <- d.train[i, coord_y]
x1 <- (x-patch_size)
x2 <- (x+patch_size)
y1 <- (y-patch_size)
y2 <- (y+patch_size)
if ( (!is.na(x)) && (!is.na(y)) && (x1>=1) && (x2<=96) &&
(y1>=1) && (y2<=96) )
{as.vector(im[x1:x2, y1:y2])} else
{NULL}}
matrix(data = colMeans(patches), nrow=2*patch_size+1,
ncol=2*patch_size+1)}
p <- foreach(coord_i = 1:length(coordinate.names),
.combine=cbind) %do% {
coord <- coordinate.names[coord_i]
coord_x <- paste(coord, "x", sep="_")
coord_y <- paste(coord, "y", sep="_")
mean_x <- mean(d.train[, coord_x], na.rm=T)
mean_y <- mean(d.train[, coord_y], na.rm=T)
x1 <- as.integer(mean_x)-search_size
x2 <- as.integer(mean_x)+search_size
y1 <- as.integer(mean_y)-search_size
y2 <- as.integer(mean_y)+search_size
x1 <- ifelse(x1-patch_size<1, patch_size+1, x1)
y1 <- ifelse(y1-patch_size<1, patch_size+1, y1)
x2 <- ifelse(x2+patch_size>96, 96-patch_size, x2)
y2 <- ifelse(y2+patch_size>96, 96-patch_size, y2)
params <- expand.grid(x = x1:x2, y = y1:y2)
r <- foreach(i = 1:nrow(d.test), .combine=rbind) %do% {
if ((coord_i==1)&&((i %% 100)==0)) {
cat(sprintf("%d/%dn", i, nrow(d.test))) }
im <- matrix(data = im.test[i,], nrow=96, ncol=96)
r <- foreach(j = 1:nrow(params), .combine=rbind) %do% {
x <- params$x[j]
y <- params$y[j]
p <- im[(x-patch_size):(x+patch_size), (y-
patch_size):(y+patch_size)]
score <- cor(as.vector(p),
as.vector(mean.patches[[coord_i]]))
score <- ifelse(is.na(score), 0, score)
data.frame(x, y, score}
best <- r[which.max(r$score), c("x", "y")]}
names(r) <- c(coord_x, coord_y)
r
}
predictions <- data.frame(ImageId = 1:nrow(d.test), p)
submission <- melt(predictions, id.vars="ImageId",
variable.name="FeatureName", value.name="Location")

More Related Content

Similar to Facial Keypoint Detection Using R

Spontaneous Smile Detection with Application of Landmark Points Supported by ...
Spontaneous Smile Detection with Application of Landmark Points Supported by ...Spontaneous Smile Detection with Application of Landmark Points Supported by ...
Spontaneous Smile Detection with Application of Landmark Points Supported by ...cscpconf
 
Image–based face-detection-and-recognition-using-matlab
Image–based face-detection-and-recognition-using-matlabImage–based face-detection-and-recognition-using-matlab
Image–based face-detection-and-recognition-using-matlabIjcem Journal
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentIJERD Editor
 
Antispoofing techniques in Facial recognition
Antispoofing techniques in Facial recognitionAntispoofing techniques in Facial recognition
Antispoofing techniques in Facial recognitionRishabh shah
 
Report Face Detection
Report Face DetectionReport Face Detection
Report Face DetectionJugal Patel
 
Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...
Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...
Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...sadique_ghitm
 
Facial landmarking localization for emotion recognition using bayesian shape ...
Facial landmarking localization for emotion recognition using bayesian shape ...Facial landmarking localization for emotion recognition using bayesian shape ...
Facial landmarking localization for emotion recognition using bayesian shape ...csandit
 
FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...
FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...
FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...cscpconf
 
Criminal Detection System
Criminal Detection SystemCriminal Detection System
Criminal Detection SystemIntrader Amit
 
Face Detection - David
Face Detection - DavidFace Detection - David
Face Detection - DavidVu Tran
 
Face Recognition Using Gabor features And PCA
Face Recognition Using Gabor features And PCAFace Recognition Using Gabor features And PCA
Face Recognition Using Gabor features And PCAIOSR Journals
 
De duplication of entities with-in a cluster using image matching
De duplication of entities with-in a cluster using image matchingDe duplication of entities with-in a cluster using image matching
De duplication of entities with-in a cluster using image matchingSaurabh Singh
 
IRJET - Emotion Recognising System-Crowd Behavior Analysis
IRJET -  	  Emotion Recognising System-Crowd Behavior AnalysisIRJET -  	  Emotion Recognising System-Crowd Behavior Analysis
IRJET - Emotion Recognising System-Crowd Behavior AnalysisIRJET Journal
 
Real time voting system using face recognition for different expressions and ...
Real time voting system using face recognition for different expressions and ...Real time voting system using face recognition for different expressions and ...
Real time voting system using face recognition for different expressions and ...eSAT Publishing House
 
Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113Editor IJARCET
 
Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113Editor IJARCET
 
A novel approach for performance parameter estimation of face recognition bas...
A novel approach for performance parameter estimation of face recognition bas...A novel approach for performance parameter estimation of face recognition bas...
A novel approach for performance parameter estimation of face recognition bas...IJMER
 
A Hybrid Approach to Recognize Facial Image using Feature Extraction Method
A Hybrid Approach to Recognize Facial Image using Feature Extraction MethodA Hybrid Approach to Recognize Facial Image using Feature Extraction Method
A Hybrid Approach to Recognize Facial Image using Feature Extraction MethodIRJET Journal
 

Similar to Facial Keypoint Detection Using R (20)

Spontaneous Smile Detection with Application of Landmark Points Supported by ...
Spontaneous Smile Detection with Application of Landmark Points Supported by ...Spontaneous Smile Detection with Application of Landmark Points Supported by ...
Spontaneous Smile Detection with Application of Landmark Points Supported by ...
 
Image–based face-detection-and-recognition-using-matlab
Image–based face-detection-and-recognition-using-matlabImage–based face-detection-and-recognition-using-matlab
Image–based face-detection-and-recognition-using-matlab
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
Antispoofing techniques in Facial recognition
Antispoofing techniques in Facial recognitionAntispoofing techniques in Facial recognition
Antispoofing techniques in Facial recognition
 
Report Face Detection
Report Face DetectionReport Face Detection
Report Face Detection
 
Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...
Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...
Study and Analysis of Novel Face Recognition Techniques using PCA, LDA and Ge...
 
Facial landmarking localization for emotion recognition using bayesian shape ...
Facial landmarking localization for emotion recognition using bayesian shape ...Facial landmarking localization for emotion recognition using bayesian shape ...
Facial landmarking localization for emotion recognition using bayesian shape ...
 
FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...
FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...
FACIAL LANDMARKING LOCALIZATION FOR EMOTION RECOGNITION USING BAYESIAN SHAPE ...
 
Real time facial expression analysis using pca
Real time facial expression analysis using pcaReal time facial expression analysis using pca
Real time facial expression analysis using pca
 
Criminal Detection System
Criminal Detection SystemCriminal Detection System
Criminal Detection System
 
Face Detection - David
Face Detection - DavidFace Detection - David
Face Detection - David
 
Face Recognition Using Gabor features And PCA
Face Recognition Using Gabor features And PCAFace Recognition Using Gabor features And PCA
Face Recognition Using Gabor features And PCA
 
De duplication of entities with-in a cluster using image matching
De duplication of entities with-in a cluster using image matchingDe duplication of entities with-in a cluster using image matching
De duplication of entities with-in a cluster using image matching
 
IRJET - Emotion Recognising System-Crowd Behavior Analysis
IRJET -  	  Emotion Recognising System-Crowd Behavior AnalysisIRJET -  	  Emotion Recognising System-Crowd Behavior Analysis
IRJET - Emotion Recognising System-Crowd Behavior Analysis
 
Real time voting system using face recognition for different expressions and ...
Real time voting system using face recognition for different expressions and ...Real time voting system using face recognition for different expressions and ...
Real time voting system using face recognition for different expressions and ...
 
Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113
 
Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113Volume 2-issue-6-2108-2113
Volume 2-issue-6-2108-2113
 
A novel approach for performance parameter estimation of face recognition bas...
A novel approach for performance parameter estimation of face recognition bas...A novel approach for performance parameter estimation of face recognition bas...
A novel approach for performance parameter estimation of face recognition bas...
 
A Hybrid Approach to Recognize Facial Image using Feature Extraction Method
A Hybrid Approach to Recognize Facial Image using Feature Extraction MethodA Hybrid Approach to Recognize Facial Image using Feature Extraction Method
A Hybrid Approach to Recognize Facial Image using Feature Extraction Method
 

Recently uploaded

Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxTanveerAhmed817946
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
Predicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationPredicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationBoston Institute of Analytics
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 

Recently uploaded (20)

Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptx
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Predicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationPredicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project Presentation
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 

Facial Keypoint Detection Using R

  • 1. Finding Faces: a Kaggle Competition Facial Keypoint Detection Using R May 12th, 2016 Geneva Porter Porter, Porter & Porter Inc. 270 C Street Suite B18 (619) 376-9793 geneva.porter@gmail.com
  • 2. Abstract Currently, there are demands for advancement in facial recognition software. This report focuses on the submission process for the Kaggle Competition “Facial Keypoints Detection.” This competition asks for an algorithm that can detect keypoints around the eyes, nose and mouth in images with faces. After using a training set of images to establish a baseline for keypoint location, R was used to extract a vector that combined these averages into a composite image. By comparing this vector to the area around each keypoint, specifically the tone of individual pixels, we were able to approximately predict the location of these same keypoints in test images. While our results were adequate for the purposes of this Kaggle Competition, far more complex analysis would be needed for application in larger software such as facial tracking, expression analysis, medical diagnosis, and face recognition. While such an algorithm can be a useful tool for these applications, for the purposes of this report we will keep it simple. Looking at small vectors and evaluating similarities within each image is just a starting point for a more advanced facial keypoint detection method.
  • 3. Kaggle Project & Background The problem presented here is to form an algorithm that accurately predicts keypoints on a face given an image containing one. We can use mathematical models to detect subtle changes in tone variation and location of facial features in order to formulate a process that can detect the eyes, brows, nose and mouth present in an image. Given training data and test data, we can “train” our algorithm to evaluate an average location and tonal area for each keypoint, and see how well it predicts keypoints in our “test” data. Since facial features are significantly different from one person to another, finding these needed keypoints can be very challenging. Here, we will create a simple algorithm for detecting these keypoints based on the competition outlined on Kaggle.com. Data, Method & Results Our algorithm will be “trained” using basic data provided by Dr. Yoshua Bengio from the University of Montreal, via the Kaggle Competitions website. The data consists of 7,049 images that have already been tagged for facial keypoints, and is considered highly reliable. In addition, there are a series of “test” images that can be used for evaluating the effectiveness of our constructed algorithm. Our objective is to use this data to form a model that can identify the presence of faces as well as distinguish unique faces from one another. This project had many applications, like social media, law enforcement, and genealogy.
  • 4. To formulate our model, we must first establish which keypoints we will be using for facial detection. We will begin with a simple model of 15 keypoints, using the following descriptors: left_eye_center right_eye_center left_eye_inner_corner left_eye_outer_corner right_eye_inner_corner right_eye_outer_corner left_eyebrow_inner_end left_eyebrow_outer_end right_eyebrow_inner_end right_eyebrow_outer_end nose_tip mouth_left_corner mouth_right_corner mouth_center_top_lip mouth_center_bottom_lip Here is an example of an image that highlights these keypoints. Note that green point indicate the right eye, blue points indicate the left eye, yellow points indicate the right brow, purple points indicate the left brow, the red point indicates the nose and the white points indicate the mouth.
  • 5. Fig.[1] A 96-square pixel test image for keypoint detection Our “training data” has already identified these points on our sample images, and we will start by finding the average location of each feature. This will tell us an approximation of where to expect these features when processing images for facial recognition. Here is a visual representation of where all the eyes (center), noses, and mouths (center bottom) in our sample images are located: Fig.[2] keypoints for eyes, nose, and mouth for all test images
  • 6. As we can see, the results form an image of a scary clown. Although these results are quite widespread, they tell us valuable information. We now have the mean location of each feature. Once we have established this baseline, we must manipulate our algorithm to detect outliers. Few images in the real world will be featured with a forward, centered face that is easy to identify. Notice that in Fig.[2], there is a clear outlier face in the bottom left corner. This face corresponds to the following image (the keypoint for the mouth is in black, for clarity). Fig.[3] keypoints for an outlier face Clearly, the location of these facial features are far from the mean. Our solution will be to evaluate facial features relative to average tone, rather than relative to the average location. In order to do this, we will use R coding language to evaluate images. Our first step in creating an algorithm for reading facial recognition keypoints is to construct a data frame in R. This is a matrix that categorizes our 30 facial recognition keypoints into columns, and 7049 images into numbers for each row. We begin by
  • 7. implementing this process with our “training” file, created with keypoints already set. We can create a variable “im.train” that will hold the values of each image row when split into 9,216 columns (92 x 92 = 9,216), each representing a single pixel and its grayscale tone for each 92 x 92 pixel image. d.train <- read.csv(train.file, stringsAsFactors=F) im.train <- foreach(im = im.train, .combine=rbind) %do% { as.integer(unlist(strsplit(im, " ")))} We can convert these 9,216 numbers from each row into a 92 x 92 matrix to give us a visual picture of what we are working with. Using the “image” function in R, we plotted keypoints on one of our training images (Fig.[1,2]) to show an example and the average location of important keypoints. Our primary basic algorithm simply uses these average locations as a guide for finding facial keypoints in all other images. Using the “colMeans” function, we can get these averages from our training images (see Table[1]). However, these averages will not be very accurate. They will guess the position of the eyes, nose and face regardless of the image at hand. To go further, we must use more information--like the expected tone of each keypoint pixel--to improve our recognition algorithm. Table [1] Average Locations of Facial Keypoints Keypoint X-axis Location Keypoint Y -axis Location left_eye_center_x 66.35902 left_eye_center_y 37 .65123 right_eye_center_x 30.30610 right_eye_center_y 37 .97694 left_eye_inner_corner_x 59.15934 left_eye_inner_corner_y 37 .94475
  • 8. left_eye_outer_corner_x 7 3.33048 left_eye_outer_corner_y 37 .70701 right_eye_inner_corner_x 36.65261 right_eye_inner_corner_y 37 .98990 right_eye_outer_corner_x 22.38450 right_eye_outer_corner_y 38.03350 left_eyebrow_inner_end_x 56.06851 left_eyebrow_inner_end_y 29.33268 left_eyebrow_outer_end_x 7 9.48283 left_eyebrow_outer_end_y 29.7 3486 right_eyebrow_inner_end_x 39.32214 right_eyebrow_inner_end_y 29.50300 right_eyebrow_outer_end_x 15.87118 right_eyebrow_outer_end_y 30.42817 nose_tip_x 48.37419 nose_tip_y 62.71588 mouth_left_corner_x 63.28574 mouth_left_corner_y 7 5.97071 mouth_right_corner_x 32.90040 mouth_right_corner_y 7 6.17977 mouth_center_top_lip_x 47 .97541 mouth_center_top_lip_y 7 2.91944 mouth_center_bottom_lip_x 48.56947 mouth_center_bottom_lip_y 7 8.97015 Our next building block uses image patches to add precision to our method. Using each keypoint as an anchor, we can look at a field of pixels around an average keypoint location and extract this area as a vector. This gives us an expected image for that keypoint, and we can compare this amalgamation with keypoint areas on our test images. coord <- "nose_tip" patch_size <- 10 coord_x <- paste(coord, "x", sep="_") coord_y <- paste(coord, "y", sep="_") patches <- foreach (i = 1:nrow(d.train), .combine=rbind) %do% { im <- matrix(data = im.train[i,], nrow=96, ncol=96) x <- d.train[i, coord_x] y <- d.train[i, coord_y] x1 <- (x-patch_size) x2 <- (x+patch_size) y1 <- (y-patch_size) y2 <- (y+patch_size)
  • 9. if ( (!is.na(x)) && (!is.na(y)) && (x1>=1) && (x2<=96) && (y1>=1) && (y2<=96) ) {as.vector(im[x1:x2, y1:y2]) } else {NULL}} mean.patch <- matrix(data = colMeans(patches), nrow=2*patch_size+1, ncol=2*patch_size+1) This means that we can tell R to “look” for a similar vector around each average keypoint location in our test images and adjust the keypoint to better resemble the defined vector. We can call this our “average patch,” to represent the keypoint image average. For example, looking at the average of the 10 pixels surrounding the nose keypoint (giving us a 21-pixel square from 10 + 1 + 1) for each training image, we get Fig.[4]. Fig.[4] Average image for “nose tip” keypoints. This looks like a good approximation of an average nose. By finding the position that best matches our average patch, our algorithm becomes much more precise. For our desired algorithm, each keypoint on each image must go through this process. Luckily, we need not do this task for each of the 15 keypoints individually. We can make use of our “foreach” function to compare each image patch to each test image. (See Appendix 2 for
  • 10. code used.) After computing the average patches and applying them to our test images, the submission to Kaggle is ready. Solution & Conclusions This method proves effective for this simple Kaggle Competition, but does not take into account more complex situations. Profiles, out-of-focus images, or partial faces cannot be detected. While the test images were all correctly identified, real-world images may not be as clear. Images that have no faces, multiple faces, or faces of similar species may not be correctly sorted, depending on the content. This project turned out to be moderately successful. Given another test file, I would be curious to see how it this algorithm measured up. I could definitely improve this ranking by tinkering with more variations in tonal averages for keypoints, and perhaps implement an algorithm that took into account keypoints in relation to each other on a single image. There are many options to explore with this data in the future.
  • 11. Kaggle Experience When first logging onto Kaggle Competitions, I was very interested in several of the challenges: satellite image chronology, predicting the artist of paintings, Reddit comments, and learning the programming language Julia. However, since I had a limited amount of time and I wanted to further improve my knowledge of R, I chose the project “Facial Keypoints Detection.” This project had a tutorial for using R in this context, and it seemed manageable to complete in 2 weeks. Going through the tutorial was simple enough. Unfortunately, I don’t have a GPU at my disposal, so some of the calculations took several minutes. At the end of the tutorial, there were several links that offered “next steps” for taking this competition further. I explored these sites and found that many required more powerful computers, programming language unknown to me, and lengthy discussions on bugs and the merits of alternative methods. As much as I would have liked to dive deeper into some of these topics, I simply did not have the hardware, software, or knowledge to implement these more complex approaches. I did get to explore a few forums that elaborated on this project, and borrowed from users’ comments and feedback. Overall, I’m very happy to have been introduced to Kaggle. Perhaps this summer, I will have the time (and the use of a programmer friend’s computer) to learn a bit more about the competitions that interest me and gain experience in a few more programming languages like C++ and Python. Kaggle will definitely be a page that I visit regularly to see updates and work through tutorials.
  • 12. References 1. Kaggle Competitions, “Facial Keypoints Detection”, www.kaggle.com 2. Dr. Yoshua Bengio, University of Montreal 3. James Petterson, “Facial Keypoints Detection” (tutorial), Kaggle 4. GitHub Gist, “Code for Kaggle Getting Started with R: Facial Keypoint Detection Competition”, www.gist.giethub.com
  • 14. Appendix 2: Image Patch Implement Code im.train <- foreach(im = d.train$Image, .combine=rbind) %do% { as.integer(unlist(strsplit(im, " ")))} im.test <- foreach(im = d.test$Image, .combine=rbind) %do% { as.integer(unlist(strsplit(im, " ")))} d.train$Image <- NULL d.test$Image <- NULL coordinate.names <- gsub("_x", "", names(d.train)[grep("_x", names(d.train))]) mean.patches <- foreach(coord = coordinate.names) %do% { cat(sprintf("computing mean patch for %sn", coord)) coord_x <- paste(coord, "x", sep="_") coord_y <- paste(coord, "y", sep="_") patches <- foreach (i = 1:nrow(d.train), .combine=rbind) %do% {im <- matrix(data = im.train[i,], nrow=96, ncol=96) x <- d.train[i, coord_x] y <- d.train[i, coord_y] x1 <- (x-patch_size) x2 <- (x+patch_size) y1 <- (y-patch_size) y2 <- (y+patch_size) if ( (!is.na(x)) && (!is.na(y)) && (x1>=1) && (x2<=96) && (y1>=1) && (y2<=96) ) {as.vector(im[x1:x2, y1:y2])} else {NULL}} matrix(data = colMeans(patches), nrow=2*patch_size+1, ncol=2*patch_size+1)} p <- foreach(coord_i = 1:length(coordinate.names), .combine=cbind) %do% { coord <- coordinate.names[coord_i] coord_x <- paste(coord, "x", sep="_") coord_y <- paste(coord, "y", sep="_") mean_x <- mean(d.train[, coord_x], na.rm=T) mean_y <- mean(d.train[, coord_y], na.rm=T) x1 <- as.integer(mean_x)-search_size x2 <- as.integer(mean_x)+search_size y1 <- as.integer(mean_y)-search_size y2 <- as.integer(mean_y)+search_size x1 <- ifelse(x1-patch_size<1, patch_size+1, x1) y1 <- ifelse(y1-patch_size<1, patch_size+1, y1) x2 <- ifelse(x2+patch_size>96, 96-patch_size, x2)
  • 15. y2 <- ifelse(y2+patch_size>96, 96-patch_size, y2) params <- expand.grid(x = x1:x2, y = y1:y2) r <- foreach(i = 1:nrow(d.test), .combine=rbind) %do% { if ((coord_i==1)&&((i %% 100)==0)) { cat(sprintf("%d/%dn", i, nrow(d.test))) } im <- matrix(data = im.test[i,], nrow=96, ncol=96) r <- foreach(j = 1:nrow(params), .combine=rbind) %do% { x <- params$x[j] y <- params$y[j] p <- im[(x-patch_size):(x+patch_size), (y- patch_size):(y+patch_size)] score <- cor(as.vector(p), as.vector(mean.patches[[coord_i]])) score <- ifelse(is.na(score), 0, score) data.frame(x, y, score} best <- r[which.max(r$score), c("x", "y")]} names(r) <- c(coord_x, coord_y) r } predictions <- data.frame(ImageId = 1:nrow(d.test), p) submission <- melt(predictions, id.vars="ImageId", variable.name="FeatureName", value.name="Location")