只是为了更详细地回答这个问题,正如Pavel所说的,批处理规范化只是另一层,因此您可以使用它来创建所需的网络体系结构。
一般用例是在网络的线性层和非线性层之间使用BN,因为它可以标准化激活函数的输入,从而使您位于激活函数(例如Sigmoid)的线性部分的中心。有一小的讨论在这里
在上述情况下,这可能类似于:
# import BatchNormalizationfrom keras.layers.normalization import BatchNormalization# instantiate modelmodel = Sequential()# we can think of this chunk as the input layermodel.add(Dense(64, input_dim=14, init='uniform'))model.add(BatchNormalization())model.add(Activation('tanh'))model.add(Dropout(0.5))# we can think of this chunk as the hidden layer model.add(Dense(64, init='uniform'))model.add(BatchNormalization())model.add(Activation('tanh'))model.add(Dropout(0.5))# we can think of this chunk as the output layermodel.add(Dense(2, init='uniform'))model.add(BatchNormalization())model.add(Activation('softmax'))# setting up the optimization of our weights sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)model.compile(loss='binary_crossentropy', optimizer=sgd)# running the fittingmodel.fit(X_train, y_train, nb_epoch=20, batch_size=16, show_accuracy=True, validation_split=0.2, verbose = 2)希望这能使事情更清楚。



