print out the shape of each layer in the net architecture

让人想犯罪 __ 提交于 2019-12-05 14:37:04

If a layer has a single node (i.e. if it isn't a shared layer), you can get its input tensor, output tensor, input shape and output shape via: layer.input_shape

from keras.utils.layer_utils import layer_from_config

config = layer.get_config()
layer = layer_from_config(config)

Source: https://keras.io/layers/about-keras-layers/

May be this the easiest way to do:

model.layers[layer_of_interest_index].output_shape
daoliker

Just using model.summary(), which gives you pretty print.

To print the complete model and all of its dependencies you can also look here: https://keras.io/visualization/

I used this command to save my model visualization as a png:

from keras.utils.visualize_util import plot
plot(model, to_file='model.png')

If you only want to print the layer shape you can do something like this:

layer = model.layers[-1]
print(layer.output._keras_shape)

Prints: (None, 1, 224, 224) # Nr. Filters, Channels, x_dim, y_dim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!