无法在卷积 NN 项目上获得不错的验证准确性



我正在尝试设计一个卷积神经网络来检测一个小的红色足球。我已经捕获了 aproxx 4000 张不同配置(添加椅子、瓶子等(的场景图片,里面没有球,还有 4000 张场景图片,也有不同的配置,但球在某个地方。 我正在使用分辨率 32x32 像素。球可以在图片中直观地看到。 这些是一些正面的例子图片(这里是颠倒的(:

我已经尝试了许多设计卷积神经网络的组合,但我找不到一个像样的。我将介绍我尝试过的 2 种架构(一种"正常"大小的架构和非常小的架构(。我一直在设计小型和小型网络,因为它认为我会帮助我解决过度拟合问题。 所以,我试过:普通网络设计

Input: 32x32x3
First Conv Layer:
W_conv1 = tf.Variable(tf.truncated_normal([5, 5, 3, 32], stddev=0.1), name=“w1”)
b_conv1 = tf.Variable(tf.constant(0.1, shape=[32]), name=“b1”) _
h_conv1 = tf.nn.relu(tf.nn.conv2d(x, W_conv1, strides=[1, 1, 1, 1], padding=‘SAME’)+ b_conv1, name=“conv1”)
h_pool1 = tf.nn.max_pool(h_conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding=‘SAME’, name=“pool1”)

第二层:

W_conv2 = tf.Variable(tf.truncated_normal([5, 5, 32, 16], stddev=0.1), name=“w2”)
b_conv2 = tf.Variable(tf.constant(0.1, shape=[16]), name=“b2”)
h_conv2 = tf.nn.relu(tf.nn.conv2d(h_pool1, W_conv2, strides=[1, 1, 1, 1], padding=‘SAME’)+ b_conv2, name=“conv2”)
h_pool2 = tf.nn.max_pool(h_conv2, ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1], padding=‘SAME’, name=“pool2”)

全连接层:

W_fc1 = tf.Variable(tf.truncated_normal([8 * 8* 16, 16], stddev=0.1), name=“w3”)
b_fc1 = tf.Variable(tf.constant(0.1, shape=[16]), name=“b3”)
h_pool2_flat = tf.reshape(h_pool2, [-1, 8816], name=“flat3”)
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1, name=“conv3”)

辍学

keep_prob = tf.placeholder(tf.float32, name=“keep3”)
h_fc2_drop = tf.nn.dropout(h_fc1, keep_prob, name=“drop3”)

读出层

W_fc3 = tf.Variable(tf.truncated_normal([16, 2], stddev=0.1), name=“w4”)
b_fc3 = tf.Variable(tf.constant(0.1, shape=([2]), name=“b4”) )
y_conv = tf.matmul(h_fc2_drop, W_fc3, name=“yconv”) + b_fc3

其他信息

cross_entropy = tf.reduce_mean(
_ tf.nn.softmax_cross_entropy_with_logits(labels=y, logits=y_conv)+ 0.005 * tf.nn.l2_loss(W_conv1)+ 0.005 * tf.nn.l2_loss(W_fc1) + 0.005 * tf.nn.l2_loss(W_fc3)) _
train_step = tf.train.AdamOptimizer(1e-5,name=“trainingstep”).minimize(cross_entropy)
_#Percentage of correct _
prediction = tf.nn.softmax(y_conv, name=“y_prediction”) _
correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y,1), name=“correct_pred”)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32), name=“acc”)

参数

keep_prob: 0.4
batch_size=500
training time in generations=55

结果

Training set final accuracy= 90.2%
Validation set final accuracy= 52.2%

图形链接 : 链接到准确性图表

小型网络设计

Input: 32x32x3

第一层:

W_conv1 = tf.Variable(tf.truncated_normal([5, 5, 3, 16], stddev=0.1), name=“w1”)
_b_conv1 = tf.Variable(tf.constant(0.1, shape=[16]), name=“b1”) _
h_conv1 = tf.nn.relu(tf.nn.conv2d(x, W_conv1, strides=[1, 1, 1, 1], padding=‘SAME’)+ b_conv1, name=“conv1”)
h_pool1 = tf.nn.max_pool(h_conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding=‘SAME’, name=“pool1”)

全连接层:

W_fc1 = tf.Variable(tf.truncated_normal([16 * 16* 16, 8], stddev=0.1), name=“w3”)
b_fc1 = tf.Variable(tf.constant(0.1, shape=[8]), name=“b3”)
h_pool2_flat = tf.reshape(h_pool1, [-1, 161616], name=“flat3”)
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1, name=“conv3”)

辍学

keep_prob = tf.placeholder(tf.float32, name=“keep3”)
h_fc2_drop = tf.nn.dropout(h_fc1, keep_prob, name=“drop3”)

读出层

W_fc3 = tf.Variable(tf.truncated_normal([8, 2], stddev=0.1), name=“w4”)
b_fc3 = tf.Variable(tf.constant(0.1, shape=([2]), name=“b4”) )
y_conv = tf.matmul(h_fc2_drop, W_fc3, name=“yconv”) + b_fc3

其他信息

cross_entropy = tf.reduce_mean(
_ tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y_conv)+ 0.005 * tf.nn.l2_loss(W_conv1)+ 0.005 * tf.nn.l2_loss(W_fc1) + 0.005 * tf.nn.l2_loss(W_fc3)) _
train_step = tf.train.AdamOptimizer(1e-5,name=“trainingstep”).minimize(cross_entropy)
_#Percentage of correct _
prediction = tf.nn.softmax(y_conv, name=“y_prediction”) _
correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y,1), name=“correct_pred”)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32), name=“acc”)

参数

keep_prob: 0.4
batch_size=500
training time in generations=55

结果

Training set final accuracy= 87%
Validation set final accuracy= 60.6%

图 链接到准确性图表

所以,我所做的一切,我都无法在验证测试中获得像样的准确性。 我确信这是缺少的东西,但我无法确定是什么。我正在使用 dropout 和 l2,但它似乎无论如何都过度拟合

感谢您的阅读和业余或高级CNN,请留下反馈

您的结果和准确性曲线对我来说似乎很正常,因此模型学习良好。几点建议:

  • 正如评论中已经指出的那样,您可能需要更大的数据集。将您的数据集与 CIFAR-10 进行比较,CIFAR-10 具有 50000 个训练图像和 10000 个测试图像,也是 32x32。只是您的训练数据可能包含太多的变体来预测您的验证/测试图像。考虑使用图像增强技术来人为地扩展数据集。
  • 当您有足够的数据时,将大部分数据用于训练。例如,在 10000 张图像中,我会像这样拆分它:7000 张用于训练,1500 张用于验证,1500 张用于测试。这将降低过度拟合的可能性。
  • 如果您确定您的训练数据集很好地代表了目标人群,您可能希望使用正则化超参数:我注意到辍学概率和 L2 正则化器。通常,通过增加这些参数,可以对抗过度拟合并改善泛化。早期层通常需要比后期层更小的辍学值。还可以考虑尝试批处理范数,这是另一种有助于泛化的技术。
  • 您可能还想调整其他超参数(学习率、过滤器大小、过滤器数量、批量大小等(以获得更好的性能。这里有一个很好的讨论如何有效地做到这一点。
  • 您是否在 10 个 epoch 后停止训练(这是图表上的限制(?你可能应该给它更多的时间,因为对于CIFAR-10,有时需要30-50个时期才能学好。

最新更新