'Keras Flatten layer returns output shape (None, None)
So, I noticed this strange behavior of Flatten layer of Keras. I'm using TF1.15 and Keras 2.3.0.
Basically the output of the Flatten layer has an unknown shape. It's hard to troubleshoot the model when you can't keep track of the shape. Why is this happening with Flatten layer, and can I do something so it recognizes the shape?
from keras.layers import Flatten
inputs = Input(shape=(3,2,4))
prediction = Flatten()(inputs)
print(inputs.shape, prediction.shape)
(?, 3, 2, 4) (?, ?)
Solution 1:[1]
Try using tf.keras instead of just keras:
import tensorflow as tf
print(tf.__version__)
inputs = tf.keras.layers.Input(shape=(3,2,4))
prediction = tf.keras.layers.Flatten()(inputs)
print(inputs.shape, prediction.shape)
1.15.2
(?, 3, 2, 4) (?, 24)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AloneTogether |
