<?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 Kofi Asiedu Brempong on Medium]]></title>
        <description><![CDATA[Stories by Kofi Asiedu Brempong on Medium]]></description>
        <link>https://medium.com/@kaybrempong?source=rss-e23c41ff2a82------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5kWkFS005UjdLPWaovMKGQ.jpeg</url>
            <title>Stories by Kofi Asiedu Brempong on Medium</title>
            <link>https://medium.com/@kaybrempong?source=rss-e23c41ff2a82------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:22:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaybrempong/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[I Finally Understood Backpropagation: And you can too…]]></title>
            <link>https://medium.com/data-science/i-finally-understood-backpropagation-and-you-can-too-44f7dd98ff52?source=rss-e23c41ff2a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/44f7dd98ff52</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[gradient-descent]]></category>
            <dc:creator><![CDATA[Kofi Asiedu Brempong]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 17:32:58 GMT</pubDate>
            <atom:updated>2020-07-03T18:34:15.545Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why the gradient is the direction of steepest ascent.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RkoTor8dTgviRlui" /><figcaption>Photo by <a href="https://unsplash.com/@thisisengineering?utm_source=medium&amp;utm_medium=referral">ThisisEngineering RAEng</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The backpropagation algorithm is one of the key ingredients for the training of neural networks, but it’s also probably the most difficult concept to grasp in understanding how things really work. At least in my own experience, it’s been the one thing that I’ve struggled to gain a deep understanding of. After juggling between a plethora of materials on the subject, I got my own eureka moment and the pieces fell into place. Like me, you may also be self-taught through online courses and may have done a couple of projects but you still feel that twinge of <strong><em>half-knowledge, </em></strong>of only vaguely understanding what is actually going on when you are training neural networks (or any other machine learning model).</p><p>In this blog post, I would be letting you in on the intuition that I’ve developed, hoping that you would build on this to develop an even better understanding of this all-important concept. I also provide links to the resources that have been of great help to me.</p><h3>Let’s begin with gradient descent</h3><p><em>But why?<br></em>Because that was the most glossed over bit for me. Many online courses would just tell you that gradient descent finds the partial derivative of the loss function with respect to the weights (ie. the gradient) and takes a step in the direction opposite to this gradient; Because the <em>gradient points in the direction of steepest ascent</em>, taking a step in the opposite direction would mean we move in <em>the direction of steepest descent</em>. But they never state why, I mean the why of the why. We take a step in the direction opposite to the gradient because it points in the direction of steepest ascent but the question (for me) really is: Why is the gradient the direction of steepest ascent?</p><h4>Reviewing gradients</h4><p>The gradient is just a vector containing all the partial derivatives of a function. Hence the key idea here is really the concept of partial derivatives. Partial derivatives tell us how much a function would change when we keep all but one of its input variables constant and move a slight nudge in the direction of the one variable that is not fixed.</p><p>As an aside, typical neural networks contain thousands of parameters but for simplicity and ease of visualization, we would be considering functions with two variables: 𝑓(𝑥,𝑦). Fortunately, everything we do here would generalize nicely to any number of dimensions.</p><p>For our two-variable case, the partial derivative tells us how much the output of the function would change if we keep the 𝑦 variable constant and move a slight nudge in the 𝑥 direction and vice versa.</p><p><strong>Concretely</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uSN5KWu5vsui4OKuHN4R-A.png" /><figcaption>Image by author</figcaption></figure><p>We are at the point (2, 3) in our input space which corresponds to a particular point t in the output plane, that is the output of our function is t for an input of (2, 3). The partial derivative with respect to 𝑥 tells us how much change would result in the output if we keep 𝑦 fixed at 3 and move slightly in the 𝑥 direction. Similarly, the partial derivative with respect to 𝑦 measures the resulting change in output when 𝑥 is fixed at 2 and we move a little nudge in the 𝑦 direction.</p><p>Let’s consider the function: 𝑓(𝑥,𝑦) = <em>x</em>²<em>y</em>. The partial derivative with respect to <em>x</em>, ∂f/∂x is 2<em>xy</em>, ie. we keep the <em>y</em> as a constant and differentiate the whole term. Likewise, the partial derivative with respect to <em>y</em>, ∂f/∂y​ is <em>x</em>².</p><p>Remembering that the gradient packs together all the partial derivative into a vector, the gradient of this function would be: ∇𝑓 = [2𝑥𝑦, 𝑥²]. At point (2, 3), the gradient would be ∇𝑓=[12, 4]. So a slight nudge purely in the x direction would cause a change by a factor of 12 in the output of the function while a similar change in the y direction would change the output of the function by a factor of 4.</p><p>Try deriving the partial derivatives for the function: 𝑔(𝑥,𝑦)=3𝑥𝑦³. Hopefully, it shouldn’t be difficult to see that the gradient of this function would be: ∇𝑔=[3𝑦³, 9𝑥𝑦²].</p><p>The problem with partial derivatives is that they only tell us how things would change if we move in only one direction. Partial derivatives are partial because neither of them tells us the full story of how our function <em>f</em>(<em>x</em>,<em>y</em>) changes when it&#39;s inputs changes. However, we do not only want to know how things change when we move in either the <em>x</em> or <em>y</em> direction, but we also want to know how much things would change if we move in any arbitrary direction within the input space. That&#39;s exactly what directional derivatives are for.</p><h3>Directional derivatives</h3><p>The directional derivative in a direction say 𝑤⃗ tells us how much the output of the function would change if we move a slight nudge in the direction of the vector 𝑤⃗. The directional derivative is found by taking the dot product of the gradient of the function and 𝑤⃗ ie. the direction in which we want to move.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/139/1*WVWohA9ukZoB1atFAX9WdQ.png" /></figure><p>If 𝑤⃗ =[3, 5], then the directional derivative:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*syCler6nN0_kIkfVFEJr8Q.png" /></figure><p>Evaluating the directional derivative at the point (2,3):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/194/1*KTmDiH0hFrcVtqtKIxS8rA.png" /></figure><p>What this means is that given that we are at the point (2, 3) in our input plane, taking a tiny step in the direction of the vector (3, 5) would change the output of our function by a factor of 56. Another way to look at this is to consider that in our input plane (ie. the x,y plane), any point or direction in this plane can be thought of as a combination of movements in the 𝑥 and 𝑦 directions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PcSqc-0JhmykxzhiUuzbA.png" /><figcaption>Image by author</figcaption></figure><p>In the image above, 𝑤⃗ =[3, 5] is a combination of 3 steps in the 𝑥 direction and 5 steps in the 𝑦 direction. So intuitively, taking a step along some arbitrary direction causes a change along the x-axis as well as along the y-axis. Taking the dot product for the directional derivative sums the changes along the x and y-axis.</p><p>So now we have directional derivatives which are essentially a generalization of partial derivatives to deal with any arbitrary direction in our input plane. When training neural networks, the problem we seek to solve is that: given that we are at a point say (2, 3) which corresponds to a loss (the output of our function) of t, we want to know the <strong>direction</strong> that would result in the greatest increase in our loss? Once we know this <strong>direction</strong> we take a step in the opposite <strong>direction</strong> which would lead to the greatest reduction in the loss. Notice that I&#39;m placing an intentional emphasis on the word <strong>direction</strong>. We are looking for the best direction and lucky enough we already have a tool that gives a measure of how good (or bad) a particular direction is, which as you may have guessed is the directional derivative.</p><p>With directional derivatives, one way we could solve this problem is to find the directional derivative of all possible directions in which we could move. The best direction would be the direction with the largest directional derivative. But that would be too slow to compute, think about the number of possible directions in which we could move, the list is endless. However, the idea is good, we just need a simpler way to find the direction with the maximum directional derivative.</p><h3>Finding the direction of steepest ascent</h3><p>Our objective now is to find:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*1lcYRCvJm4wv_7-WkciDNA.png" /></figure><p>Notice that the vectors in the equation above have a magnitude or length of 1. In a sense, this ensures that we don’t end up picking the wrong vector just because it has a larger magnitude than the rest and hence would maximize the dot product even though it’s pointing in the wrong direction.</p><p>The directional derivative as has already been stated is found by taking the dot product of the gradient and the vector pointing in our desired direction. The dot product possesses a very nice property that would allow us to find the direction that maximizes the directional derivative without having to consider all the possible directions. The dot product measures the similarity between two vectors. It assigns a score to how much the two vectors are traveling in the same direction. Formally, the dot product between two vectors 𝑢⃗ and 𝑣⃗ is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/0*FMitSMtCQVvZOxeb" /></figure><p>Where 𝜃 is the angle between the two vectors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBhKGcDL3v4CU9riZwc0uw.png" /><figcaption>Image by author</figcaption></figure><p>In the illustration above, when 𝑢⃗ =[0, 1] and 𝑣⃗ =[1, 0], their dot product is 0 because there is no similarity between them, 𝑢⃗ is pointing purely in the 𝑥 direction (it has no 𝑦 component whiles 𝑣⃗ also points solely in the 𝑦 direction. The angle between them is 90° (they are perpendicular) and 𝑐𝑜𝑠(90°) = 0. When, 𝑢⃗ =[0, 1] and 𝑣⃗ =[0, 1], the dot product is maximized because they are pointing in the same direction. The dot product, in this case, is 1 because the angle between them is 0°.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/0*QlZXavMSiTurOvJM" /></figure><p>The magnitude of the vectors does not have an impact on the result of the dot product because both vectors have a magnitude of 1. Hence the result of the dot product using the formulation above depends on the angle between the two vectors. From the foregoing, it is not difficult to grasp the fact that we are driving at, which is that, for unit length vectors, the dot product is maximized when the two vectors are parallel, that is they point in the same direction or that the angle between them is 0°.</p><p>To remind us of our objective, we want to find the vector that maximizes the directional derivative:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*1lcYRCvJm4wv_7-WkciDNA.png" /></figure><p>The directional derivative is also a dot product and so it flows naturally from our understanding of dot products that the vector that would maximize the directional derivative and result in the greatest increase in our function is the vector that points in the same direction as the gradient which is the gradient itself. This is why the gradient is the direction of steepest ascent. Gradient descent takes a step in the opposite direction because our objective in training is to minimize, not to maximize the loss function.</p><p>Hopefully, you’ve gained some useful insights from this post to help you solidify your understanding of the foundations of neural networks and other machine learning algorithms. The next blogpost will take a look at the chain rule which is the other major concept behind backpropagation.</p><h3>Resources</h3><p>Partial and Directional derivatives: <a href="https://www.khanacademy.org/math/multivariable-calculus/multivariable-derivatives">Khan Academy: Multivariable calculus</a><br>Dot products: <a href="https://www.khanacademy.org/math/linear-algebra/vectors-and-spaces/dot-cross-products/v/vector-dot-product-and-vector-length">Khan Academy: Linear Algebra</a><br>Calculus: <a href="https://www.youtube.com/watch?v=WUvTyaaNkzM&amp;list=PLZHQObOWTQDMsr9K-rj53DwVRMYO3t5Yr">3Blue1Brown</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44f7dd98ff52" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/i-finally-understood-backpropagation-and-you-can-too-44f7dd98ff52">I Finally Understood Backpropagation: And you can too…</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dogs vs Cats is too easy]]></title>
            <link>https://medium.com/predict/dogs-vs-cats-is-too-easy-40ec607fc0b0?source=rss-e23c41ff2a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/40ec607fc0b0</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[image-recognition]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Kofi Asiedu Brempong]]></dc:creator>
            <pubDate>Tue, 30 Oct 2018 19:10:54 GMT</pubDate>
            <atom:updated>2018-11-02T11:28:32.468Z</atom:updated>
            <content:encoded><![CDATA[<h4>A harder problem: Fine-grain classification</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PU7wwmX3JaTa6CcDKvSwpA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/KE0nC8-58MQ?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Carl Heyerdahl</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The Dogs vs Cats problem has become a sort of hello world for deep learning folks. Many courses and blog posts that are aimed at beginners use it as the fundamental building block for an introduction into the exciting world of deep learning.</p><p><a href="http://course.fast.ai/">Fastai</a> has not been any different with past versions of the course focusing on building a Dogs vs Cats classifier in the first lesson. But this year the course is taking a different approach because as <a href="https://medium.com/u/34ab754f8c5e">Jeremy Howard</a> puts it,</p><blockquote>We have gotten to the point where deep learning is so fast and so easy that the Dogs vs Cats problem, which a few years ago was considered extremely difficult is now too easy. 80% accuracy in the past was considered state of the art. Our models are now basically getting every thing right all the time without any tuning.</blockquote><p>So the Dogs vs Cats problem is no longer challenging which means there is no opportunity to try out new ideas. A more challenging problem that Jeremy suggests is <a href="https://www.youtube.com/watch?v=pxTPUIR7UEc">fine-grain</a> classification. With this problem, we train models to distinguish between similar categories. An example which is also used in the Fastai course is the <a href="http://www.robots.ox.ac.uk/~vgg/data/pets/">Oxford-IIIT Pet Dataset</a> which has 37 classes of different species of pets.</p><p>In this post, we are going to build a fine-grain image classification model to detect which species of fish appears on a fishing boat, based on images captured from boat cameras at various angles. Eight target categories are available in this dataset which is available on <a href="https://www.kaggle.com/c/the-nature-conservancy-fisheries-monitoring/data">kaggle</a>.</p><h3>Nature Conservancy Fisheries Monitoring</h3><blockquote>Illegal, unreported, and unregulated fishing practices are threatening marine ecosystems, global seafood supplies and local livelihoods. Deep learning has the potential to dramatically scale the monitoring of fishing activities to fill critical science and compliance monitoring data gaps. — <a href="https://www.conserveca.org/">The nature conservancy</a></blockquote><p>The development of accurate models for this problem is a critical factor in ensuring that efforts aimed at conserving our fisheries are successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*Kfn6FYlfQmBafQ7iF4lIrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*jAqLgthCiTERN8vMIPCOtA.png" /></figure><p>From the images, we can tell tell that this problem would require a great deal of effort. With some of the images, it will be difficult even for a human to identify the species of the fish that has been caught.</p><p>To build our model, we are going to use the <a href="http://docs.fast.ai/">fastai</a> library which makes it incredibly easy (believe me) to build deep learning models.</p><p><em>Our first step will be to load and normalize the data.</em></p><blockquote>Data normalization is an important step which ensures that each input parameter (pixel, in this case) has a similar data distribution. This makes convergence faster while training the network. Data normalization is done by subtracting the mean from each pixel, and then dividing the result by the standard deviation. — <a href="https://becominghuman.ai/@nik_b?source=post_header_lockup">Nikhil Balaji</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*HczLy91jBuduIXyKuyONrA.png" /></figure><p>This creates an 80/20 split for our data, 80% of the data is used for the training set whiles 20% is used for the validation set. The concept of training, validation and test sets can be very much likened to a classroom setting. The lessons and assignments are the training set, the quizzes are the validation set and the final exam is the test set.</p><p>In a class you learn (train) from the lessons you take as well as the assignments that are given to you. Quizzes are given to validate and give useful feedback to the teacher concerning the effectiveness of her approach. The teacher (deep learning practitioner) uses this feedback to adjust her approach with the aim of getting better results (accuracy or any other metric). The final exam gives a more holistic assessment of the performance of the students in the class and shows how well the teacher was able to train the students (model).</p><h4>Creating the Model</h4><p>We create our model using a pre-trained resnet50 model to perform transfer learning. Transfer learning allows us to use a model built for another task as the starting point for the model we want to develop for our own task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*ovNMgv2yulRn6mnpzOSkUg.jpeg" /></figure><p>The idea is to take the knowledge learned by the pre-trained model and apply it to our task. A neural network is trained on data which in the case of <a href="http://www.image-net.org/">ImageNet</a> is 1.2M labeled images. This network captures universal features of images like curves, shapes and edges.</p><p>So instead of training a new network and having it learn all these features from scratch, we transfer the knowledge learned by the pre-trained network to our problem domain.</p><p>This pre-trained model does not know about species of fish, but it certainly knows something about recognizing some kind of images already. We don’t start with a model that does not know anything, we start with one that knows how to recognize categories of things in the ImageNet dataset.</p><p>With transfer learning we can get state of art results in a short time even with a small dataset because we are utilizing the knowledge gained from previously training on a larger dataset. You can read more about transfer learning <a href="https://machinelearningmastery.com/transfer-learning-for-deep-learning/">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*1S1Ipk8koj6RVAK2DSXwdw.png" /></figure><p>After training for 5 epochs, we end up with an error rate of 0.093. That is, our model is making the wrong predictions 9% of the time.</p><h4>Fine tuning</h4><p>For such an important problem 9% error rate is not too good. So to improve upon our accuracy, we turn to fine-tuning. In the first phase of training, we only updated the weights of the newly initialized fully connected layer. We did not update (freeze) the weights of the pre-trained model.</p><p>We unfreeze the weights of the pre-trained model and train the model again. This fine-tunes the weights of the pre-trained model, making it more fitting for our task of identifying fish species.</p><p>The intuition behind fine-tuning is that, the earlier layers of the network capture generic features of images like curves and edges. But the later layers learn features that are more specific to the data it’s trained on such as recognizing dogs and cats in the case of ImageNet.</p><p>When we fine-tune the network, we are essentially adjusting the weights of these layers so that they capture the features that are more important to the task at hand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*cVfLMzhUxKtdQF9JcHZ4xQ.png" /></figure><h4>Top losses</h4><p>Let’s take a look at some of the images which our model misclassified with a lot of confidence. This helps us to identify the kind of images that our network is having trouble classifying which will inform our decision making as to the next steps to take to improve model accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*0aYqiR7qZ_ZAI-3u_eoGAQ.png" /></figure><p>Our final error rate is 0.05 which can still be improved upon. However this shows how challenging fine-grain classification problems can be. Hopefully as we turn our focus to these kind of problems, we will be able to develop techniques that can help us achieve even higher levels of accuracy.</p><p>The code for this project is available on <a href="https://github.com/asiedubrempong/fisheries-monitoring">github</a>.</p><blockquote><em>If you enjoyed this piece, please recommend and share</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40ec607fc0b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/predict/dogs-vs-cats-is-too-easy-40ec607fc0b0">Dogs vs Cats is too easy</a> was originally published in <a href="https://medium.com/predict">Predict</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Summer of Code Without Google]]></title>
            <link>https://medium.com/good-audience/summer-of-code-without-google-3c225aad4b07?source=rss-e23c41ff2a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c225aad4b07</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Kofi Asiedu Brempong]]></dc:creator>
            <pubDate>Wed, 24 Oct 2018 18:23:20 GMT</pubDate>
            <atom:updated>2018-11-01T23:46:20.191Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VNNeZVL_anR3JxQYZeDfoQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/pMnw5BSZYsA?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Hitesh Choudhary</a> on <a href="https://unsplash.com/@hiteshchoudhary?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>So I’m studying computer science, I do some web programming and I want a cool internship this summer.</blockquote><blockquote>…Well am going to apply to <em>GSoC</em> and make 6K!</blockquote><p>These were the ideas that solidified into a plan earlier this year when I was thinking about how my summer was going to be spent. I wanted an internship with a company where I was going to build (cool) stuff, learn, challenge my self along the way.</p><p>Looking around in my immediate environment gave me a few options if any. But it didn’t take long before I chanced upon the gold mine — <a href="https://summerofcode.withgoogle.com/"><em>Google Summer of Code</em></a>. Wow… spend the summer coding at home (no early mornings) and earn 6K. It doesn’t get better than this. Does it?</p><p>But, the dust settles and reality dawns. You have to go through the applications, contacting mentors, making contributions among others. I realized early enough that I was not going to be able to get into into GSoC 😞.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3oKIPi7cfWprZMtEM8%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fdebbyryan-debby-ryan-3oKIPi7cfWprZMtEM8&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3oKIPi7cfWprZMtEM8%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e6bf7a0968534ea0bd00d65cce6fb73/href">https://medium.com/media/7e6bf7a0968534ea0bd00d65cce6fb73/href</a></iframe><p>My web programming skills were not enough (I didn’t want do web anyway). I had never made an open source contribution and I had nothing to show that I was capable at what I wanted to do.</p><p>Artificial intelligence has been my first love (so to say) since freshman year in college. After I heard a lecturer say that His research area was AI, I was intrigued. Can intelligence really be artificial? I read about it and I was sold. Everybody knew I was in love with AI but I did nothing about it. Instead I branched off and tasted a bit of everything: full stack web development, hybrid mobile application development, micro-controllers (you name it). Along the line I continued to jump in and out of some online AI courses.</p><p>So although I genuinely wanted to spend my summer doing AI, I had not prepared myself to do that with Google.</p><p>Too bad I had to part with the hopes of making 6K over the summer, but I was still going to code with or without Google. Better still, it was going to do AI. I decided to put aside all my other interests (well except javascript 😏) and focus on AI. I ignored other internship opportunities and set out to have a <em>summer of code with myself.</em></p><h4>The plan:</h4><p>I knew <strong><em>the one who failed to plan, planned to fail</em></strong> and so I had a plan. But, and this was going to be my first lesson:</p><blockquote>plans are not meant to be set in stone</blockquote><p>My plan had to be rewritten several times, to make room for fitting in other skills I needed to have before I could move on with the others. If you are starting out with something new, your first plan would most often not be the best. Be ready to refine it as you go along. It would definitely feel like you are failing. But learning to stay on track in those moments would be a key determinant of the kind of results you will be able to produce.</p><p>So after the many changes to my plan, this happens to be my learning journey so far:</p><ul><li><a href="https://www.coursera.org/learn/machine-learning">Machine Learning Coursera</a>: A splendid introductory course. Although I realize I should have paid more attention to getting a firm grasp of the concepts rather than the code.</li><li><a href="http://course.fast.ai/ml">Introduction to Machine Learning for Coders (Fast AI)</a>: A gold mine for random forests and decision tree models. Although it does not go into other machine learning approaches, I would definitely recommend it if you are looking to quickly get up and going.</li><li><a href="http://course.fast.ai/">Practical Deep Learning for Coders (Fast AI)</a>: This course is surely worth the hype. You are able to reproduce the state of the art results that <a href="https://medium.com/u/34ab754f8c5e">Jeremy Howard</a> gets in the various lessons.</li><li><a href="http://neuralnetworksanddeeplearning.com/">Neural Networks and Deep Learning (Micheal Nielsen)</a>: This book will teach you the fundamental of neural networks and deep learning. One good thing is that you get to implement all the concepts that is Backpropagation and Stochastic Gradient Descent using just plain <a href="http://www.numpy.org/">NumPy</a>.</li><li><a href="https://www.coursera.org/specializations/deep-learning">Deep Learning Specialization Coursera</a>: A very good course on both the theory and programming aspects of deep learning. However, the way the programming assignments are structured make it difficult to build stuff on your own outside the class.</li><li><a href="https://www.manning.com/books/deep-learning-with-python">Deep Learning with Python (Francois Chollet</a>): This book teaches you to build models using keras which is a great starting point for beginners.</li><li><a href="https://www.oreilly.com/library/view/python-for-data/9781491957653/">Python for analysis (Wes Mckinney</a>): This book is largely about pandas and NumPy, but also delves into general methodologies for munging data and performing analytical operations on them.</li><li><a href="https://www.youtube.com/watch?v=fNk_zzaMoSs&amp;list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab">Essence of linear algebra</a>: This series of videos will really give you a solid understanding of the concepts in linear algebra like transformations, determinants, cross products and eigenvectors.</li><li><a href="https://ocw.mit.edu/resources/res-18-005-highlights-of-calculus-spring-2010/highlights_of_calculus/big-picture-of-calculus/">Big picture of Calculus</a>: Professor Strang has a knack for making complex things seem really simple. He shows how calculus applies to ordinary life situations and gives you a good intuition about the subject.</li></ul><p><strong>The result: </strong><br>After spending my summer going through all those materials, this is what I have to show:</p><ul><li>Geo-Eye: An image classification model that is meant to be an aid to geologists. It classifies hand specimen pictures of minerals. I wrote about it <a href="https://blog.goodaudience.com/can-ai-help-geologists-to-see-better-c9d625082b81">here</a>.</li><li>Pneumonia-classification: A model to predict pneumonia from chest x-rays. It makes use of a S<a href="https://arxiv.org/abs/1506.02025">patial Transformer Network</a> to improve the spatial invariance of the network.</li><li>Plant seedlings classification: Used <a href="https://arxiv.org/abs/1106.1813">Synthetic Minority Over-sampling Technique (SMOTE)</a> to balance a highly unbalanced dataset and built a classifier on top of it.</li><li>House prices prediction: Built a random forest model for predicting the prices of houses using the House Prices dataset on <a href="https://www.kaggle.com/c/house-prices-advanced-regression-techniques">kaggle</a>.</li><li>SimNet: Built a neural network from scratch and implemented backpropagation and stochatic gradient descent.</li></ul><p>In the process, not only did I learn AI but a few life lessons as well:</p><blockquote>The old classic is still true: <strong>Think outside the box</strong></blockquote><p>The concepts you learn in books and online course are not enough to build accurate models. Different problems would require different approaches. You have to be willing to accept that your knowledge is actually not enough and come up with innovative ideas that you will use to approach these problems.</p><blockquote>Never stop learning</blockquote><p>In my experience, there is no single course that will make you an expert. You have to take multiple courses, read multiple books and in all, aggregate knowledge from multiple sources.</p><blockquote>Get help along the way</blockquote><p>In starting out with anything, one important thing that I’ve learnt is to get help very early on from people who are already doing what you want to do. As a beginner you are not able to see much farther and the input of a much experienced person would go a long way to help you overcome the frustrations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Jln7cAtyFtRGr3TQ" /><figcaption>“Best Summer Ever” by <a href="https://unsplash.com/@dearseymour?utm_source=medium&amp;utm_medium=referral">Ksenia Makagonova</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So I enjoyed my summer of code and although I’ve not achieved mastery, I have surely gotten off to a good start. I am sure you enjoyed yours too. Comment below and share your learning experiences.</p><p>The code for the projects are available on <a href="https://github.com/asiedubrempong">github</a>.</p><p>I am on the lookout for projects, opportunities and challenges that will stretch me and make me learn more. Feel free to <a href="https://twitter.com/asiedubrempong">contact</a> me about any of such.</p><blockquote>If you enjoyed this article, please recommend and share</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F7b0181%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F7b0181%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/748a06e9019942f2677bba917ef55804/href">https://medium.com/media/748a06e9019942f2677bba917ef55804/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c225aad4b07" width="1" height="1" alt=""><hr><p><a href="https://medium.com/good-audience/summer-of-code-without-google-3c225aad4b07">Summer of Code Without Google</a> was originally published in <a href="https://medium.com/good-audience">Good Audience</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can AI help Geologists to see better?]]></title>
            <link>https://medium.com/good-audience/can-ai-help-geologists-to-see-better-c9d625082b81?source=rss-e23c41ff2a82------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9d625082b81</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[geology]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Kofi Asiedu Brempong]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 20:51:06 GMT</pubDate>
            <atom:updated>2018-07-10T19:27:50.197Z</atom:updated>
            <content:encoded><![CDATA[<h4>8 steps to build a world class image classifier.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fI6MQXKvOvkOarUy8sLW-A.jpeg" /><figcaption>Photo by Victoria Kure-Wu on Unsplash</figcaption></figure><h3>The Primer</h3><p>Recently I was having chat with a colleague of mine who is studying Geological Engineering. He had seen me use <a href="http://dlib.net/"><em>Dlib</em></a> to perform facial recognition tasks, and with a sense of awe after seeing the program learn to distinguish between myself and him given just a single picture, he asked….</p><p><em>Can it distinguish between minerals and rocks?</em></p><p><strong>Well, I think it can…</strong></p><p>This got my mind racing and probably yours too, thinking of the many ways in which AI specifically <a href="https://en.wikipedia.org/wiki/Deep_learning">deep learning</a> can help Geologists and Geophysicists in their day to day tasks.<br>To test the waters, we’re going to address the initial question of distinguishing between minerals.</p><h3>Which minerals?</h3><p>We are going to build an image classifier that distinguishes between <strong>quartz</strong> and <strong>amazonite</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*ijmRgU2PaF-uOa23NoMeKg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eN6BXCKWJQeZoOD3VtaEOQ.jpeg" /><figcaption>quartz (left) amazonite (right)</figcaption></figure><p>Well it turns out you are not the only one who couldn’t identify an amazonite, my colleague couldn’t and surprisingly neither does medium’s editor, as it thinks amazonite is not a word.</p><h3>Let’s see if our model can do better</h3><p>Our image classifier is going to be built using the 8 steps outlined by <a href="https://medium.com/u/34ab754f8c5e">Jeremy Howard</a> in the <a href="http://course.fast.ai/">Fastai course</a>.</p><p>To get enough images to train the model, I used a <a href="https://github.com/hardikvasa/google-images-download">script</a> suggested by <a href="https://medium.com/u/1629686e65cf">Nikhil B</a> in his <a href="https://towardsdatascience.com/fun-with-small-image-data-sets-part-2-54d683ca8c96">post</a>. I downloaded 200 images of each mineral, which was reduced to 138 after removing the corrupted and inappropriate ones. The images were split into 118 training images and 20 validation images for both classes.</p><p><strong>Step 1: Set precompute = True</strong></p><p>Setting precompute=True saves the activations of the last layers of the neural network. These activations are referred to as precomputed activatations. This generally makes it faster to train your model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*NHlPHEUolr4aoVeZs0o3XQ.png" /></figure><p><strong>Step 2: Use </strong><strong>lr_find() to find highest learning rate where loss is still clearly improving</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*xqkrKxhNpZv_avi_DjHlOg.png" /></figure><p>Based on the plot, I chose a learning rate of 0.01.<br>This approach to finding learning rates is based on the <a href="https://arxiv.org/abs/1506.01186">Cyclical Learning Rates for Training Neural Networks</a> paper.</p><p><strong>Step 3: Train last layer from precomputed activations for 1–2 epochs</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*QXBq9SvvV-BQcvwGTyNeqg.png" /></figure><p>This gave us an accuracy of 82.5%.</p><p><strong>Step 4: Train last layer with data augmentation (i.e. precompute=False) for 2–3 epochs with cycle_len=1</strong></p><p>With data augmentation, we randomly apply changes to the images in ways that shouldn’t impact their interpretation, such as flipping, zooming and rotating. This effectively creates more data for our model to train on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*FtwDZZzJ2Uh71BAf8vFiOw.png" /><figcaption>Data augmentation applied to a single image</figcaption></figure><p>cycle_len=1: enables <a href="https://medium.com/38th-street-studios/exploring-stochastic-gradient-descent-with-restarts-sgdr-fa206c38a74e">stochastic gradient descent with restarts</a> which ensures that we arrive at a global minimum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*xvVEodf0KT2wR7XkdylHZw.png" /></figure><p>We now have an accuracy of 95%…. that clearly helped!</p><p><strong>Step 5: Unfreeze all layers</strong></p><p>Because we are using a pretrained network, unfreezing the layers allows us to fine tune the weights of the earlier layers.</p><p><strong>Step 6: Set earlier layers to 3x-10x lower learning rate than next higher layer</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*HYtZ_lfsmmg_lz8VC4_wgg.png" /></figure><p>The learning rate for the earlier layers is smaller than the learning rate for the later layers because we don’t want to destroy the pretrained weights. We are only fine tuning.</p><p><strong>Step 7: Use </strong><strong>lr_find() again</strong></p><p>Using learning rate finder again showed that a learning rate of 0.001 was going to be better going forward.</p><p>And at last…</p><p><strong>Step 8: Train full network with cycle_mult=2 until over-fitting</strong></p><p>cycle_mult=2: doubles the length of the cycle after each cycle.<br>I trained the model for 30 epochs, with the results of the last 8 epochs being shown here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*wbI6PsneKteWsEmsybR42w.png" /></figure><p><strong>97.5%</strong> accuracy… Hurray !!!</p><h4>Wait, what does that actually mean?</h4><p>Let’s plot a <a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html">confusion matrix</a> to find out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*s38XuPD2YXFT3b6gqTTeLw.png" /></figure><p>It turns out our model only makes one wrong classification.</p><p><strong>And so…</strong></p><p>This I think is a very great feat considering that our dataset is very small by all deep learning standards.</p><p><strong>Back to our question: </strong><em>Can it distinguish between minerals and rocks?</em></p><p>It surely can… and I think you do agree with me on this. This approach can be used to analyze photographs and quickly and accurately recognize rock types .</p><p><strong>More questions:</strong></p><ul><li>Can it be used to interpret <a href="https://en.wikipedia.org/wiki/Reflection_seismology">seismic</a> data.</li><li>Can it recognize processes that were responsible for creation of rock formations.</li><li>Can it be used for interpreting remote sensing images (RSIs).</li><li>…</li></ul><p>Given the extreme effectiveness of the tools of deep learning that we have at our disposal today, computers can definitely be used for these tasks and many more. But it would require collaboration between deep learning practitioners and domain experts in the geo-sciences to see these ideas come to fruition.</p><p><em>If you enjoyed this post (actually this is my first), please recommend and share.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F7b0181%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F7b0181%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/748a06e9019942f2677bba917ef55804/href">https://medium.com/media/748a06e9019942f2677bba917ef55804/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9d625082b81" width="1" height="1" alt=""><hr><p><a href="https://medium.com/good-audience/can-ai-help-geologists-to-see-better-c9d625082b81">Can AI help Geologists to see better?</a> was originally published in <a href="https://medium.com/good-audience">Good Audience</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>