model.summary() output shape is “multiple” when defining input_shape via model.build()

When I define a model and pass the input_shape to the first layer, the Output Shape is well-defined after I call model.summary(). However, if I define a model and then pass the input_shape to model.build(), the Output Shape displays as “multiple.” This behavior does not make sense to me. Both models should be identical as far as I can tell.

For example, running this code snippet

import tensorflow as tf
from tensorflow.keras.layers import Dense

if __name__ == '__main__':
    model1 = tf.keras.Sequential([Dense(1, input_shape=[10])])
    print(model1.summary())

    model2 = tf.keras.Sequential([Dense(1)])
    model2.build(input_shape=[None, 10])
    print(model2.summary())

produces this output:

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
dense (Dense)                (None, 1)                 11
=================================================================
Total params: 11
Trainable params: 11
Non-trainable params: 0
_________________________________________________________________
None
Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
dense_1 (Dense)              multiple                  11
=================================================================
Total params: 11
Trainable params: 11
Non-trainable params: 0
_________________________________________________________________
None

System information

  • Have I written custom code (as opposed to using example directory): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04
  • TensorFlow backend (yes / no): yes
  • TensorFlow version: 2.1.0
  • Keras version: 2.3.1
  • Python version: 3.6.9
  • CUDA/cuDNN version: CUDA 10.0 / cuDNN 7.6.5
  • GPU model and memory: NVIDIA GeForce RTX 2080 Ti (11 Gb)

1 possible answer(s) on “model.summary() output shape is “multiple” when defining input_shape via model.build()

  1. Thanks everyone who replied to this issue. As pointed out by @theblackfly, the behavior has been fixed in later versions of tensorflow. Out of curiosity, I tested the releases between 2.1.0 (mine) and 2.3.1 (theblackfly’s); it looks like the bug was first fixed in 2.3.0.