神经网络参数稳定

时间:2019-10-25 11:25:08

标签: python tensorflow keras conv-neural-network

我正在尝试音频分类。

我的代码-

x_train = (800, 32, 1)
x_test = (200, 32, 1)
y_train = (800, 1)
y_test = (200, 1)

model = Sequential()

model.add(Conv1D(filters=64, kernel_size=20, padding='same', input_shape=(32,1), activation="relu"))
model.add(MaxPooling1D(3))

model.add(Conv1D(filters=64, kernel_size=15, padding='same',  activation="relu"))
model.add(MaxPooling1D(2))

model.add(Conv1D(filters=96, kernel_size=10, padding='same',  activation="relu"))

model.add(Flatten())
model.add(Dense(128, activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(96, activation="relu"))
model.add(Dense(10, activation="softmax"))

model.compile(
    loss ='sparse_categorical_crossentropy',
    optimizer = Adam(lr=0.01),
    metrics = ['accuracy']
)
model.summary()

red_lr= ReduceLROnPlateau(monitor='val_loss', patience=3, verbose=1, factor=0.001, mode='min')
check=ModelCheckpoint(filepath=r'/content/drive/My Drive/Colab Notebooks/genre/cnn.hdf5', verbose=1,save_best_only = True)

History = model.fit(x_train,y_train, epochs=30,batch_size=128,validation_data = (x_test, y_test),verbose = 2, callbacks=[check, red_lr,],shuffle=True )

我从1层开始,然后增加该层的准确性 我拥有的最好的模型具有以下值-(损耗:0.5385-acc:0.8275-val_loss:0.8758-val_acc:0.7400)

我在val_acc和val_loss中都运行4至5次都具有相同的模式 这两个参数逐渐增加,并且在执行了一半的时期后,它将在其余时期变得稳定...像这样,

Accuracy Loss

任何提高准确性的建议,以及为什么损失在一半的时间内都没有改变

1 个答案:

答案 0 :(得分:0)

有两个可能的答案。您的模型已经处于局部最小值或超出局部最小值。您可以测试它的方法是在优化器功能中设置较低的学习率:

optimizer = Adam(lr=0.001) # change it to 0.001 or even lower