ImportError: cannot import name 'wrappers' from 'tensorflow.python.keras.layers'

Hi I get an error when executing plot_model. I am lost here, anyone can help? (I am in Google Colab)

Hi there, did you sort this out? Which lab or assignment is this?

hi @gent.spah , thanks for reaching out.
It appears in numerous labs, for example in C1_W1_Lab_1_functional-practice.ipynb.
I import the library without any problems but when calling the function it gives me an error.

I tried one of those labs but there were no problems. So i guess that is in the colab, you should check if there are utils files on the lab folder in coursera and if any imports are done in there. Secondly you should search in google how to import wrapers from tensorflow, it might have changed as updates roll on.


Please change the import plot_model like this and give it a shot:
from tensorflow.keras.utils import plot_model

Thanks, @gent.spah and @balaji.ambresh but, doesn’t work.

@gent.spah Could you please file a ticket on the repo if this is a real issue? It’d be better for the staff to fix dependencies.

@balaji.ambresh I ran one of the labs there was no issue for me running it. I think shes running it on Colab and the lab is in coursera!

Hey @balaji.ambresh : This worked for me in colab. Thanks.

I also added these 2 lines as I was trying to get some lucidity in the code:

model_plot = plot_model(model, show_shapes= True, show_layer_names = True, to_file = ‘model.png’)

If the rules allow, I will add a ink to my colab notebook.

1 Like

Maybe you need to update Tensorflow, cause it might have been damaged,
use either conda or pip to update,
I prefer that you update your environment every month.

Thanks for this thread.

I ran the C1W1 lab1 in VS Code on my local machine (MacBook Pro M1 Max) in a Conda environment that includes TensorFlow, and I experienced the error described at the beginning of this thread (“…cannot import ‘wrappers’ from ‘tensorflow.python.keras.layers’”).

To resolve it, I created a new code cell in the notebook just before the line ‘model= build_model_with_sequential()’ and ran the line ‘from tensorflow.keras.utils import plot_model’.

In case it matters, just before this step, I used pip to install pydot in the Conda environment: ‘pip install pydot’ (see this thread in Stackoverflow, if desired: Error `Cannot import name 'wrappers' from 'tensorflow.python.keras.layers'`? - Stack Overflow). Together, these two actions solved the wrapper error in my case. I recommend trying the import by itself before bothering with the installation of pyplot as well.