TensorFlow 2.12: Shape Mismatch scenarios When Using tf.keras.layers.Concatenate with Different Input Shapes
I'm building a feature where I'm working with a shape mismatch behavior when trying to concatenate the outputs of two different branches in my TensorFlow model. I have two sub-models that output tensors with different shapes, and I'm trying to concatenate them using `tf.keras.layers.Concatenate(axis=-1)`. The first model outputs a tensor of shape `(None, 64)` and the second model outputs a tensor of shape `(None, 32)`. When I attempt to concatenate them, I get the following behavior: ``` ValueError: Shapes (None, 64) and (None, 32) are incompatible ``` I've double-checked that the dimensions along the concatenation axis (the last dimension here) are indeed different, which is causing the scenario. I've tried reshaping the outputs using `tf.keras.layers.Reshape` but that hasn't worked as expected. Hereβs a snippet of my model: ```python import tensorflow as tf input1 = tf.keras.Input(shape=(64,)) input2 = tf.keras.Input(shape=(32,)) # Sub-models model1 = tf.keras.layers.Dense(64, activation='relu')(input1) model2 = tf.keras.layers.Dense(32, activation='relu')(input2) # Attempt to concatenate outputs concatenated = tf.keras.layers.Concatenate()([model1, model2]) # Final output layer output = tf.keras.layers.Dense(10, activation='softmax')(concatenated) # Complete model model = tf.keras.Model(inputs=[input1, input2], outputs=output) ``` I thought using `Concatenate` would handle the different shapes automatically as long as the other dimensions matched. Is there a way to resolve this shape mismatch or should I consider restructuring my models to ensure the outputs are compatible before concatenation? Any advice or tips would be greatly appreciated! For context: I'm using Python on macOS. Any ideas what could be causing this? My team is using Python for this desktop app. What are your experiences with this? For context: I'm using Python on Ubuntu 20.04. Thanks, I really appreciate it!