首页 文章

为什么我的CNN无法学习?

提问于
浏览
2

我是新学习者 . 我刚刚使用Tensorflow实现了CNN,并在CIFAR-10(一个对象识别基准测试,图像在 10 different classes 中)上进行了尝试 .

在训练过程中,训练损失在开始时(从100000到3)真的很快下降,但随后它总是停留在 2.30 左右(大约是log(1/10)) . 由于我使用交叉熵作为损失函数,因此损失2.30意味着我的模型具有大约10%的准确度----与随机猜测完全相同(我已经检查了模型的实际输出,实际上几乎都是10%左右)每节课) .

我试图增加模型的大小,以便尝试是否因为我的模型不够“强”到足以装配 . 但事实证明,无论我如何增加或减少模型大小,训练损失总是会在2.30附近停止下降 .

我非常有信心我正确地实现了它,因为我的模型适用于更简单的任务,如MNIST(手写数字识别) . 所以我真的很想知道问题是什么 . 非常感谢 .
enter image description here

conv1:卷积层与relu

pooling1:最大池层

fc1:带有relu的完全连接层

输出:带softmax的全连接层

CODE:

nn = NeuralNetwork(optimizer=Adam(0.001), log_dir='logs')
nn.add(Input('input', [32, 32, 3], ))
nn.add(Convolution2D(name='conv1', filter_height=3, filter_width=3, 
                     n_output_channels=256, activation_fn='relu'))
nn.add(Pooling2D('pooling1', mode='max', pool_shape=(3, 3), padding='SAME'))
nn.add(Convolution2D(name='conv2', filter_height=3, filter_width=3, 
                     n_output_channels=128, activation_fn='relu'))
nn.add(Pooling2D('pooling2', mode='max', pool_shape=(3, 3), padding='SAME'))
nn.add(FullyConnected('fc1', 384, activation_fn='relu',
                      weight_init=truncated_normal(), bias_init=constant(0.1)))
nn.add(FullyConnected('fc2', 192, activation_fn='relu', 
                      weight_init=truncated_normal(), bias_init=constant(0.1)))
nn.add(Output(loss_fn='sparse_softmax_cross_entropy', output_fn='softmax',
              name='output', target_shape=[], target_dtype=tf.int64, 
              output_shape=10))
nn.build()

EDIT:

正如我所提到的 . 我试图通过添加更多图层来增加模型的复杂性,并且几乎尝试了教程中的那个,除了我没有标准层(conv1,pooling1,conv2,pooling2,fc1,fc2,softmax)和预处理像美白等 . 为简单起见,我认为这可能不会影响我的表现,从86%到10%严重 .

Another clue that I think might help is that I found the output of layer fc1 is extremely sparse(almost 99% elements are zeros). Since I use ReLU as activation function, it means the units in fc1 are mostly dead. I there any thing I can do with it?

1 回答

  • 7

    您可能只是严重低估了在此任务上获得合理结果所需的架构 . 您描述的模型(input-> conv1-> pooling1-> fc1-> output)可能适用于MNIST,但这并不意味着它可以在涉及真彩色图像的图像分类任务上实现比随机结果更好的效果 .

    现实情况是,您已经描述过我至少会建议您查看其他可以解决此问题的模型 . 例如,Tensorflow附带一个example CNN,可以在CIFAR-10上达到约86%的准确度,但这个模型更复杂 . 即使有额外的卷积和完全连接的层,规范化和输入预处理(白化,数据增强等)和调整的超参数,在强大的GPU上仍需要几个小时的培训才能获得良好的结果 .

    无论如何,长话短说,我认为您应该查看示例模型,以了解所需的架构类型 . 很容易低估识别随机彩色图像中的对象与黑白数字组合的复杂程度 .

相关问题