我的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)
e.g:
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了解更多详情。