python batch_python – 我在哪里调用Keras中的BatchNormaliza...

只是为了更详细地回答这个问题,并且正如Pavel所说,批量标准化只是另一层,因此您可以使用它来创建所需的网络架构.

一般用例是在网络中的线性和非线性层之间使用BN,因为它将激活函数的输入规范化,因此您将在激活函数的线性部分(例如Sigmoid)中居中.对它有一个小小的讨论here

在上面的例子中,这可能看起来像:

# import BatchNormalization

from keras.layers.normalization import BatchNormalization

# instantiate model

model = Sequential()

# we can think of this chunk as the input layer

model.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 layer

model.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 fitting

model.fit(X_train, y_train, nb_epoch=20, batch_size=16, show_accuracy=True, validation_split=0.2, verbose = 2)

希望这能澄清一些事情.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值