Cifar10数据集训练之采用不同池化层的训练结果比较

一 模型介绍

    在这篇博文中(https://blog.csdn.net/paopaovae/article/details/81353242)我们训练了CIFAR10数据集,并在模型上获得了83%的准确率。现在来对卷积神经网络各层进行介绍。

    第一层卷积层我们采用了5*5*3的卷积核,一共用了64个。步长为1,采用padding=SMAE的填充方式,也即不改变输入的高宽维度。

kernel = _variable_with_weight_decay('weights', shape=[5, 5, 3, 64],
                                         stddev=1e-4, wd=0.004)
    conv = tf.nn.conv2d(images, kernel, [1, 1, 1, 1], padding='SAME')
    biases = _variable_on_cpu('biases', [64], tf.constant_initializer(0.0))

    采用Relu激活函数。

 bias = tf.nn.bias_add(conv, biases)
 conv1 = tf.nn.relu(bias, name=scope.name)

    第一层卷积层之后池化层我们采用最大池化的方法。卷积核大小为

 pool1 = tf.nn.max_pool(conv1, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1],
                         padding='SAME', name='pool1')

    在最大池化后,采用LRN层。

norm1 = tf.nn.lrn(pool1, 4, bias=1.0, alpha=0.001 / 9.0, beta=0.75,
                 #   name='norm1')

    第二层卷积层,采用5*5*64的卷积核,一共64个。

kernel = _variable_with_weight_decay('weights', shape=[5, 5, 64, 64],
                                         stddev=1e-4, wd=0.004)
conv = tf.nn.conv2d(pool1, kernel, [1, 1, 1, 1], padding='SAME')
biases = _variable_on_cpu('biases', [64], tf.constant_initializer(0.1))
bias = tf.nn.bias_add(conv, biases)

    同样采用Relu激活函数以及最大池化,以及LRN。

conv2 = tf.nn.relu(bias, name=scope.name)
    _activation_summary(conv2)

norm2 = tf.nn.lrn(conv2, 4, bias=1.0, alpha=0.001 / 9.0, beta=0.75,
                  name='norm2')
pool2 = tf.nn.max_pool(conv2, ksize=[1, 3, 3, 1],
                         strides=[1, 2, 2, 1], padding='SAME', name='pool2')

    然后紧接着两个全连接层。

  with tf.variable_scope('local3') as scope:
    # Move everything into depth so we can perform a single matrix multiply.
    dim = 1
    for d in pool2.get_shape()[1:].as_list():
      dim *= d
    reshape = tf.reshape(pool2, [FLAGS.batch_size, dim])

    weights = _variable_with_weight_decay('weights', shape=[dim, 384],
                                          stddev=0.04, wd=0.004)
    biases = _variable_on_cpu('biases', [384], tf.constant_initializer(0.1))
    local3 = tf.nn.relu(tf.matmul(reshape, weights) + biases, name=scope.name)
    _activation_summary(local3)

  # local4
  with tf.variable_scope('local4') as scope:
    weights = _variable_with_weight_decay('weights', shape=[384, 192],
                                          stddev=0.04, wd=0.004)
    biases = _variable_on_cpu('biases', [192], tf.constant_initializer(0.1))
    local4 = tf.nn.relu(tf.matmul(local3, weights) + biases, name=scope.name)
    _activation_summary(local4)

    最后softmax输出。

  with tf.variable_scope('softmax_linear') as scope:
    weights = _variable_with_weight_decay('weights', [192, NUM_CLASSES],
                                          stddev=1/192.0, wd=0.0)
    biases = _variable_on_cpu('biases', [NUM_CLASSES],
                              tf.constant_initializer(0.0))
    softmax_linear = tf.add(tf.matmul(local4, weights), biases, name=scope.name)
    _activation_summary(softmax_linear)

  return softmax_linear

二 不同池化选择结果之间的比较

    我们选用5000次迭代次数下,比较选用不同池化层的结果。每1000迭代看下实验结果。

    第一层池化和第二层池化都选用最大池化。

    1 

    2 

   3

    4 

    5 

6

    第一层池化和第二层池化都选用平均池化。

    1

    2

    3

    4

    5

    6

    第一层采用平均池化,第二层采用最大池化。

    1

    2

    3

    4

    5

    6

    第一层采用最大池化第二层采用平均池化

    1

    2

    3

    4

    5

    6

    现在来通过表格来看下不同池化之间的loss的比较。其中的loss是均值。

池化方法 0 1000 2000 3000 4000 5000
max-max 4.64 3.08 2.02 1.55 1.26 1.09
max-avg 4.64 3.34 2.20 1.61 1.41 1.33
avg-max 4.64 3.35 2.28 1.82 1.47 1.46
avg-avg 4.63 3.35 2.25 1.84 1.55 1.49

    从表格可以看出两层都采用max-max池化,训练效果最好。其次是max-avg。avg-max和axg-avg效果差不多,都是训练效果不怎么好。这也表明在池化层选用max-pooling效果可能最好。

    来看下各种情况下loss的变化情况,以及学习率的变化。

    max-max

    

    max-avg

    

    avg-max

    

    avg-avg

    由于在每层池化之后,加里LRN层,我们来看下去掉LRN对训练结果有没有影响。

    采用avg-max池化,去掉LRN和保存LRN之间的比较。

有无LRN 0 1000 2000 3000 4000 5000
4.64 3.35 2.28 1.82 1.47 1.46
4.64 3.35 2.41 1.84 1.66 1.46

    可以看出使用LRN层对训练效果几乎没什么影响。

    采用max-max池化,去掉LRN层和保存LRN之间的比较。

有无LRN 0 1000 2000 3000 4000 5000
4.64 3.08 2.02 1.55 1.26 1.09
4.64 3.35 2.17 1.75 1.44 1.25

    可以看出在max-max池化下,LRN层对训练结果还是有很大的影响。看下没有LRN层一些变量的变化。

三 参考

https://www.cnblogs.com/neopenx/p/4480701.html

猜你喜欢

转载自blog.csdn.net/paopaovae/article/details/81409594
今日推荐