C3W3 - Model Summary is empty

@Deepti_Prasad

1 Like

@Ajith1

kindly add the below in the notebook in the beginning of the cell where you built your model

from keras.models import Sequential

Possible issue could be if you do not have keras downloaded

Kindly check if you have keras before you try the above import statement by using

pip show keras

let me know what happens

@Deepti_Prasad

I did not understand why I need to import Sequential explicitly as I am accessing the same using tf.keras.sequential.

Well i still went ahead and added the following line in the cell1 and ran cell after cell with no Change in final output

I do have keras as mentioned below

pip show keras
Name: keras
Version: 3.3.3
Summary: Multi-backend Keras.
Home-page: https://github.com/keras-team/keras
Author: Keras team
Author-email: keras-users@googlegroups.com
License: Apache License 2.0
Location: C:\Users\aa\AppData\Local\anaconda3\envs\oreilly-langchain\Lib\
site-packages
Requires: absl-py, h5py, ml-dtypes, namex, numpy, optree, rich
Required-by: tensorflow-intel
1 Like

i was doing some digging, and what I found, the reason it is probably not taking because model need to be built if the output has come as unbuilt.

another post mentioned to mention the input shape.

i tried multiple times with a new jupyter notebook, and I am getting the desired output.

the last thing which I could suspect in your case is the anaconda issue as I don’t use it.

did you try using this codes on your Google colab once??

@Deepti_Prasad - It seems to work fine in colab but not in anaconda3 environment.

Is there any alternate option for offline-onprem setup other than anaconda which I can try ?

1 Like

so it is anaconda issue as suspected, let me dig in about this issue

because anaconda environment doesn’t require dependencies to run some of packages it is used but the downside of this is probably for the code to run in the local jupyter environment you need to install the dependencies locally.

is your jupyter also located in anaconda environment, I don’t think so!! from what I remember.

probably environment incompatibility is causing the issue of model inbuilt.

regards
DP

@Deepti_Prasad

Yes Jupyterlab is part of anaconda environment.

Hey ajith if you still have this problem, you can downgrade the tensorflow version or add input layer in the model

@ai_curious this is the post I mentioned about. I don’t know if learner could solve his issue.

you can seee I didn’t had recall the input separately, it just worked the way it worked in assignment unlike for the learner.

I had found a solution on Google that input need to be defined separately but I guess it didn’t work for him, I don’t remember now but as I remember your post which had detail explanation about sequential api, I shared in that post for learners, probably it might be helpful to Ajith too I don’t know.

You can have a look at his comment where he shared his keras version and using anaconda environment.

Regards
DP

Have you seen this?

I was having the same problem when running the code from the ungraded lab in Google Colab. It seems that the Sequential model doesn’t get properly built until some data is passed through it – the model.summary() looks just fine after you’ve trained the model.

If you want to check it before training, you can just pass one sample through:

print("Original shape:", training_padded.shape)
sample = training_padded[0:1]
print("Sample shape:", sample.shape)
print("Untrained output:", model(sample))
model.summary()

For me, my untrained output came out as 0.5015231 (not surprising, since model weights are random and untrained), but the model.summary() looked fine after this, as opposed to the “empty” summary that @Ajith1 was describing.

@cjolley
When the model has no idea about the input shape, say via tf.keras.Input layer, it makes sense to pass a sample batch of data for the model to better understand the shape of inputs.

Please share your notebook via a direct message for me to better understand what you’re doing.