C1W3_Lab Error: "Layer has never been called and thus has no defined input"

I’m following the lab without making any change. However I received the error message “Layer has never been called and thus has no defined input”.

The following is how this model is defined and called. Does anyone has any suggestion about what is missing?

Did you try running down all codes in one cell?? Does it run successfully then?

I also get this error for all of the labs where it trys to show images of how the convolutions work.
If i uninstall Tensorflow and reinstall an old version it works, but obviously is not very efficient and it would be useful to know what the equivalent code is in the new Tensorflow.

I’m also getting the same error for layer 3. I did try adding the following line suggested by Gemeni

_ = model.predict(test_images[0:1].reshape(1, 28, 28, 1))

but of no help.

I tried running all the lines of code in a single cell and still continued to get the error. Each run the error differs i.e. first run, error is layer sequential_1, 2dn run, layer sequential_4 etc.

I am sharing a very well explained post related to recalling sequential layers, I don’t if it’s related to this, but surely will help you understand how one needs to recall codes related to sequential and functional api

This is expected behavior if you are not explicitly naming layers in your code. In the absence of a name=‘my_layer_name_here’ parameter, layer names will be generated using the layer type appended with underscore plus the integer count of that type of layer.

I believe if you restart the collab
Session from scratch the numbers will restart at _1 so I wouldn’t spend time debugging there.

I haven’t looked at this exercise in several years and don’t have access to a current notebook, but just from the symptom described it does seem related to how the model input shape is being used.

I just ran on Colab and got the same reported error. I added print statements and see that the versions running in my env are:

TensorFlow: 2.17.0
Keras : 3.4.1

I do think there is a difference in how input and input shape is handled in Keras 3.x Model, but am not an expert on the change and am not an active Mentor for these courses any longer. Perhaps someone who is can join the thread.

The technical lead for this course is @chris.favila.

I did a little search on stackoverflow. It does seem to be related to tensorflow version. My colab has tf version 2.17.0.

I tried to call the model with an input, instead of using the input_shape parameter which caused warning.

original model definition:
image

revised model definition:
image

Now the error has changed to:

Can anyone please help? Troubleshooting is too hard for a new tensor flow learner.

did you refer the pinned link my previous comment by ai_curious

Hi! This is indeed a problem with TF2.17 using Keras 3 by default. We’ve updated the notebook to pin to TF2.15 . Kindly re-launch the notebook from your classroom to see the changes. Thank you!

2 Likes

Thanks for the update .

Confirmed that the visualization cell runs without error for me, though I did get this report during the package loading step…


ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorstore 0.1.64 requires ml-dtypes>=0.3.1, but you have ml-dtypes 0.2.0 which is incompatible.

Hi Nomen! Glad it works now. Those errors during the pip install are expected because of bundled packages with Colab. It shouldn’t affect those that are needed in this lab so I don’t think we should resolve them. Thanks!