0
votes

I am using keras Flatten() layer after a dropout layer whose output shape is (?,35,50). The output of Flatten() is (?,?) whereas it should be (?, 35*50).

The code snippet is-

y2=MyLayer((35,50))(y1)
y2=BatchNormalization()(y2)
y2=Dropout(0.5)(y2)  

y3=Flatten()(y2)

y4=Dense(32)(y2)

The size of output of dropout layer is-

tf.Tensor 'dropout_22/cond/Merge:0' shape=(?, 35, 50) dtype=float32

And that of flatten layer is

tf.Tensor 'flatten_7/Reshape:0' shape=(?, ?) dtype=float32

Please suggest what is wrong.

1
You can always call y3.set_shape((None, 35*50)) if you know its shape.Alexandre Passos

1 Answers

0
votes

"My Layer" is probably the issue you should be checking. When reproduced without it:

from keras.layers import Input, Flatten
from keras.models import Model

input = Input((35, 50))
output = Flatten()(input)

model = Model(input, output)
model.summary()

You'll get

flatten_1 (Flatten) (None, 1750)