gpt4 book ai didi

python - Keras:如何在顺序模型中获取图层形状

转载 作者:太空狗 更新时间:2023-10-29 17:21:31 26 4
gpt4 key购买 nike

我想访问 Sequential Keras 模型中所有层的层大小。我的代码:

model = Sequential()
model.add(Conv2D(filters=32,
kernel_size=(3,3),
input_shape=(64,64,3)
))
model.add(MaxPooling2D(pool_size=(3,3), strides=(2,2)))

然后我想要像下面这样的一些代码来工作

for layer in model.layers:
print(layer.get_shape())

.. 但事实并非如此。我收到错误:AttributeError: 'Conv2D' object has no attribute 'get_shape'

最佳答案

如果你想以一种奇特的方式打印输出:

model.summary()

如果您想要以可访问的形式显示尺寸

for layer in model.layers:
print(layer.get_output_at(0).get_shape().as_list())

可能有比这更好的访问形状的方法。感谢 Daniel 的启发。

关于python - Keras:如何在顺序模型中获取图层形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com