简体   繁体   English

尝试为 CIFAR-10 创建一个完全连接的神经网络

[英]Trying to create a fully connected neural network for CIFAR-10

I am a relative beginner when it comes to machine learning.在机器学习方面,我是一个相对的初学者。

I have been playing with Keras with TensorFlow as a backend and for some reason I am not getting good accuracy when I am using the CIFAR-10 dataset.我一直在使用 TensorFlow 作为后端使用 Keras,由于某种原因,当我使用 CIFAR-10 数据集时,我没有获得很好的准确性。

This is my code.这是我的代码。

model = Sequential()

batch_size = 250

model.add(Dense(100, input_shape = (3072, ), activation='relu',
bias_initializer = 'RandomNormal',kernel_regularizer=regularizers.l2(.01)))


model.add(Dense(50))

model.add(Dense(10))

model.compile(optimizer=keras.optimizers.SGD(lr=0.004), 
loss='hinge', metrics=['categorical_accuracy'])

model.fit(x=X_train, y=utils.to_categorical(Y_Train, num_classes = 10), 
batch_size = batch_size, epochs = 100, validation_split = .4)

X_Train is a (50000, 3072) numpy array and Y_Train is a (50000, 1) numpy array. X_Train 是一个 (50000, 3072) numpy 数组,Y_Train 是一个 (50000, 1) numpy 数组。

The result I got was我得到的结果是

loss: 1.1865损失:1.1865

categorical_accuracy: 0.1696 categorical_accuracy:0.1696

val_loss: 1.1859价值损失:1.1859

val_categorical_accuracy: 0.1668 val_categorical_accuracy:0.1668

in 100 epochs.在 100 个时代。

My setup is Ubuntu 18.04, Python 3.6, Numpy 1.16, Keras 2.2.4我的设置是 Ubuntu 18.04、Python 3.6、Numpy 1.16、Keras 2.2.4

Is there something wrong in my code or is it the fact that a fully connected neural network is just a bad setup for image classification and one should use a convolution neural network?我的代码是否有问题,或者是完全连接的神经网络对于图像分类来说只是一个糟糕的设置,应该使用卷积神经网络?

There are a number of issues with your model:您的模型存在许多问题:

  • Layers 2 and 3 have no activation, and are thus linear (useless for classification, in this case)第 2 层和第 3 层没有激活,因此是线性的(在这种情况下对分类无用)

  • Specifically, you need a softmax activation on your last layer.具体来说,您需要在最后一层进行 softmax 激活。 The loss won't know what to do with linear output.损失不知道如何处理线性输出。

  • You use hinge loss, when you should be using something like categorical_crossentropy .当您应该使用诸如categorical_crossentropy东西时,您会使用hinge损失。

What Jibin said about your fully connected model not being complex enough is not true, you don't need much complexity to get decent accuracy on CIFAR10. Jibin 所说的关于您的全连接模型不够复杂的说法是不正确的,您不需要太多复杂性即可在 CIFAR10 上获得不错的准确性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM