13.7 azface detect hats pipeline
20210406
Letβs use a pipeline to count the number of faces with their forehead occluded. If their forehead is occluded perhaps they are wearing a hat! Letβs check. We will use this photo again:
First we count the number of faces that the model finds that the
forehead is occluded. We saw in Section 13.3 that the
model can identify forehead_occluded
so here we run the model and
pipe the result to the grep command. This keeps only
those faces with forehead_occluded
. Then pass the output on to the
wc command (for word count), giving it the option -l
(short for --lines
) to count the number of lines rather than the
number of words.
So there are 4 faces with forehead_occluded
. But from the photo we
might have identified just 3 people wearing caps. So letβs check who
have been identified as having their forehead occluded. This gets a
little more complicated since we will draw a box around the face for
each of the 4 faces of interest. See Section
?? for an explanation of this
more complex pipeline. Replace the link to the photo with any other
file and you can mark up any photo.
$ ml detect azface 3818.jpg |
grep forehead_occluded |
cut -d, -f1 |
xargs printf "-draw 'polygon %s,%s %s,%s %s,%s %s,%s' " |
awk '{print "3818.jpg -fill none -stroke red -strokewidth 5 " $0 "bb.png"}' |
xargs convert
This produces the following file bounded.png
, noting the outlier
has hair covering her foreheadβshe is not actually wearing a cap. We
always need to be careful with our assumptions!
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0