我有一些麻烦了解使用batchnormalization的DNN模型,在使用keras的详细说明中。有人可以向我解释我构建的这个模型中每一层的结构和内容吗?有关使用keras进行batening规范的dnn层的理论问题
modelbatch = Sequential()
modelbatch.add(Dense(512, input_dim=1120))
modelbatch.add(BatchNormalization())
modelbatch.add(Activation('relu'))
modelbatch.add(Dropout(0.5))
modelbatch.add(Dense(256))
modelbatch.add(BatchNormalization())
modelbatch.add(Activation('relu'))
modelbatch.add(Dropout(0.5))
modelbatch.add(Dense(num_classes))
modelbatch.add(BatchNormalization())
modelbatch.add(Activation('softmax'))
# Compile model
modelbatch.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# Train the model
start = time.time()
model_info = modelbatch.fit(X_2, y_2, batch_size=500, \
epochs=20, verbose=2, validation_data=(X_test, y_test))
end = time.time()
这一点,我想,我的模型的所有层:
print(modelbatch.layers[0].get_weights()[0].shape)
(1120, 512)
print(modelbatch.layers[0].get_weights()[1].shape)
(512,)
print(modelbatch.layers[1].get_weights()[0].shape)
(512,)
print(modelbatch.layers[1].get_weights()[1].shape)
(512,)
print(modelbatch.layers[1].get_weights()[2].shape)
(512,)
print(modelbatch.layers[1].get_weights()[3].shape)
(512,)
print(modelbatch.layers[4].get_weights()[0].shape)
(512, 256)
print(modelbatch.layers[4].get_weights()[1].shape)
(256,)
print(modelbatch.layers[5].get_weights()[0].shape)
(256,)
print(modelbatch.layers[5].get_weights()[1].shape)
(256,)
print(modelbatch.layers[5].get_weights()[2].shape)
(256,)
print(modelbatch.layers[5].get_weights()[3].shape)
(256,)
print(modelbatch.layers[8].get_weights()[0].shape)
(256, 38)
print(modelbatch.layers[8].get_weights()[1].shape)
(38,)
print(modelbatch.layers[9].get_weights()[0].shape)
(38,)
print(modelbatch.layers[9].get_weights()[1].shape)
(38,)
print(modelbatch.layers[9].get_weights()[2].shape)
(38,)
print(modelbatch.layers[9].get_weights()[3].shape)
(38,)
我会感谢您的帮助,在此先感谢。
是的,谢谢,它更清晰,但只是批量标准化的4个参数,我不知道是否可以用另一个数据来评估(如何知道,可以将模型保存在keras中或如果是简单的DNN,你可以通过model.layers.get_weights()来获取权重和偏差来评估另一个数据),所以,我希望做同样的事情,在这种情况下使用批量规范化,但我不知道所有图层中的哪一个需要在另一个环境中进行评估?提前致谢! –
您的意思是您希望使用您学习的模型在没有Keras API的情况下进行预测,并且您想将所有权重和体系结构复制到其他项目中? – Nathan
是的,就像用一个简单的DNN例子一样,我得到这个权重:'weights1 = modelbatch.layers [0] .get_weights()[0]'#1隐藏层 'biases1 = ...' '权重2 = modelbatch.layers [1] .get_weights()[0]'#The 2 hidden layer 'biases2 = .....' 'weights3 = modelbatch.layers [4] .get_weights()[0]'#The输出层 'biases3 = ....' –