Henrik
Henrik

Reputation: 531

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. 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.

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

Upvotes: 0

Views: 513

Answers (1)

Daniel Möller
Daniel Möller

Reputation: 86600

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.

Upvotes: 1

Related Questions