Tensorflow 如何更改神经网络以提高验证集的准确性?
我们正在使用Tensorflow来训练一个包含Tensorflow 如何更改神经网络以提高验证集的准确性?,tensorflow,neural-network,deep-learning,conv-neural-network,Tensorflow,Neural Network,Deep Learning,Conv Neural Network,我们正在使用Tensorflow来训练一个包含700幅图像的二元分类图像数据集,其中每幅图像都是256*256*1,并且数据集被平均分为两类。我们在Tensorflow上稍微更改了Cifar10模型,我们模型的代码如下所示 # conv1 with tf.variable_scope('conv1') as scope: kernel = _variable_with_weight_decay('weights',
700幅图像的二元分类图像数据集,其中每幅图像都是256*256*1
,并且数据集被平均分为两类。我们在Tensorflow
上稍微更改了Cifar10
模型,我们模型的代码如下所示
# 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
目前,这个。最大精度在65%
和70%
之间波动
我应该更改哪些类型的参数以获得更高的精度?我试图将过滤器大小减小到3,并添加两个退出层(0.5),但它似乎没有改变任何东西。对我来说,您的模型似乎在训练数据中。这意味着您的模型在真正学习数据的基本概念方面没有很好的泛化,而只是简单地记住了700个训练图像。在你的训练数据上看到一个准确度曲线图会很有帮助,我认为它在90%-98%的范围内。您的损失函数显示出非常急剧的下降,而您的验证集的准确性似乎稳定在65%左右。这是过度拟合模型的有力指标
有几个选择。首先,在大多数情况下,只有700张图像的训练集太小了,这使得网络能够非常快地记住数据。您应该尝试收集更多的训练数据和/或对训练数据应用数据扩充,以增加训练图像的总数。这使得网络更难记住每一张图像及其正确的标签
此外,您应该应用()例如权重衰减(L1、L2范数)或您的模型,这有助于网络很好地概括数据。我刚刚对训练数据集的180张图像进行了验证。它确实是100%。。。因此,这绝对是过于合适了。我们每节课有350张图片,总共有2节课。我们每节课需要的最佳图像数量是多少?非常感谢你的建议!他们非常有帮助。这不容易说。。。越多越好,通常每堂课几千美元就好了。请记住,在大多数情况下,您可以通过对每个图像应用数据增强操作(如水平翻转
、随机裁剪
或颜色抖动
)来非常简单地增加训练图像的数量。有一些非常有用的预实现脚本,您可以在数据集上运行这些脚本来扩展它。在通过您的网络传播增强之前,不要运行增强实况,在实际培训之前请执行此操作,并将其存储在LMDB或HD5数据库中以便快速访问。