It's March 2020 and #COVID19 is all the rage nowadays; for all the wrong reasons.
Whether you're still working in an open office space or your company has done the responsible thing and sent everyone to remotely work from the comfort (and relative safety) of their home desk already, there are three things one can do to protect oneself from contracting the virus (other than avoiding public spaces):
thoroughly wash your hands with soap and
don't touch your face under no circumstances.
So, the motivation behind this blog post stems from a discussion with colleagues at work regarding that last point on the list; we all just seem to have the darnest of times keeping our hands away from our faces! I don't know if it's the nature of a desk job or whatever but using Tensorflow.js, some simple HTML and my laptop's webcam, I was able to count the number of times I touch my face during a typical 8 hours-long work day in the freaking hundreds...
Machine Learning to the rescue!
Or well, maybe just a simple TensorFlow model, some arbitrary weights after a whooping 5 minutes of training said model and 2 sets of 250 images for each of two image classes: my face and my hands.
The idea here is that you can use your laptop's webcam (which as a tech worker is more than likely just sitting there staring at your face not doing much anyhow) to prevent yourself from touching your face with your hands. Now, I say "prevent" but the best I could think of doing for the scope of this demo is play a really weird Zombie-like sound when the model detects your hand approaching your face in the camera's frame feed. I am sure y'all can get more creative than that though /wink.
Without further ado, the code for running this sample in the comfort of your own web server:
I used Google's TeachableMachines to train and host the TensorFlow model; it's quick and convenient for user cases involving binary model classifications and image-based data but you can always train and host your own model should you so decide. One additional benefit of using TeachableMachines for these kind of trivial experiments is that it allows exporting the model in various other Machine Learning frameworks, if that's your thing.
It's entirely likely that the data of my model are nowhere near granural enough to cover the characteristics of everyone's faces (spoiler: that's a certainty) so if you're looking to use the demo and you're not satisfied with the results, please create your own model instead and just replace the URL constant in the code sample when running it on your local dev environment.
If you're just getting started with TensorFlow, I can't recommend this masterclass by freecodecamp.org enough, it'll get you from zero to hero in under 7 hours.