Answers.Body: <h2>Why are CNNs useful?</h2>
  <p>The main property of CNNs that make them more suitable than FFNNs to solve tasks where the inputs are images is that they perform <strong>convolutions</strong> (or cross-correlations).</p>
  <h2>Convolution</h2>
  <p>The convolution is an operation (more precisely, a linear operator) that takes two functions <span class="math-container">$f$</span> and <span class="math-container">$h$</span> and produces another function <span class="math-container">$g$</span>. It's often denoted as <span class="math-container">$f \circledast h = g$</span>, where <span class="math-container">$\circledast$</span> represents the convolution operation and <span class="math-container">$g$</span> is the function that results from the convolution of the functions <span class="math-container">$f$</span> and <span class="math-container">$h$</span>.</p>
  <p>In the case of CNNs,</p>
  <ul>
  <li><span class="math-container">$f$</span> is a multi-dimensional array (aka tensor) and it represents an <strong>image</strong> (or a processed version of an image, i.e. a feature map)</li>
  <li><span class="math-container">$h$</span> is a multi-dimensional array and it is called <strong>kernel</strong> (aka filter), which represents the learnable parameters of the CNN, and</li>
  <li><span class="math-container">$g$</span> is a processed version (with <span class="math-container">$h$</span>) of <span class="math-container">$f$</span> and it is often called the <strong>feature map</strong>, so it's also a multi-dimensional array</li>
  </ul>
  <h3>Images as functions</h3>
  <p>To be consistent with the initial definition of the convolution, <span class="math-container">$f, h$</span>, and <span class="math-container">$g$</span> can indeed be represented as functions.</p>
  <p>Suppose that the input image is a greyscale (so it is initially represented as a matrix), then we can represent it as a function as follows
  <span class="math-container">$$f: [a, b] \times [c, d] \rightarrow [0, 1],$$</span>
  i.e. given two numbers <span class="math-container">$x \in [a, b]$</span> and <span class="math-container">$y \in [c, d]$</span>, <span class="math-container">$f$</span> outputs a number in the range <span class="math-container">$[0, 1]$</span>, i.e. <span class="math-container">$f(x, y) = z$</span>, where <span class="math-container">$z$</span> is the grayscale intensity of the pixel at coordinates <span class="math-container">$x$</span> and <span class="math-container">$y$</span>. Similarly, the kernel <span class="math-container">$h$</span> and <span class="math-container">$g$</span> can also be defined as a function <span class="math-container">$h: [a, b] \times [c, d] \rightarrow [0, 1]$</span> and <span class="math-container">$g: [a, b] \times [c, d] \rightarrow [0, 1]$</span>, respectively.</p>
  <p>To be more concrete, if the shape of the image <span class="math-container">$f$</span> is <span class="math-container">$28 \times 28$</span>, then it is represented as the function <span class="math-container">$f: [0, 28] \times [0, 28] \rightarrow [0, 1]$</span>.</p>
  <p>Note that the domain of the images doesn't have to range from <span class="math-container">$0$</span> to <span class="math-container">$28$</span> and the codomain doesn't have to range from <span class="math-container">$[0, 1]$</span>. For example, in the case of RGB images, the codomain can also equivalently range from <span class="math-container">$0$</span> to <span class="math-container">$255$</span>.</p>
  <p>RGB images can also be represented as functions, more precisely, vector-valued functions, i.e.</p>
  <p><span class="math-container">$$
  f(x, y) = 
  \begin{bmatrix}
  r(x, y) \\
  g(x, y) \\
  b(x, y)
  \end{bmatrix}
  $$</span>
  where</p>
  <ul>
  <li><span class="math-container">$r: [a, b] \times [c, d] \rightarrow [0, 1]$</span> represents the red channel,</li>
  <li><span class="math-container">$g: [a, b] \times [c, d] \rightarrow [0, 1]$</span> represents the green channel, and</li>
  <li><span class="math-container">$b: [a, b] \times [c, d] \rightarrow [0, 1]$</span> represents the blue channel</li>
  </ul>
  <p>Or, equivalently, <span class="math-container">$f: [a, b] \times [c, d] \times [0, 1]^3$</span>.</p>
  <h2>Why is the convolution useful?</h2>
  <p>The convolution of an image with kernels (e.g. the median kernel) can be used to perform many operations.</p>
  <p>For example, the convolution of a noisy image with the median filter can be used to remove noise from that image.</p>
  <p><a href="https://i.sstatic.net/kMrmO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kMrmO.png" alt="enter image description here" /></a></p>
  <p>This is a screenshot of an image from <a href="https://ch.mathworks.com/help/images/noise-removal.html" rel="nofollow noreferrer">this article</a>, which you should read if you want to understand more about noise removal. So, on the left, there's the noisy image, and, on the right, there's the convolution of the median filter with the noisy image, which removes (at least, partially) the initial noise (i.e. those dots, which are due to the so-called &quot;pepper and salt&quot; noise).</p>
  <p>The convolution of any image with the Sobel filter can be used to compute the derivatives of that image (both in the <span class="math-container">$x$</span> and <span class="math-container">$y$</span> directions, from which you can compute the magnitude and orientation of the gradient at each pixel of the image). See <a href="https://ch.mathworks.com/help/images/ref/imgradient.html" rel="nofollow noreferrer">this article</a> for more info.</p>
  <p>So, in general, the convolution of an image with a kernel processes the image and the results (i.e. another image, which, in the case of CNNs, is called a <em>feature map</em>) can be different depending on the kernel.</p>
  <p>This is the same thing as in CNNs. The only difference is that, in CNNs, the kernels are the learnable (or trainable) parameters, i.e. they change during training so that the overall loss (that the CNN is making) reduces (in the case CNNs are trained with gradient descent and back-propagation). For this reason, people like to say that CNNs are <em>feature extractors</em> or are performing feature extraction (aka feature learning or representation learning).</p>
  <p>(Moreover, note that the convolution and cross-correlation are the same operations when the kernels are symmetric (e.g. in the case of a Gaussian kernel). In the case of CNNs, the distinction between convolution and cross-correlation doesn't make much sense because the kernels are learnable. You can ignore this if you are a beginner, but you can find more details <a href="https://ai.stackexchange.com/q/21999/2444">here</a>.)</p>
  <h2>Other useful properties</h2>
  <p>There are other useful properties of CNNs, most of them are just a consequence of the use of the convolution</p>
  <ul>
  <li><p>Translation invariance (or equivariance), i.e. they can <em>potentially</em> find the same features (if you think of them as feature extractors) in multiple places of the image independently of their position, orientation, etc. See <a href="https://stats.stackexchange.com/a/208949/82135">this answer</a> for more details.</p>
  </li>
  <li><p>The equivalent FFNN has a lot more parameters (so CNNs may be less prone to overfitting)</p>
  </li>
  <li><p>They often use a sub-sampling operation  (known as <em>pooling</em>) to further reduce the number of parameters (which can possibly help to avoid overfitting) and introduce non-linearity.</p>
  </li>
  </ul>
  <h2>Notes</h2>
  <p>Note that the FFNN can also be used to process images. It's just that the CNN is more suited to deal with images for the reasons described above.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-22T11:51:45.143Z
Answers.LastActivityDate: 2020-12-12T12:30:12.933Z
Answers.LastEditDate: 2020-12-12T12:30:12.933Z
Answers.UserDisplayName: nbro
Body: <p>Why do we need convolutional neural networks instead of feed-forward neural networks?</p>
  
  <p>What is the significance of a CNN? Even a feed-forward neural network will able to solve the image classification problem, then why is the CNN needed?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-04T19:29:17.510Z
Comments.Text: Here's a related question: [What is the difference between a convolutional neural network and a regular neural network?](https://ai.stackexchange.com/q/5546/2444).
Comments.UserDisplayName: nbro
Tags: <neural-networks><deep-learning><convolutional-neural-networks><comparison><feedforward-neural-networks>
Title: Why do we need convolutional neural networks instead of feed-forward neural networks?
UserDisplayName: DRV
ThreadText: # Why do we need convolutional neural networks instead of feed-forward neural networks?
  
  (Asked by: username_0 on 2020-05-22)
  
  Why do we need convolutional neural networks instead of feed-forward neural networks?
  
  What is the significance of a CNN? Even a feed-forward neural network will able to solve the image classification problem, then why is the CNN needed?
  
  **Tags:** neural-networks, deep-learning, convolutional-neural-networks, comparison, feedforward-neural-networks
  
  > **Comments:**
  > **username_1**: Here's a related question: [What is the difference between a convolutional neural network and a regular neural network?](https://ai.stackexchange.com/q/5546/2444).  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-05-22. Score: 5 | Accepted answer
  
  ## Why are CNNs useful?
  
  The main property of CNNs that make them more suitable than FFNNs to solve tasks where the inputs are images is that they perform **convolutions** (or cross-correlations).
  
  ## Convolution
  
  The convolution is an operation (more precisely, a linear operator) that takes two functions $f$ and $h$ and produces another function $g$. It's often denoted as $f \circledast h = g$, where $\circledast$ represents the convolution operation and $g$ is the function that results from the convolution of the functions $f$ and $h$.
  
  In the case of CNNs,
  
  * $f$ is a multi-dimensional array (aka tensor) and it represents an **image** (or a processed version of an image, i.e. a feature map)
  * $h$ is a multi-dimensional array and it is called **kernel** (aka filter), which represents the learnable parameters of the CNN, and
  * $g$ is a processed version (with $h$) of $f$ and it is often called the **feature map**, so it's also a multi-dimensional array
  
  ### Images as functions
  
  To be consistent with the initial definition of the convolution, $f, h$, and $g$ can indeed be represented as functions.
  
  Suppose that the input image is a greyscale (so it is initially represented as a matrix), then we can represent it as a function as follows
  $$f: [a, b] \times [c, d] \rightarrow [0, 1],$$
  i.e. given two numbers $x \in [a, b]$ and $y \in [c, d]$, $f$ outputs a number in the range $[0, 1]$, i.e. $f(x, y) = z$, where $z$ is the grayscale intensity of the pixel at coordinates $x$ and $y$. Similarly, the kernel $h$ and $g$ can also be defined as a function $h: [a, b] \times [c, d] \rightarrow [0, 1]$ and $g: [a, b] \times [c, d] \rightarrow [0, 1]$, respectively.
  
  To be more concrete, if the shape of the image $f$ is $28 \times 28$, then it is represented as the function $f: [0, 28] \times [0, 28] \rightarrow [0, 1]$.
  
  Note that the domain of the images doesn't have to range from $0$ to $28$ and the codomain doesn't have to range from $[0, 1]$. For example, in the case of RGB images, the codomain can also equivalently range from $0$ to $255$.
  
  RGB images can also be represented as functions, more precisely, vector-valued functions, i.e.
  
  $$
  f(x, y) =
  \begin{bmatrix}
  r(x, y) \\
  g(x, y) \\
  b(x, y)
  \end{bmatrix}
  $$
  where
  
  * $r: [a, b] \times [c, d] \rightarrow [0, 1]$ represents the red channel,
  * $g: [a, b] \times [c, d] \rightarrow [0, 1]$ represents the green channel, and
  * $b: [a, b] \times [c, d] \rightarrow [0, 1]$ represents the blue channel
  
  Or, equivalently, $f: [a, b] \times [c, d] \times [0, 1]^3$.
  
  ## Why is the convolution useful?
  
  The convolution of an image with kernels (e.g. the median kernel) can be used to perform many operations.
  
  For example, the convolution of a noisy image with the median filter can be used to remove noise from that image.
  
  [![enter image description here](https://i.sstatic.net/kMrmO.png)](https://i.sstatic.net/kMrmO.png)
  
  This is a screenshot of an image from [this article](https://ch.mathworks.com/help/images/noise-removal.html), which you should read if you want to understand more about noise removal. So, on the left, there's the noisy image, and, on the right, there's the convolution of the median filter with the noisy image, which removes (at least, partially) the initial noise (i.e. those dots, which are due to the so-called "pepper and salt" noise).
  
  The convolution of any image with the Sobel filter can be used to compute the derivatives of that image (both in the $x$ and $y$ directions, from which you can compute the magnitude and orientation of the gradient at each pixel of the image). See [this article](https://ch.mathworks.com/help/images/ref/imgradient.html) for more info.
  
  So, in general, the convolution of an image with a kernel processes the image and the results (i.e. another image, which, in the case of CNNs, is called a *feature map*) can be different depending on the kernel.
  
  This is the same thing as in CNNs. The only difference is that, in CNNs, the kernels are the learnable (or trainable) parameters, i.e. they change during training so that the overall loss (that the CNN is making) reduces (in the case CNNs are trained with gradient descent and back-propagation). For this reason, people like to say that CNNs are *feature extractors* or are performing feature extraction (aka feature learning or representation learning).
  
  (Moreover, note that the convolution and cross-correlation are the same operations when the kernels are symmetric (e.g. in the case of a Gaussian kernel). In the case of CNNs, the distinction between convolution and cross-correlation doesn't make much sense because the kernels are learnable. You can ignore this if you are a beginner, but you can find more details [here](https://ai.stackexchange.com/q/21999/2444).)
  
  ## Other useful properties
  
  There are other useful properties of CNNs, most of them are just a consequence of the use of the convolution
  
  * Translation invariance (or equivariance), i.e. they can *potentially* find the same features (if you think of them as feature extractors) in multiple places of the image independently of their position, orientation, etc. See [this answer](https://stats.stackexchange.com/a/208949/82135) for more details.
  * The equivalent FFNN has a lot more parameters (so CNNs may be less prone to overfitting)
  * They often use a sub-sampling operation (known as *pooling*) to further reduce the number of parameters (which can possibly help to avoid overfitting) and introduce non-linearity.
  
  ## Notes
  
  Note that the FFNN can also be used to process images. It's just that the CNN is more suited to deal with images for the reasons described above.
  
  
  ---
  
  