我的CNN模型架构如下:
def model_a(x_train):
input_batch = tflearn.layers.core.input_data(shape=(None, x_train.shape[1], x_train.shape[2], x_train.shape[3]))
input_batch = tflearn.layers.normalization.batch_normalization(input_batch)
network = tflearn.layers.conv.conv_2d(input_batch, 32, 5, activation='relu')
network = tflearn.layers.conv.max_pool_2d(network, 2,2)
network = tflearn.dropout(network, .8)
network = tflearn.layers.conv.conv_2d(network, 32, 5, activation='relu')
network = tflearn.layers.conv.max_pool_2d(network, 2,2)
network = tflearn.dropout(network, .8)
network = tflearn.fully_connected(network, 256, activation='relu')
network = tflearn.dropout(network, .8)
network = tflearn.fully_connected(network, 128, activation='relu')
network= tflearn.dropout(network, .8)
network = tflearn.fully_connected(network,2, activation='softmax')
return network
我想在训练的每一层之后打印并保存特征矢量形状,并在训练结束时保存每一层的权重。我如何在tflearn中做到这一点?
最佳答案
您可以使用以下方法获取层的权重和偏差值:
model.get_weights(layer_name.W)
model.get_weights(layer_name.b)
例如:
network1 = tflearn.layers.conv.conv_2d(input_batch, 32, 5, activation='relu')
network2 = tflearn.layers.conv.max_pool_2d(network1, 2,2)
network3 = tflearn.dropout(network2, .8)
// ...
// To get the weights and bias value of the convolutional layer i.e. network1
weight_network1 = model.get_weights(network1.W)
bias_network1 = model.get_weights(network1.b)
您可以查看此example以获得更多详细信息。
关于python - 如何在CNN中的每一层之后打印特征矢量形状,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54414092/