Advertisement

深度学习:卷积神经网络 Convolutional neural networks for deep learning

阅读量:

Last story we talked about ordinary neural networks which are basic building blocks for deep learning, This story I wanna talk about Convolutional neural networks or Convnets.
上一个故事我们讨论了普通神经网络,它是深度学习的基本构建模块,这个故事我想谈谈卷积神经网络或卷积网络。

The convnets have been the major breakthroughs in the field of Deep learning and they perform really well for image recognition, we can also use CNN’s for Natural language processing and speech analysis. In this story I focus on computer vision(Image recognition). Let’s get started!!!!!!
卷积网络是深度学习领域的重大突破,它们在图像识别方面表现非常出色,我们还可以使用 CNN 进行自然语言处理和语音分析。在这个故事中,我重点关注计算机视觉(图像识别)。让我们开始吧!!!!!!

I follow Simon Sinek , he says always start with Why ,how and finally What
我跟随西蒙·斯内克(Simon Sinek),他说总是从“为什么”开始,“如何”,最后“什么”

_**Why CNN’s ??? Over Ordinary neural networks ??

为什么是CNN???超过普通神经网络?**_

Let’s say we are training a classifier to identify a cat using an ordinary neural net(where we have input, hidden and output layers)
假设我们正在训练一个分类器来使用普通的神经网络(其中有输入层、隐藏层和输出层)来识别猫

An ordinary neural networks typically takes features as inputs, for this problem we take image array as inputs, so we have a vector, size of (image widthheight) as an input.
普通的神经网络通常以特征作为输入,对于这个问题,我们以图像数组作为输入,因此我们有一个向量,大小为(图像宽度
高度)作为输入。

Note: I took just 1010 grid here for understanding, but the image array size = WidthHeightColor.
注意:为了便于理解,我这里只取了10
10的网格,但图像数组大小=宽度高度颜色

We feed it to the model and train it (back propagation) for many images for many iterations.
我们将其输入模型并针对许多图像进行多次迭代训练(反向传播)。

Once the network is trained then we can give another cat picture to predict (to get the score) to see if it gives the result as cat(high probability score).
一旦网络训练完毕,我们就可以给另一张猫图片进行预测(以获得分数),看看它是否给出猫的结果(高概率分数)。

well, it works, but wait..
好吧,它有效,但是等等..

what if I gave the test pictures like these for prediction.
如果我给出这样的测试图片来进行预测会怎样?

The ordinary network may not predict well(or not get much score for the cat) and what if I gave b/w pictures as test images(assume the train set does not have b/w images)
普通网络可能无法很好地预测(或者猫没有得到太多分数) ,如果我将黑白图片作为测试图像(假设训练集没有黑白图像)会怎样?

The network might fail to give the highest probability score as this type of features(b/w) we did not train.
网络可能无法给出最高概率得分,因为我们没有训练此类特征 (b/w)。

So what is happening here??
那么这里发生了什么?

**What we feed is what we get.

我们喂养什么,我们就得到什么。**

The network understands the mapping between X and y but not the patterns in X.
网络理解 X 和 y 之间的映射,但不理解 X 中的模式。

For above 3 test images the CNN is gonna be able to predict well for cats.
对于以上 3 个测试图像,CNN 将能够很好地预测猫。

_ConvNets are used mainly to look for patterns in an image, we don’t need to give features, the CNN understands the right features by itself as it goes deep.this is one of the reasons why we need CNN’s. Period.
ConvNet 主要用于寻找图像中的模式,我们不需要提供特征,CNN 会随着深入而自行理解正确的特征。这就是我们需要 CNN 的原因之一。 _

And another reason is, ordinary neural networks don’t scale well for full sized images , let’s say that input images size =100(width) * 100 (height) * 3 (rgb).
另一个原因是,普通神经网络对于全尺寸图像的缩放效果不佳,假设输入图像大小=100(宽度)* 100(高度)* 3(rgb)。

then we need to have 30,000 neurons which is very expensive in the network.
那么我们需要 30,000 个神经元,这在网络中是非常昂贵 的。

Hence We need to learn CNN.

因此我们需要学习CNN。

_**Okay so how does it work???

好吧,那么它是如何工作的呢?**_

For every image , it creates many images by applying some filters( just like photo editing tools )
对于每个图像,它通过应用一些过滤器创建许多图像(就像照片编辑工具一样)

These filters , we can call weights , kernels or features

这些过滤器,我们可以称为权重、内核或特征

they are initialized randomly first then during the training these weights will get updated (the network learns these weights)
它们首先被随机初始化,然后在训练期间这些权重将被更新(网络学习这些权重)

let’s take an example, suppose we have an image of 5X5 size like this and filters are like this,
举个例子,假设我们有一张这样的 5X5 大小的图像,滤镜是这样的,

Note : For sake of understanding I assume that 5 X 5 array is full image and the values are pixel values, otherwise it would be a big table of matrix and the values can be anything 0 and 1 or continuous value (- to +).
注意:为了便于理解,我假设 5 X 5 数组是完整图像,并且值是像素值,否则它将是一个大矩阵表,并且值可以是任何 0 和 1 或连续值(- 到 +)。

