当我像这样在Keras中创建模型时:
from keras.models import Model
my_model = model_building_function() # returns a Keras Model
inputs = keras.layers.Input(shape=(None, None, 3))
outputs = my_model(inputs)
my_model = Model(inputs, outputs)
my_model
的摘要(使用Model.summary()
)将导致如下结果:
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input (InputLayer) (None, None, None, 3) 0
__________________________________________________________________________________________________
model_1 (Model) multiple 23561152 input[0][0]
__________________________________________________________________________________________________
==================================================================================================
Total params: 23,561,152
Trainable params: 23,454,912
Non-trainable params: 106,240
__________________________________________________________________________________________________
my_model
(keras.utils.plot_model
)的绘制图也是如此。
有什么办法可以解开模型,使各个图层可见?
答案 0 :(得分:0)
您可以获取模型/图层的layers
属性,如果是模型,则可以打印其摘要。
def sub_models(layer):
if isinstance(layer, Model):
print('summary for model ' + layer.name)
layer.summary()
if hasattr(layer, 'layers'):
for l in layer.layers:
sub_models(l)
sub_models(my_model)