<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rosa Gradilla on Medium]]></title>
        <description><![CDATA[Stories by Rosa Gradilla on Medium]]></description>
        <link>https://medium.com/@iselagradilla94?source=rss-cae7e5755852------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uhYEQcvP5dBC6m0TW0sGqQ.jpeg</url>
            <title>Stories by Rosa Gradilla on Medium</title>
            <link>https://medium.com/@iselagradilla94?source=rss-cae7e5755852------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:17:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iselagradilla94/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Gradient Boosting Machine explained from a philosophical perspective]]></title>
            <link>https://medium.com/@iselagradilla94/the-gradient-boosting-machine-explained-from-a-philosophical-perspective-fbe1107cd2d7?source=rss-cae7e5755852------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbe1107cd2d7</guid>
            <dc:creator><![CDATA[Rosa Gradilla]]></dc:creator>
            <pubDate>Sat, 06 Jun 2026 00:58:36 GMT</pubDate>
            <atom:updated>2026-06-06T00:58:36.512Z</atom:updated>
            <content:encoded><![CDATA[<p>Data science and philosophy are some of my favorite topics, which is why I thought it would be good use of my time to write this post explaining what a Gradient Boosting machine is, from a philosophical perspective. When it comes to tabular data, a gradient boosting machine is pretty much my go to. It tends to outperform other models in both classification and regression problems. In this post I will go over the Gradient Boosting methodology and the theory behind it.</p><p>In my next post I will go over a tutorial of how to implement an XGBoost model.</p><h3><strong>So, what is a Gradient Boosting Machine?</strong></h3><p>Let’s think about a dataset D with n samples. Each sample has a set of features, say m features per sample in a vector x, and a target value y, which is what we are trying to predict.</p><p>“In all things which have a plurality of parts, and which are not a total aggregate but a whole of some sort distinct from the parts”</p><p>-<strong>Aristotle, <em>Metaphysics</em> 8.6</strong></p><p>When we think about the whole, it is impossible not to think about the parts that make up a whole.</p><p>Gradient Boosting machines are an ensemble method, which means it <strong>combines multiple models</strong> to produce improved results. Think of this as a “many brains are better than one” approach. When we are trying to predict some value <em>y</em>, we are essentially trying to find the underlying function that spits out this y. The basic intuition for gradient boosting machines is a little bit philosophical, or at least I like to think of it that way: that if that underlying function is <strong>some complex function</strong>, it <strong>can be made up of smaller and simpler functions added together</strong>.</p><p>A gradient boosting model assumes this complex function can be broken up into simpler functions added together.</p><p>A gradient boosting model assumes this complex function can be broken up into simpler functions added together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I90BWCejUWihwS2ZTo9CXA.png" /></figure><p>The idea is not that any individual function (f_i) captures the truth of the phenomenon we are studying. Rather, each function captures a small aspect of it. Taken in isolation, each function may be a poor explanation. Taken together, however, they can approximate highly complex relationships.</p><p>This idea should sound familiar to anyone who has studied philosophy. Aristotle argued that a whole is not merely the sum of its parts, but that understanding the parts is nevertheless necessary to understanding the whole. A gradient boosting machine takes a similar approach. Instead of attempting to learn the entire underlying function in one step, it constructs the whole gradually through a collection of simpler models.</p><p>In practice, these simpler functions are usually decision trees. A single decision tree is often called a “weak learner.” It is not expected to be highly accurate on its own. Its purpose is simply to contribute some information that the overall model has not yet captured.</p><p>Suppose we begin with the simplest possible prediction. If we are solving a regression problem, our first prediction might simply be the average value of the target variable across all observations. This is obviously imperfect, but it gives us a starting point.</p><p>At this stage, the model makes mistakes. Some predictions are too high, while others are too low. These mistakes are called residuals:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*JZCAMpBvFeXpc8IBzrUDBg.png" /></figure><p>The residual represents the gap between reality and our current understanding of reality.</p><p>This is where the “boosting” part begins. Instead of building an entirely new model from scratch, we train a small decision tree to predict these residuals. In other words, we ask:</p><p>“What pattern explains the mistakes we are currently making?”</p><p>The new tree learns some portion of these errors and produces a correction. We then add this correction to our existing model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*FsVPDWrYt6I8Bh6J7sEXZg.png" /></figure><p>The process repeats. We calculate new residuals, train another tree to explain the remaining errors, and add its contribution to the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*wRzbuXZZF_Up9hRruC0ADw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*CQotMV-6P3wUM1HpE_u5-g.png" /></figure><p>And so on.</p><p>Viewed philosophically, this process resembles a form of epistemic refinement. We begin with a crude approximation of reality. We then confront the errors in our understanding and construct explanations for those errors. Each iteration produces a model that is slightly less wrong than before.</p><p>This perspective is one reason I find gradient boosting machines so elegant. Rather than claiming immediate access to the true underlying function, the algorithm proceeds through successive corrections.</p><p>Knowledge is accumulated incrementally. Each tree contributes a small insight, and the final model emerges from the aggregation of many partial truths.</p><p>The word “gradient” comes from the fact that these corrections are guided by a loss function, which quantifies how wrong our predictions are. At every step, the algorithm seeks the direction that most rapidly reduces this error. In mathematical terms, it follows the negative gradient of the loss function, much like descending a hill by continually taking steps in the direction of steepest downward slope.</p><p>The result is a model that often achieves remarkable predictive performance while remaining conceptually simple: identify errors, explain them, and incorporate those explanations into a growing body of knowledge.</p><h3>Conclusion</h3><p>What I find most interesting about gradient boosting machines is that they embody a surprisingly sophisticated view of knowledge.</p><p>A gradient boosting model does not begin with a perfect understanding of the world. It begins with a crude approximation. It then examines its mistakes, learns from them, and updates its understanding accordingly. Each new tree is not an entirely new theory; it is a correction to the shortcomings of the theories that came before it.</p><p>This idea bears a resemblance to Karl Popper’s philosophy of science. Popper argued that knowledge advances not through the accumulation of confirmations, but through the discovery and correction of errors. We formulate hypotheses, identify where they fail, and construct better explanations. Progress comes from becoming less wrong.</p><p>Gradient boosting follows a similar process. The model makes predictions, identifies its errors through the loss function, and trains new trees specifically to explain those errors. With each iteration, the model moves closer to the underlying relationship hidden within the data.</p><p>Of course, no machine learning model truly discovers the “essence” of a phenomenon. The model does not know why a customer churns, why a stock price changes, or why a disease progresses. It merely constructs an increasingly accurate approximation of the patterns present in the data. Yet there is something philosophically appealing about the method. Rather than assuming complete knowledge from the outset, it embraces the idea that understanding emerges through a sequence of corrections.</p><p>Perhaps this is why gradient boosting machines have remained one of the most successful approaches for tabular data. Their strength lies not in any individual decision tree, but in the cumulative effect of many small improvements. Just as our own understanding of the world develops through the gradual elimination of error, the model achieves predictive power through a process of continual refinement.</p><blockquote>Progress comes from becoming less wrong.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbe1107cd2d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building My Personal AI Diet Assistant: LogiBites]]></title>
            <link>https://medium.com/@iselagradilla94/building-my-personal-ai-diet-assistant-logibites-e5bd28595a2b?source=rss-cae7e5755852------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5bd28595a2b</guid>
            <category><![CDATA[nutrition]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Rosa Gradilla]]></dc:creator>
            <pubDate>Fri, 04 Apr 2025 16:03:40 GMT</pubDate>
            <atom:updated>2025-04-04T16:03:40.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JGenwbdt7taGeiLPNf1wxw.jpeg" /></figure><p>As someone who tracks calories and protein while managing a busy schedule, I wanted a tool that could help me stick to my goals without relying on tedious spreadsheets or manually logging every meal. So I built a custom AI-powered diet assistant that lives in my local machine, I don’t have a front end just yet. It tracks my food inventory, makes smart meal suggestions, and even pulls in nutritional data automatically.</p><p><strong>Why I Built It:</strong> Commercial apps are often bloated, lack customization, or require subscriptions. I wanted something lightweight, intelligent, and personalized to <em>my</em> kitchen and dietary goals. Plus, I’ve always liked building things that solve my own problems.</p><p><strong>Inventory Management Without a Database:</strong> I started with a basic inventory system written in Python, using a simple inventory.json file to store items. Each item includes name, quantity, unit, and nutritional info (protein, carbs, fat, calories). I built utilities to normalize units and track everything as grams, which makes comparing macros easier.</p><pre>{<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Greek Yogurt&quot;,<br>    &quot;category&quot;: &quot;Dairy&quot;,<br>    &quot;quantity&quot;: 150,<br>    &quot;unit&quot;: &quot;g&quot;,<br>    &quot;original_quantity&quot;: 1,<br>    &quot;original_unit&quot;: &quot;container&quot;,<br>    &quot;calories&quot;: 100,<br>    &quot;protein&quot;: 10,<br>    &quot;carbs&quot;: 5,<br>    &quot;fat&quot;: 2,<br>    &quot;source&quot;: &quot;USDA&quot;<br>}</pre><p><strong>Fetching Nutritional Info Automatically:</strong> Rather than manually entering nutritional data, I integrated with the<a href="https://www.ers.usda.gov/developer/data-apis"> USDA API</a>. Every time I add an item, the app fetches its macros automatically and stores them in the inventory file.</p><p><strong>AI-Powered Recipe Suggestions:</strong> Once the inventory system was working, I hooked it up to OpenAI’s API. I generate prompts based on a condensed view of the current inventory (grouped by category), asking GPT to create a high-protein, low-calorie recipe using what I already have. It’s like having a chef that knows my fridge.</p><p>Here’s an example of the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2-j7MTkXY9UCizUsRDHcQ.png" /></figure><p><strong>Smart Substitutions with AI:</strong> Another feature I added was AI-powered ingredient substitutions. If I’m missing a key item from a suggested recipe, I ask the model for viable alternatives based on my inventory. It suggests swaps like Greek yogurt for sour cream or lentils for ground beef — contextual and often creative.</p><p><strong>What’s Next:</strong> I want to build a proper UI, support meal logging and historical tracking, and maybe even explore integration with wearables or fitness apps, I would also like to integrate a feature to add items to my inventory from barcodes. For now, this assistant helps me eat better, waste less food, and stay on track with my goals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5bd28595a2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Style Transfer with a Special Application: Face Recognition.]]></title>
            <link>https://medium.com/@iselagradilla94/neural-style-transfer-with-a-special-application-face-recognition-945e5e6d2e91?source=rss-cae7e5755852------2</link>
            <guid isPermaLink="false">https://medium.com/p/945e5e6d2e91</guid>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[neural-style-transfer]]></category>
            <category><![CDATA[facial-recognition]]></category>
            <dc:creator><![CDATA[Rosa Gradilla]]></dc:creator>
            <pubDate>Wed, 26 Aug 2020 03:37:57 GMT</pubDate>
            <atom:updated>2020-08-26T04:15:12.055Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial I will go over how to implement <strong>Neural Style Transfer</strong> in a novel way: applying the style to only the face recognized in an image. In case you are not familiar with Neural-Transfer, it is an algorithm that allows you to take an image and apply another image’s “style” on it. This technique looks super cool if the style image is some sort of painting or of artistic nature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1DMdD3nHXyF4bp7_So9wA.png" /><figcaption>Content and Style images</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*5aGUayg0UdHST9cBVMnRfg.png" /><figcaption>Generated Image</figcaption></figure><p>In this tutorial I will show you how I used Neural-Style Transfer and facial recognition together to perform style transfer on just the face recognized in an image. For this project I created an application with <a href="https://www.streamlit.io/">Streamlit</a> to make the interaction with the algorithm very simple. Streamlit is a very easy and versatile app framework built for Python developers. It requires very minimal lines of code to turn a regular python script into an app, which is why I chose it for this project.</p><p>The application I created is quite simple, it asks you to upload a content and a style image, then you click the “Start computation” button and that’s it! you get your styled image back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0dyZefgMi-e1BAf4Wug_Zw.jpeg" /><figcaption>Elon + Picasso</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W1o-iazwcB4pEgTsYN2fEg.jpeg" /><figcaption>Andrew Ng + Circuit</figcaption></figure><p>The process of computing the style transfer is what required the most lines of code, I followed Pytorch’s <a href="https://pytorch.org/tutorials/advanced/neural_style_tutorial.html">tutorial</a> and modified it to suit my needs. In order to detect the face I leveraged <a href="https://github.com/timesler/facenet-pytorch">PyTorch’s MTCNN</a> implementation. This module allows you to create a MTCNN object able to detect the face’s bounding box in an image or video. Please install the module before so you can use it in your script, it is as easy as:</p><p><strong>pip install facenet-pytorch</strong></p><p>So let’s get started! I suggest you check out <a href="https://pytorch.org/tutorials/advanced/neural_style_tutorial.html">PyTorch’s tutorial</a> on how to perform Neural Style transfer. I used many of those functions in my script and I will briefly go over how each one works and what they are doing but if you would like a more in-depth explanation, please refer to the tutorial. Basically the pipeline consists of these steps:</p><ol><li><strong>Ask the user for content and style images</strong></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fff00aff4356dd868ddfb9703feea1d/href">https://medium.com/media/9fff00aff4356dd868ddfb9703feea1d/href</a></iframe><p>2.<strong> Initiate the Neural-Style network with a VGG19 pretrained model</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7c487d9947baba1a6b7b6e96794915c/href">https://medium.com/media/b7c487d9947baba1a6b7b6e96794915c/href</a></iframe><p>3. <strong>Use MTCNN to detect the face in the image and return bounding box coordinates. Expand the bounding box a little for the foreground extraction algorithm</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*my8frH5Y6CtLFnZLfejMEw.jpeg" /><figcaption>MTCNN detects the face and bounding box. After this we expand the bounding box a little larger for the foreground extraction algorithm</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d68761a6f734b651689333c1d4d7876/href">https://medium.com/media/0d68761a6f734b651689333c1d4d7876/href</a></iframe><p>4. <strong>Run the Style-Transfer on the detected face’s expanded bounding box.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*W9STTN6AlGP6isKAZv-2ig.png" /><figcaption>Neural-Style applied to bounding box</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d5b2ba249933321e6449f9d69e136d9/href">https://medium.com/media/9d5b2ba249933321e6449f9d69e136d9/href</a></iframe><p>5. <strong>Perform Foreground-Background separation on the face’s bounding box. This is done with the help of a semantic segmentation algorithm.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*bsin3NzQ3vsxbJMGdnwkJA.png" /><figcaption>A semantic segmentation model is used for foreground extraction</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73679d4e3ffc2d0fe9405b447e36e93d/href">https://medium.com/media/73679d4e3ffc2d0fe9405b447e36e93d/href</a></iframe><p>6. <strong>Get rid of the background and overlay the styled face on the original content image.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*-5tEVDyTz3kURuilCOpCBA.jpeg" /><figcaption>Final output</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d5b026e047dd301fad2e05a2d7f015e/href">https://medium.com/media/2d5b026e047dd301fad2e05a2d7f015e/href</a></iframe><p>In this tutorial I have decided to go over the main functions that perform the most important steps in the process. However, there are many other helper functions which I am not including in this tutorial because it would make it way too long. I wrote this post to present a big-picture point of view of what the the application does. Please refer to the <a href="https://github.com/rosagradilla19/style-transfer-face-recognition-app">Github </a>repository for the complete code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=945e5e6d2e91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Train a CNN to recognize and blur your face from a video with PyTorch and OpenCV]]></title>
            <link>https://medium.com/@iselagradilla94/train-a-cnn-to-recognize-and-blur-your-face-from-a-video-with-pytorch-and-opencv-7909547e2cde?source=rss-cae7e5755852------2</link>
            <guid isPermaLink="false">https://medium.com/p/7909547e2cde</guid>
            <dc:creator><![CDATA[Rosa Gradilla]]></dc:creator>
            <pubDate>Mon, 10 Aug 2020 23:45:33 GMT</pubDate>
            <atom:updated>2020-08-11T00:06:13.169Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the third post of my series for Face Detection with Pytorch and OpenCV. This story is following my previous post: <strong>How to build a Face Detection application using PyTorch and OpenCV. </strong>In this post we will be adding a CNN classifier and training it to recognize your face (or anyone else of your choice).</p><ol><li><strong>Collect the Data</strong></li></ol><p>The first thing you need to do is collect the data. The data will consist of two simple categories: you vs not-you. You will need about the same number of images of your face and of other people. I had about 300 images of my face and 300 images of other people, but the more you can collect the better.</p><p>Once you get your images you need to split them into training and validation sets. In your Dataset folder create two folders: train and val. Inside each folder have a folder for each category:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*XsyQ_vPMGVUo-3KIvhevmw.png" /><figcaption>Directory tree structure for Dataset</figcaption></figure><p>Make sure your dataset images are cropped to only the face. You can use MTCNN to detect the face and save the bounding box only. If you would like some help doing this, I have<strong> </strong><a href="https://www.youtube.com/watch?v=p5jhlEvCLlg"><strong>a video</strong></a> in which I explain how I take the frames of a video, collect the bounding box of my face and save them as images to build the dataset.</p><p><strong>2. Prepare the Data</strong></p><p>To train the CNN we will be using transfer learning. Transfer learning is when we use a CNN that has been trained for something else and we freeze all the weights except for the final fully connected layer. This last layer is replaced with random weights and only this layer is trained. Freezing all the other weights is helpful because since this CNN has already been trained, we can trust these weights are capable of extracting meaningful features.</p><p>The following is a script to label our data and export it as npy files that we will later use in a Google Colab notebook to train.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29fd65e6afc76c69be86e8f18a54c40e/href">https://medium.com/media/29fd65e6afc76c69be86e8f18a54c40e/href</a></iframe><p>Make sure you change the PATH for your dataset directory in line 30. This script will output 2 npy files: train_data.npy and val_data.npy. We will use these files in a Colab Google notebook to train. This is very helpful if you are like me and don’t have access to a GPU.</p><p><strong>3. Train the classifier</strong></p><p>In order to train our classifier we will use Google Colab. First add the npy files to your google drive, we will get access to these files by mounting to google drive. You can follow this <a href="https://colab.research.google.com/drive/1O05X4ldQEnMwrId7FillR5YTJB-JqEu8?usp=sharing">notebook</a> just make sure you mount to your own drive and change the path if necessary.</p><p>I have a<strong> </strong><a href="https://medium.com/@iselagradilla94/how-to-build-a-face-detection-application-using-pytorch-and-opencv-d46b0866e4d6?source=friends_link&amp;sk=b3fb560ad5b6843d47b6ecb419349db0"><strong>video</strong></a> going over the code and what each cell does. Please watch that if you are interested.</p><p><strong>4. Incorporate the classifier to the Face Detector</strong></p><p>Now that we have trained the classifier we will incorporate it to our Face Detector by adding class methods to our FaceDetector class. You can find the code for the FaceDetector class <strong>in my previous story</strong>. We will add a method to blur the face out of the frame (_blur_face()), a method to run the classifier and determine wether it is your face or not (_is_it_Rosa()), and we will also incorporate some lines in the _run() method to use the classifier. The new FaceDetector class with all the new methods is the following:</p><p>I have a <strong>video </strong>going over the script <a href="https://www.youtube.com/watch?v=kjD0Cf4HyCw&amp;feature=youtu.be"><strong>here</strong></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f05680b2784c2f00ccb27e3c8cc5ee0/href">https://medium.com/media/1f05680b2784c2f00ccb27e3c8cc5ee0/href</a></iframe><p>Now we can run the app from a different script by importing all the necessary scripts:</p><p>and you guessed it, there’s also a <a href="https://www.youtube.com/watch?v=xxXngT89oHw&amp;feature=youtu.be"><strong>video</strong></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/855633dd04a1701cad892334fc17c08d/href">https://medium.com/media/855633dd04a1701cad892334fc17c08d/href</a></iframe><p>Run your script through the terminal by typing python app.py when inside the folder in which you have your app.py script and look at your masterpiece!</p><p><strong>Note: </strong>you can also turn the blurring feature off by running the script as: python app.py — blur False.</p><p><strong>Thank you for following until the end!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7909547e2cde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a Face Detection application using PyTorch and OpenCV]]></title>
            <link>https://medium.com/@iselagradilla94/how-to-build-a-face-detection-application-using-pytorch-and-opencv-d46b0866e4d6?source=rss-cae7e5755852------2</link>
            <guid isPermaLink="false">https://medium.com/p/d46b0866e4d6</guid>
            <dc:creator><![CDATA[Rosa Gradilla]]></dc:creator>
            <pubDate>Tue, 28 Jul 2020 16:49:39 GMT</pubDate>
            <atom:updated>2020-07-28T16:49:39.495Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post I will show you how to <strong>build a face detection application capable of detecting faces and their landmarks through a live webcam feed</strong>. In the <a href="https://medium.com/@iselagradilla94/7909547e2cde?source=friends_link&amp;sk=cda20a1d9e7617883ae5ea236e19d9a8">following post I will also show you how to integrate a classifier to recognize your face (or someone else’s) and blur it out</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*d9q5xcpYgBZcT8KFJB7sxA.gif" /><figcaption>Face Detector in action</figcaption></figure><p>For this project I leveraged facenet-pytorch’s MTCNN module, <a href="https://github.com/timesler/facenet-pytorch">this is the GitHub repo</a>. This framework was developed based on the paper: <em>“Joint Face Detection and Alignment Using Multitask Cascaded Convolutional Networks.” </em>by Zhang, Kaipeng et al. IEEE Signal Processing Letters 23.10 (2016): 1499–1503. <strong>Multi-task Cascaded Convolutional Networks (MTCNN)</strong> adopt a cascaded structure that predicts face and landmark locations in a coarse-to-fine manner.</p><p>If you want to learn more about Multi-task Cascaded Convolutional Neural Networks you should check out <a href="https://medium.com/@iselagradilla94/7c21e8007923?source=friends_link&amp;sk=56ce09f9aa413293ac3bfdd69f5010a9"><strong>my previous post</strong></a>, in which I explain the network’s architecture step by step.</p><p>Multi-task Cascaded Convolutional Networks (MTCNN) adopts a cascaded structure that predicts face and landmark locations in a coarse-to-fine manner. For this project your project folder structure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*tf4f9WQiltXOia0WjrN2DQ.jpeg" /></figure><p>The first thing you will need to do is install facenet-pytorch, you can do this with a simple pip command:</p><pre>&gt; pip install facenet-pytorch</pre><p><strong>0. Use MTCNN and OpenCV to Detect Faces with your webcam</strong></p><p>First, inside the face_detector folder we will create a script to declare the FaceDetector class and its methods. Take a moment to look at the code:</p><p>If you prefer a video explanation, I have a<strong> </strong><a href="https://www.youtube.com/watch?v=p5jhlEvCLlg"><strong>video</strong></a> going over the code below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/476827c34bef745cc93968fc29e4a69f/href">https://medium.com/media/476827c34bef745cc93968fc29e4a69f/href</a></iframe><p>lines 14–40 include the _draw() method for the class, this method will be used to draw the bounding boxes for the detected faces as well as the probability of being a face, and the facial landmarks: eyes, nose and mouth.</p><p>And finally lines 42–66 run the FaceDetector. Line 46 initiates the connection with your laptop’s webcam though OpenCV’s VideoCapture() method. Then we run a while loop to read the frames from the camera and use the draw method to draw bounding boxes, landmarks and probabilities.</p><p>Lines 62–63 stop the video if the letter ‘q’ is pressed on the keyboard. And lastly, the last three lines are creating and instance of MTCNN to pass to the FaceDetector and run it.</p><p>To <strong>incorporate a classifier to recognize and blur out your face</strong>, check out<strong> </strong><a href="https://medium.com/@iselagradilla94/7909547e2cde?source=friends_link&amp;sk=cda20a1d9e7617883ae5ea236e19d9a8"><strong>my next post</strong></a><strong>.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d46b0866e4d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi-task Cascaded Convolutional Networks (MTCNN) for Face Detection and Facial Landmark Alignment]]></title>
            <link>https://medium.com/@iselagradilla94/multi-task-cascaded-convolutional-networks-mtcnn-for-face-detection-and-facial-landmark-alignment-7c21e8007923?source=rss-cae7e5755852------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c21e8007923</guid>
            <dc:creator><![CDATA[Rosa Gradilla]]></dc:creator>
            <pubDate>Mon, 27 Jul 2020 23:20:03 GMT</pubDate>
            <atom:updated>2020-07-27T23:20:03.952Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the first of a series of posts in which I will walk you through how I developed a <strong>face detection application with PyTorch and OpenCV</strong>. The outline for the following stories is the following:</p><ol><li><a href="https://medium.com/@iselagradilla94/d46b0866e4d6?source=friends_link&amp;sk=b3fb560ad5b6843d47b6ecb419349db0">Developing the face detector</a></li><li><a href="https://medium.com/@iselagradilla94/7909547e2cde?source=friends_link&amp;sk=cda20a1d9e7617883ae5ea236e19d9a8">Incorporating a classifier to blur out a specific face</a></li></ol><p>In this first post I will go over how MTCNN works based on the paper “Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks” by Zhang, Zhang and Zhifeng. In following posts I will go over how I developed the face detection app and finally how I trained a classifier to recognize my face and blur it out in a video feed.</p><p>Multi-task Cascaded Convolutional Networks (MTCNN) is a framework developed as a solution for both face detection and face alignment. The process consists of three stages of convolutional networks that are able to recognize faces and landmark location such as eyes, nose, and mouth.</p><p>The paper proposes MTCNN as a way to integrate both tasks (recognition and alignment) using multi-task learning. In the first stage it uses a shallow CNN to quickly produce candidate windows. In the second stage it refines the proposed candidate windows through a more complex CNN. And lastly, in the third stage it uses a third CNN, more complex than the others, to further refine the result and output facial landmark positions.</p><h3>The Three Stages of MTCNN:</h3><p>The first step is to take the image and resize it to different scales in order to build an image pyramid, which is the input of the following three-staged cascaded network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQsF84De415OSLDSormZwQ.png" /><figcaption>Input image is resized to different scales to build an image pyramid</figcaption></figure><h4>Stage 1: The Proposal Network (P-Net)</h4><p>This first stage is a fully convolutional network (FCN). The difference between a CNN and a FCN is that a fully convolutional network does not use a dense layer as part of the architechture. This Proposal Network is used to obtain candidate windows and their bounding box regression vectors.</p><p>Bounding box regression is a popular technique to predict the localization of boxes when the goal is detecting an object of some pre-defined class, in this case faces. After obtaining the bounding box vectors, some refinement is done to combine overlapping regions. The final output of this stage is all candidate windows after refinement to downsize the volume of candidates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6xkYymO5qetLLjUt0MYJXg.jpeg" /><figcaption>P-Net (from MTCNN paper)</figcaption></figure><h4>Stage 2: The Refine Network (R-Net)</h4><p>All candidates from the P-Net are fed into the Refine Network. Notice that this network is a CNN, not a FCN like the one before since there is a dense layer at the last stage of the network architecture. The R-Net further reduces the number of candidates, performs calibration with bounding box regression and employs non-maximum suppression (NMS) to merge overlapping candidates.</p><p>The R-Net outputs wether the input is a face or not, a 4 element vector which is the bounding box for the face, and a 10 element vector for facial landmark localization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PoMst7LfCfRSADzSFHXIJg.jpeg" /><figcaption>R-Net (from MTCNN paper)</figcaption></figure><h4>Stage 3: The Output Network (O-Net)</h4><p>This stage is similar to the R-Net, but this Output Network aims to describe the face in more detail and output the five facial landmarks’ positions for eyes, nose and mouth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GEHEFApb0VF9poTIh1Bmng.jpeg" /><figcaption>O-Net (from MTCNN paper)</figcaption></figure><h3>The Three Tasks of MTCNN</h3><p>The Network’s task is to output three things: face/non-face classification, bounding box regression, and facial landmark localization.</p><ol><li><strong>Face classification</strong>: this is a binary classification problem that uses cross-entropy loss:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g1W7Tv_sp2ACiGPHQCSbAg.jpeg" /><figcaption>Cross-entropy loss</figcaption></figure><p>2. <strong>Bounding box regression</strong>: the learning objective is a regression problem. For each candidate window, the offset between the candidate and the nearest ground truth is calculated. Euclidean loss is employed for this task:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*-3anUH8pzO_4SrFr1bio7Q.jpeg" /><figcaption>Euclidean loss</figcaption></figure><ol><li><strong>Facial Landmark localization</strong>: the localization of facial landmarks is formulated as a regression problem, in which the loss function is Euclidean distance:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*14v1tnPlHx3_Z7TSQ_sHAA.jpeg" /><figcaption>Euclidean loss</figcaption></figure><p>There are five landmarks: left eye, right eye, nose, left mouth corner and right mouth corner.</p><p>To build a FaceDetector using MTCNN and OpenCV, check out my <a href="https://medium.com/@iselagradilla94/d46b0866e4d6?source=friends_link&amp;sk=b3fb560ad5b6843d47b6ecb419349db0">following story</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c21e8007923" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>