I have a model with an input (batch of images w/ shape (height, width, time)) that has a dynamically sized dimension (time), which is only determined at runtime. However, the Flatten
layer requires fully defined spatial dimensions. Code snippet example:
import tensorflow as tf
from tensorflow.keras.layers import Dense, Flatten, Input
# Define an input with an undefined dimension (None)
input_tensor = Input(shape=(None, 256, 256, None, 13))
# Apply a Dense layer (which expects a fully defined shape)
x = Flatten()(input_tensor)
x = Dense(10)(x)
# Build the model
model = tf.keras.models.Model(inputs=input_tensor, outputs=x)
model.summary()
This raises the error:
ValueError: The last dimension of the inputs to a Dense layer should be defined. Found None.
How can I make it work using Flatten
instead of alternatives like GlobalAveragePooling3D
? I need to retain all pixel-level information.
2