如何为我的python keras ANN添加噪声(抖动),以避免过度拟合?

问题描述 投票:0回答:2

我正在Python Keras中实现人工神经网络模型,并且在培训中获得了很高的准确性,但在测试中却获得了较低的准确性。这意味着数据中存在一些过拟合。

我想避免过拟合,其中一种技术是抖动或添加噪声。但是,我的问题是:如何在Python中做到这一点?

这是我的ANN代码:

def designANN(input_nodes, dropout, layer_nodes, output_nodes):

    classifier = Sequential()

    classifier.add(Dense(units = layer_nodes, kernel_initializer = "uniform",
                 activation = "relu", input_dim = input_nodes)) 

    classifier.add(Dropout(dropout))

    classifier.add(Dense(units = layer_nodes, kernel_initializer = "uniform",
                 activation = "relu"))
    classifier.add(Dropout(dropout))


    classifier.add(Dense(units = output_nodes, kernel_initializer = "uniform",
                 activation = "sigmoid"))


    classifier.compile(optimizer = "adam", loss = "binary_crossentropy", metrics = [npv])

    return classifier
python keras neural-network noise jitter
2个回答
0
投票

您只需要GaussianNoise层。您可以将其放入网络中。我建议在激活功能之前使用它。这是relu的情况,如果我们添加随机噪声,则输出值可能超出范围(<0)]

def designANN(input_nodes, dropout, layer_nodes, output_nodes):

    classifier = Sequential()

    classifier.add(Dense(units = layer_nodes, kernel_initializer = "uniform",
                         input_dim = input_nodes))
    classifier.add(GaussianNoise(0.1))
    classifier.add(Activation('relu'))
    classifier.add(Dropout(dropout))

    classifier.add(Dense(units = layer_nodes, kernel_initializer = "uniform"))
    classifier.add(GaussianNoise(0.1))
    classifier.add(Activation('relu'))
    classifier.add(Dropout(dropout))

    classifier.add(Dense(units = output_nodes, kernel_initializer = "uniform",
                 activation = "sigmoid"))

    classifier.compile(optimizer = "adam", loss = "binary_crossentropy", metrics = [npv])

    return classifier

0
投票

噪声通常是图像或信号添加到您的输入中,因此在这种情况下,它将取决于您的输入。

© www.soinside.com 2019 - 2024. All rights reserved.