简体   繁体   English

Keras中的Flatten()层具有可变的输入形状

[英]Flatten() Layer in Keras with variable input shape

I am working with a CNN implemented in Keras which at some point has a flatten layer. 我正在使用在Keras中实现的CNN,在某些时候它具有平坦的层。 Now, my goal is to allow different input shaped images. 现在,我的目标是允许输入不同形状的图像。 So my first conv. 所以我第一次转换 layer looks something like: 层看起来像:

model.add(Conv2D(...., input_shape=(None, None, 1))

Well in this setup my flatten layer becomes unhappy and tells me to specify the input shape. 在此设置中,我的展平层变得不满意,并告诉我指定输入形状。 As such, I am using a GlobalMaxPooling layer currently, which I would like to avoid. 因此,我目前正在避免使用GlobalMaxPooling层。

After all, why does the flatten layer bother about the width and height? 毕竟,扁平层为什么会在宽度和高度上困扰呢?

Background: I try to train a net for classification (smaller resolution) and afterwards use this net for object detection (higher resolution) 背景:我尝试训练一个用于分类的网络(较小的分辨率),然后将该网络用于对象检测(较高的分辨率)

Thanks 谢谢

It bothers about the shape because you will probably want to connect another layer to it. 它困扰着形状,因为您可能想要将另一层连接到该形状。

And its feature dimension will be the basis for the next layer to create its own weights. 并且其特征尺寸将成为下一层创建其自身权重的基础。 A layer can't have a variable size weight matrix, thus, it can't have a variable size feature input. 图层不能具有可变大小的权重矩阵,因此,它不能具有可变大小的要素输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM