2
我的Keras模型沒有學習任何東西,我不明白爲什麼。我甚至將訓練集大小減少到5個元素,並且該模型仍然不適合訓練數據。Keras model not learning
loss function visualized with 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)
任何幫助,不勝感激!