We have 3 filters which we initialize randomly (we define the filter size).
我们有 3 个过滤器,我们随机初始化它们(我们定义过滤器大小)。

Note: Here I took 0 or 1 to make the math easy , usually these are continuous values.
注意:这里我取 0 或 1 是为了方便数学计算,通常这些是连续值。

if we run each filter all over the image we will get the output images like these.
如果我们在整个图像上运行每个过滤器,我们将得到像这样的输出图像。

How did we get the output like these???
我们如何得到这样的输出???

Here is how 这是如何

This is for only one filter, we take a local receptive field in the image and we apply the dot product to a scalar value then we move the window by the Stride and repeat the same process for the entire image.
这仅适用于一个过滤器,我们在图像中获取局部感受野,并将点积应用于标量值,然后按步幅移动窗口,并对整个图像重复相同的过程。

This process is called ** Convolution.**

这个过程称为卷积。

so Step1 : Apply Convolution to all the filters for the input image.
所以第一步:对输入图像的所有滤波器应用卷积。

Step 2 : Apply Pooling concept for the generate output images
第 2 步:应用池化概念来生成输出图像

for example, for the first image,
例如,对于第一张图像,

The main goal of pooling is to reduce the size of an image by taking the max values in the window, and padding is not necessary here, but for Padding explanation purpose only I added here.
池化的主要目标是通过获取窗口中的最大值来减小图像的大小,这里不需要填充,但出于填充解释的目的,我仅在此处添加了填充。

Step 3 : Normalization, this is the step when you apply an activation function, the most used function here is ReLu (Rectified linear unit)
步骤3:归一化,这是应用激活函数的步骤,这里最常用的函数是ReLu(整流线性单元)

A rectified linear unit has output 0 if the input is less than 0, and raw output otherwise. That is, if the input is greater than 0, the output is equal to the input.
如果输入小于 0,则整流线性单元的输出为 0,否则为原始输出。也就是说,如果输入大于0,则输出等于输入。

Here we don’t have any negative values so don’t need to apply , if we assume we have, then it will be,
这里我们没有任何负值,所以不需要 apply ,如果我们假设有,那么它将是,

Step 4 : Feed these values to Fully Connected Neural network(we talked in the last story)
第 4 步:将这些值输入到全连接神经网络 (我们在上一个故事中谈到)

This process I already covered before here, so I don’t talk about it now.
这个过程我之前已经讲过,所以现在不再讲。

we train the model for all the images in the training set for certain no of epochs, and during training we update the weights using ** back propagation.**
我们为训练集中的所有图像训练特定时期的模型,并在训练期间使用反向传播更新权重。

so This is how it works.
这就是它的工作原理。

Love you man! 爱你男人!

_**So now what is a Convolutional neural network????

那么现在什么是卷积神经网络???**_

A Convolution neural network is a network of different types of layers sequentially connected together.

Types of layers 图层类型

  1. Convolution layer where the convolution process happens.
    发生卷积过程的卷积层。
  2. Pooling layer where the pooling process happens.
    池化过程发生的池化层。
  3. Normalization layer where the activation (ReLu) process happens.
    发生激活 (ReLu) 过程的归一化层。
  4. Fully Connected layer (Dense)
    全连接层(密集)

A CNN can typically have multiple Convolution, pooling, Normalization layers and not necessarily following the order.
CNN 通常可以有多个卷积层、池化层、归一化层,并且不一定遵循顺序。

Here are the examples 以下是示例

hirokatsukataoka.net(Picture)
hirokatsukataoka.net(图片)

Cs231n stanford.edu(Picture)
Cs231n stanford.edu(图片)

Okay now let’s make that cat follow all the steps, we will see how it looks like.
好吧,现在让那只猫遵循所有步骤,我们看看它是什么样子的。

after one layer of convolution and pooling, it will look like this
经过一层卷积和池化后,它会看起来像这样

I hope you get the idea how an image transforms and goes to network for training.
我希望您了解图像如何转换并进入网络进行训练。

Here I defined 3 X 3 filter size with 3 filters and pooling size = 2 X 2
这里我定义了 3 X 3 过滤器大小,有 3 个过滤器,池化大小 = 2 X 2

Anyway coding is not in scope in this story.
无论如何,编码不在本故事的范围内。

We need to define the network architecture and some parameters, then we train the model for all the images in the training set for certain no of epochs, and during training we update the weights using ** back propagation.**
我们需要定义网络架构和一些参数,然后我们为训练集中的所有图像训练特定时期的模型,并在训练期间使用反向传播更新权重。

Once the training is done , just like ordinary neural networks we feed forward the test image into the network, at the end we get the probabilities scores.
训练完成后,就像普通的神经网络一样,我们将测试图像馈送到网络中,最后我们得到概率分数。

Cool! right? 凉爽的!正确的?

That’s it for this story , In the next story I will build the convolution neural network from scratch/tensorflow/keras/caffe using the above steps.
这就是这个故事,在下一个故事中我将使用上述步骤从头开始/tensorflow/keras/caffe 构建卷积神经网络。

全部评论 (0)

还没有任何评论哟~