Keras模型不学习 [英] Keras model not learning

查看:69
本文介绍了Keras模型不学习的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Keras模型没有学习任何东西,我也不知道为什么.我什至将训练集的大小减少到5个元素,并且该模型仍然不适合训练数据.

My Keras model is not learning anything and I can't figure out why. I even reduced the training set size to 5 elements and the model is still not fitting to the training data.

使用TensorBoard可视化的损失函数

这是我的代码:

model = Sequential()
model.add(Conv1D(30, filter_length=3, activation='relu', input_shape=(50, 1)))
model.add(Conv1D(40, filter_length=(3), activation='relu'))
model.add(Conv1D(120, filter_length=(3), activation='relu'))
model.add(Flatten())
model.add(Dense(1024, activation='relu'))
model.add(Dense(256, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(1, activation='relu'))
model.summary()
model.compile(loss='mse',
              optimizer=keras.optimizers.adam())


train_limit = 5 
batch_size = 4096 
tb = keras.callbacks.TensorBoard(log_dir='./logs/' + run_name + '/', 
    histogram_freq=0, write_images=False)
tb.set_model(model)
model.fit(X_train[:train_limit], y_train[:train_limit],
          batch_size=batch_size,
          nb_epoch=10**4,
          verbose=0,
          validation_data=(X_val[:train_limit], y_val[:train_limit]),
          callbacks=[tb])
score = model.evaluate(X_test, y_test, verbose=0)
print('Test loss:', score)
print('Test accuracy:', score)

任何帮助将不胜感激!

推荐答案

这似乎是一个回归问题.我注意到的一件事是,您的最后一层仍然具有ReLU激活功能.我建议在最后一层取出ReLU.

It seems to be a regression problem. One thing I noticed is that your last layer still has the ReLU activation function. I would recommend taking the ReLU out at the last layer.

这篇关于Keras模型不学习的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