如何更改神经网络以提高验证集的准确性?

时间:2017-04-21 12:42:36

标签: tensorflow neural-network deep-learning conv-neural-network

我们使用Tensorflow训练二元分类图像数据集700 images,其中每个图像都是256*256*1,数据集平均分为两个类。我们稍微更改了Cifar10上的Tensorflow模型,我们的模型代码如下所示。

# conv1
with tf.variable_scope('conv1') as scope:
    kernel = _variable_with_weight_decay('weights',
                                     shape=[5, 5, 1, 256],
                                     stddev=5e-2,
                                     wd=0.0)
    conv = tf.nn.conv2d(images, kernel, [1, 1, 1, 1], padding='SAME')
    biases = _variable_on_cpu('biases', [256], tf.constant_initializer(0.0))
    pre_activation = tf.nn.bias_add(conv, biases)
    conv1 = tf.nn.relu(pre_activation, name=scope.name)
    _activation_summary(conv1)

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

# conv2
with tf.variable_scope('conv2') as scope:
    kernel = _variable_with_weight_decay('weights',
                                     shape=[5, 5, 256, 256],
                                     stddev=5e-2,
                                     wd=0.0)
    conv = tf.nn.conv2d(norm1, kernel, [1, 1, 1, 1], padding='SAME')
    biases = _variable_on_cpu('biases', [256], tf.constant_initializer(0.1))
    pre_activation = tf.nn.bias_add(conv, biases)
    conv2 = tf.nn.relu(pre_activation, name=scope.name)
    _activation_summary(conv2)

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

# local3
with tf.variable_scope('local3') as scope:
  reshape = tf.reshape(pool2, [FLAGS.batch_size, -1])
  dim = reshape.get_shape()[1].value
  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)

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)

我们使用 batchsize = 2 学习率= 0.005

目前,lossvalidation accuracy看起来像这样。最高准确度在65%70%之间反弹。

我应该更改哪些参数以获得更高的准确度?我试图将滤镜大小减小到3并添加两个丢失图层(0.5)但它似乎没有改变任何东西。

1 个答案:

答案 0 :(得分:1)

对我而言,您的模型在训练数据上似乎是overfitting。这意味着您的模型在真正学习数据的基本概念方面并不能很好地概括,而只是简单地记住700个训练图像。查看训练数据的准确度图会很有帮助,我认为这个数据的范围在90%到98%之间。您的损失函数显示出非常大幅度的下降,而验证集的准确度似乎达到了65%的稳定水平。这是过度拟合模型的强有力指标。

有几种选择。首先,在大多数情况下,只有700张图像的训练集很小,这使得网络可以非常快速地记忆数据。您应该尝试收集更多训练数据和/或将数据增强应用于训练数据,以增加训练图像的总数。这使得网络难以记住每个图像及其正确的标签。

此外,您应该将regularization operationslecture slides)(如称重衰减(L1,L2规范)或Dropout)应用于您的模型,以帮助网络更好地概括数据。< / p>