C2_W2_Assignment - Exercise 2 - model.summary() shows error

In the exercise 2 of the graded lab of week 2, if the below instruction is missing
tf.keras.Input(shape=(400,)), #specify input size
when creating the model, the call model.summary() shows below error


ValueError Traceback (most recent call last)
in
----> 1 model.summary()

/opt/conda/lib/python3.7/site-packages/keras/engine/training.py in summary(self, line_length, positions, print_fn, expand_nested, show_trainable)
2774 if not self.built:
2775 raise ValueError(
→ 2776 'This model has not yet been built. ’
2777 'Build the model first by calling build() or by calling ’
2778 ‘the model on a batch of data.’)

ValueError: This model has not yet been built. Build the model first by calling build() or by calling the model on a batch of data.

That instruction is not mandatory for the exercise. I wonder if it can be added to the base code of the exercise to avoid the errors and save some debugging time.

Hi Hoan, welcome to the community!

Including the line tf.keras.Input(shape=(400,)), #specify input size in the base code is a good idea to preemptively handle the model build requirement, as it ensures that the input shape is explicitly defined. This would avoid the ValueError about the model not being built, which often occurs when the model is not initialized with specific input dimensions.