模型为所有输入(keras)给出相同的输出,精度,损耗

时间:2019-03-04 06:57:32

标签: python tensorflow keras

这是我的大胆无人驾驶汽车模型!

model = Sequential()
model.add(Lambda(lambda x: x/127.5-1.0, input_shape=(64,64,3)))
model.add(Conv2D(3, 1, 1, activation="elu"))
model.add(Conv2D(32, 3, 3, activation='elu'))
model.add(Conv2D(32, 3, 3, activation='elu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
model.add(Dropout(0.5))
model.add(Conv2D(64, 3, 3, activation='elu'))
model.add(Conv2D(64, 3, 3, activation='elu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
model.add(Dropout(0.5))
model.add(Conv2D(128, 3, 3, activation='elu'))
model.add(Conv2D(128, 3, 3, activation='elu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(512, activation="elu"))
model.add(Dense(64, activation="elu"))
model.add(Dense(16, activation="elu"))
model.add(Dense(1, activation="softmax"))
model.summary()

我正在使用adam编译器来编译模型

from keras.optimizers import Adam
model.compile(optimizer=Adam(lr=0.0001),loss='mean_squared_error',metrics='accuracy'])
model.fit(X_train, y_train, batch_size=256, epochs=250, shuffle = True,  validation_split=0.2)

我尝试了每种批次大小和历元组合,但结果似乎是相同的。我最初拍摄12000张图像,用于训练和测试模型。我的问题准确率非常低,并且在整个时期都是恒定的。此外,它还为每个预处理图像预测相同的输出。 (ps:我在训练之前已经对图像进行了预处理)。这里的样本输出显示出恒定的精度和损耗(太低了)。

 Train on 8084 samples, validate on 2021 samples
    Epoch 1/250
    8084/8084 [==============================] - 8s 1ms/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 2/250
    8084/8084 [==============================] - 6s 763us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 3/250
    8084/8084 [==============================] - 6s 779us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 4/250
    8084/8084 [==============================] - 6s 779us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 5/250
    8084/8084 [==============================] - 6s 790us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 6/250
    8084/8084 [==============================] - 6s 770us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 7/250
    8084/8084 [==============================] - 6s 739us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 8/250
    8084/8084 [==============================] - 6s 735us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 9/250
    8084/8084 [==============================] - 6s 724us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 10/250
    8084/8084 [==============================] - 6s 727us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015
    Epoch 11/250
    8084/8084 [==============================] - 6s 729us/step - loss: 1.0467 - acc: 0.0014 - val_loss: 1.0666 - val_acc: 0.0015

请帮助。谢谢

1 个答案:

答案 0 :(得分:0)

您的模型没有学到任何东西,因为您对一个输出神经元使用了softmax激活,这意味着在任何权重值下,输出都是常数1.0。

您应该将激活更改为双曲正切(tanh),因为它与输出[-1,1]的范围匹配。您还应该删除准确性指标,因为它是一项回归任务,准确性仅适用于分类。