cnn

Introduce

Convolutional neural networks (CNNs) are the current state-of-the-art model architecture for image classification tasks. CNNs apply a series of filters to the raw pixel data of an image to extract and learn higher-level features, which the model can then use for classification.

卷积神经网络是目前图片分类任务中最先进的模型架构,卷积神经网络对图片的原始像素数据应用一系列的过滤器来提取和学习更高级的特征,而这正是模型作分类时要用到的

Layers

1. input layer

原始的图片数据

2. Convolutional layers (卷积层)

将原始的图片数据提取成feature map

对图片作卷积操作,常常会加上一个ReLU激活函数对卷积层的输出进行一个非线性映射

$$f(x) = max(x, 0)$$

一个卷积核对应一个feature map

in tensorflow tf.layers.conv2d()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
tf.layers.conv2d(
inputs,
filters,
kernel_size,
strides=(1, 1),
padding='valid',
data_format='channels_last',
dilation_rate=(1, 1),
activation=None,
use_bias=True,
kernel_initializer=None,
bias_initializer=tf.zeros_initializer(),
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
trainable=True,
name=None,
reuse=None
)
  • inputs:
  • filters: filter的数量
  • kernel_size: 卷积窗口大小(感受视野?)
  • strides: 步长,(高,宽) (纵向,横向)
  • padding: valid or same
  • data_format:

channels_last: shape(batch_size, height, width, channels)
channels_first: shape(batch_size, channels, height, width)

  • activation: 激活函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
keras.layers.convolutional.Convolution2D(
nb_filter,
nb_row,
nb_col,
init='glorot_uniform',
activation=None,
weights=None,
border_mode='valid',
subsample=(1, 1),
dim_ordering='default',
W_regularizer=None,
b_regularizer=None,
activity_regularizer=None,
W_constraint=None,
b_constraint=None,
bias=True)
  • dim_ordering: ‘th’ or ‘tf’. In ‘th’ mode, the channels dimension (the depth) is at index 1, in ‘tf’ mode is it at index 3. It defaults to the image_dim_ordering value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be “tf”.

3. Pooling layers (池化层)

in tensorflow tf.layers.max_pooling2d()

feature map降维以减少处理时间

池化层有与卷积层视野大小类似的东西,在tensorflow中叫pool_size

  • max pooling

  • average pooling

4. Dense (fully connected) layers(全连接层)

in tensorflow tf.layers.dense()

通常,CNN由一堆提取特征的卷积模块组成,每个卷积模块包括一个卷积层和紧接着的一个池化层,最后一个卷积模块后跟着一个或多个全连接层,CNN中的最后一个全连接层可以用来预测

Reference

  1. https://blog.csdn.net/cxmscb/article/details/71023576

2.https://www.tensorflow.org/tutorials/layers?hl=zh-cn