<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Generalization | Haobin Tan</title><link>https://haobin-tan.netlify.app/tags/generalization/</link><atom:link href="https://haobin-tan.netlify.app/tags/generalization/index.xml" rel="self" type="application/rss+xml"/><description>Generalization</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:00:00 +0000</lastBuildDate><image><url>https://haobin-tan.netlify.app/media/icon_hu7d15bc7db65c8eaf7a4f66f5447d0b42_15095_512x512_fill_lanczos_center_3.png</url><title>Generalization</title><link>https://haobin-tan.netlify.app/tags/generalization/</link></image><item><title>Dropout</title><link>https://haobin-tan.netlify.app/docs/ai/deep-learning/nn-basics/dropout/</link><pubDate>Sun, 16 Aug 2020 00:00:00 +0000</pubDate><guid>https://haobin-tan.netlify.app/docs/ai/deep-learning/nn-basics/dropout/</guid><description>&lt;h2 id="model-overfitting">Model Overfitting&lt;/h2>
&lt;img src="https://raw.githubusercontent.com/EckoTan0804/upic-repo/master/uPic/截屏2020-08-23%2022.00.46.png" alt="截屏2020-08-23 22.00.46" style="zoom:50%;" />
&lt;p>In order to give more &amp;ldquo;capacity&amp;rdquo; to capture different features, we give neural nets a lot of neurons. But this can cause overfitting.&lt;/p>
&lt;img src="https://raw.githubusercontent.com/EckoTan0804/upic-repo/master/uPic/截屏2020-08-23%2021.59.37.png" alt="截屏2020-08-23 21.59.37" style="zoom: 50%;" />
&lt;p>Reason: Co-adaptation&lt;/p>
&lt;ul>
&lt;li>Neurons become dependent on others&lt;/li>
&lt;li>Imagination: neuron $H\_i$ captures a particular feature $X$ which however, is very frequenly seen with some inputs.
&lt;ul>
&lt;li>If $H\_i$ receives bad inputs (partial of the combination), then there is a chance that the feature is ignored 🤪&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Solution: Dropout!&lt;/strong> &amp;#x1f4aa;&lt;/p>
&lt;h2 id="dropout">Dropout&lt;/h2>
&lt;p>With dropout the layer inputs become more sparse, forcing the network weights to become more robust.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="flex justify-center ">
&lt;div class="w-100" >&lt;img src="https://raw.githubusercontent.com/EckoTan0804/upic-repo/master/uPic/%e6%88%aa%e5%b1%8f2020-08-23%2022.06.16.png" alt="截屏2020-08-23 22.06.16" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>Dropout a neuron = all the inputs and outputs to this neuron will be disabled at the current iteration.&lt;/p>
&lt;h3 id="training">Training&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>Given&lt;/p>
&lt;ul>
&lt;li>input $X \in \mathbb{R}^D$&lt;/li>
&lt;li>weights $W$&lt;/li>
&lt;li>survival rate $p$
&lt;ul>
&lt;li>Usually $p=0.5$&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Sample mask $M \in \{0, 1\}^D$ with $M\_i \sim \operatorname{Bernoulli}(p)$&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Dropped input:
&lt;/p>
$$
\hat{X} = X \circ M
$$
&lt;/li>
&lt;li>
&lt;p>Perform backward pass and mask the gradients:
&lt;/p>
$$
\frac{\delta L}{\delta X}=\frac{\delta L}{\delta \hat{X}} \circ M
$$
&lt;/li>
&lt;/ul>
&lt;h3 id="evaluationtestinginference">Evaluation/Testing/Inference&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>ALL input neurons $X$ are presented WITHOUT masking&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Because each neuron appears with probability $p$ in training&lt;/p>
&lt;p>$\to$ So we have to scale $X$ with $p$ (or scale $\hat{X}$ with $\frac{1}{1-p}$ during training) to match its expectation&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="why-dropout-works">Why Dropout works?&lt;/h2>
&lt;ul>
&lt;li>Intuition: Dropout prevents the network to be too dependent on a small number of neurons, and forces every neuron to be able to operate independently.&lt;/li>
&lt;li>Each of the “dropped” instance is a different network configuration&lt;/li>
&lt;li>$2^n$ different networks sharing weights&lt;/li>
&lt;li>The inference process can be understood as an &lt;strong>ensemble of $2^n$ different configuration&lt;/strong>&lt;/li>
&lt;li>This interpretation is in-line with &lt;em>Bayesian Neural Networks&lt;/em>&lt;/li>
&lt;/ul>
&lt;img src="https://raw.githubusercontent.com/EckoTan0804/upic-repo/master/uPic/截屏2020-08-23%2022.20.36.png" alt="截屏2020-08-23 22.20.36" style="zoom: 50%;" /></description></item><item><title>👍 Data Augmentation</title><link>https://haobin-tan.netlify.app/docs/ai/deep-learning/nn-basics/data-augmentation/</link><pubDate>Sun, 16 Aug 2020 00:00:00 +0000</pubDate><guid>https://haobin-tan.netlify.app/docs/ai/deep-learning/nn-basics/data-augmentation/</guid><description>&lt;h2 id="motivation">Motivation&lt;/h2>
&lt;p>Overfitting happens because of having &lt;strong>too few examples&lt;/strong> to train on, resulting in a model that has poor generalization performance &amp;#x1f622;. If we had infinite training data, we wouldn’t overfit because we would see every possible instance.&lt;/p>
&lt;p>However, in most machine learning applications, especially in image classification tasks, obtaining new training data is not easy. Therefore we need to make do with the training set at hand. &amp;#x1f4aa;&lt;/p>
&lt;p>&lt;strong>Data augmentation is a way to generate more training data from our current set. It enriches or “augments” the training data by generating new examples via random transformation of existing ones. This way we artificially boost the size of the training set, reducing overfitting. So data augmentation can also be considered as a regularization technique.&lt;/strong>&lt;/p>
&lt;p>Data augmentation is done dynamically during training time. We need to generate realistic images, and the transformations should be learnable, simply adding noise won’t help. Common transformations are&lt;/p>
&lt;ul>
&lt;li>rotation&lt;/li>
&lt;li>shifting&lt;/li>
&lt;li>resizing&lt;/li>
&lt;li>exposure adjustment&lt;/li>
&lt;li>contrast change&lt;/li>
&lt;li>etc.&lt;/li>
&lt;/ul>
&lt;p>This way we can generate a lot of new samples from a single training example.&lt;/p>
&lt;p>&lt;strong>Notice that data augmentation is ONLY performed on the training data, we don’t touch the validation or test set.&lt;/strong>&lt;/p>
&lt;h2 id="popular-augmentation-techniques">Popular Augmentation Techniques&lt;/h2>
&lt;h3 id="flip">Flip&lt;/h3>
&lt;figure>&lt;img src="https://nanonets.com/blog/content/images/2018/11/1_-beH1nNqlm_Wj-0PcWUKTw.jpeg"
alt="Left: original image. Middle: image flipped horizontally. Right: image flipped vertically">&lt;figcaption>
&lt;p>Left: original image. Middle: image flipped horizontally. Right: image flipped vertically&lt;/p>
&lt;/figcaption>
&lt;/figure>
&lt;h3 id="rotation">Rotation&lt;/h3>
&lt;figure>&lt;img src="https://cdn-images-1.medium.com/max/720/1*i_F6aNKj3yggkcNXQxYA4A.jpeg"
alt="Example of square images rotated at right angles. From left to right: The images are rotated by 90 degrees clockwise with respect to the previous one.">&lt;figcaption>
&lt;p>Example of square images rotated at right angles. From left to right: The images are rotated by 90 degrees clockwise with respect to the previous one.&lt;/p>
&lt;/figcaption>
&lt;/figure>
&lt;p>Note: image dimensions may not be preserved after rotation&lt;/p>
&lt;ul>
&lt;li>If image is a square, rotating it at right angles will preserve the image size.&lt;/li>
&lt;li>If image is a rectangle, rotating it by 180 degrees would preserve the size.&lt;/li>
&lt;/ul>
&lt;h3 id="scale">Scale&lt;/h3>
&lt;figure>&lt;img src="https://cdn-images-1.medium.com/max/720/1*INLTn7GWM-m69GUwFzPOaQ.jpeg"
alt="Left: original image. Middle: image scaled outward by 10%. Right: image scaled outward by 20%">&lt;figcaption>
&lt;p>Left: original image. Middle: image scaled outward by 10%. Right: image scaled outward by 20%&lt;/p>
&lt;/figcaption>
&lt;/figure>
&lt;p>The image can be scaled outward or inward. While scaling outward, the final image size will be larger than the original image size. Most image frameworks cut out a section from the new image, with size equal to the original image.&lt;/p>
&lt;h3 id="crop">Crop&lt;/h3>
&lt;figure>&lt;img src="https://cdn-images-1.medium.com/max/720/1*ypuimiaLtg_9KaQwltrxJQ.jpeg"
alt="Left: original image. Middle: a square section cropped from the top-left. Right: a square section cropped from the bottom-right. The cropped sections were resized to the original image size.">&lt;figcaption>
&lt;p>Left: original image. Middle: a square section cropped from the top-left. Right: a square section cropped from the bottom-right. The cropped sections were resized to the original image size.&lt;/p>
&lt;/figcaption>
&lt;/figure>
&lt;p>Random cropping&lt;/p>
&lt;ol>
&lt;li>Randomly sample a section from the original image&lt;/li>
&lt;li>Resize this section to the original image size&lt;/li>
&lt;/ol>
&lt;h3 id="translation">Translation&lt;/h3>
&lt;figure>&lt;img src="https://cdn-images-1.medium.com/max/720/1*L07HTRw7zuHGT4oYEMlDig.jpeg"
alt="Left: original image. Middle: the image translated to the right. Right: the image translated upwards.">&lt;figcaption>
&lt;p>Left: original image. Middle: the image translated to the right. Right: the image translated upwards.&lt;/p>
&lt;/figcaption>
&lt;/figure>
&lt;p>&lt;strong>Translation = moving the image along the X or Y direction (or both)&lt;/strong>&lt;/p>
&lt;p>This method of augmentation is very useful as most objects can be located at almost anywhere in the image. This forces your convolutional neural network to look everywhere.&lt;/p>
&lt;h3 id="gaussian-noise">Gaussian Noise&lt;/h3>
&lt;figure>&lt;img src="https://cdn-images-1.medium.com/max/720/1*cx24OpSNOwgg7ULUHKiGnA.png"
alt="Left: original image. Middle: image with added Gaussian noise. Right: image with added salt and pepper noise.">&lt;figcaption>
&lt;p>Left: original image. Middle: image with added Gaussian noise. Right: image with added salt and pepper noise.&lt;/p>
&lt;/figcaption>
&lt;/figure>
&lt;p>One reason of overfitting ist that neural network tries to learn high frequency features (patterns that occur a lot) that may not be useful.&lt;/p>
&lt;p>&lt;strong>Gaussian noise&lt;/strong>, which has zero mean, essentially has data points in all frequencies, effectively distorting the high frequency features. This also means that lower frequency components (usually, your intended data) are also distorted, but your neural network can learn to look past that. Adding just the right amount of noise can enhance the learning capability.&lt;/p>
&lt;p>A toned down version of this is the &lt;strong>salt and pepper noise&lt;/strong>, which presents itself as random black and white pixels spread through the image. This is similar to the effect produced by adding Gaussian noise to an image, but may have a lower information distortion level.&lt;/p>
&lt;h2 id="reference">Reference&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://towardsdatascience.com/applied-deep-learning-part-4-convolutional-neural-networks-584bc134c1e2#9722">Applied Deep Learning - Part 4: Convolutional Neural Networks&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://nanonets.com/blog/data-augmentation-how-to-use-deep-learning-when-you-have-limited-data-part-2/">Data Augmentation | How to use Deep Learning when you have Limited Data — Part 2&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>