C2W4 grader cannot execute code due to tf import

In the C2W4 coding assignment the grader can’t execute the code. Error message:

There was a problem compiling the code from your notebook. Details:
No module named ‘keras.layers.pooling.max_pooling2d’; ‘keras.layers.pooling’ is not a package

After getting that error, I reran in a copy of my notebook the assignment, but after submitting it I got the same error again.

Grader uses tensorflow 2.7.0 which considers keras.layers.pooling.max_pooling2d as an invalid import.
Google colab uses tensorflow 2.12.0 which allows the above import.

Please code your notebook to match tensorflow 2.7.0. If you want to use docker, here’s 2.7.0

I tried to follow the instructions I found on the internet. They say that the configuration is under “Runtime”, so “Laufzeit” in German, but there I can only switch between Python3 and R.

Can you give me some detailed instructions how I can change the tf version?
And I also don’t know how to use docker.


In the command prompt or terminal window, you can do this:

pip install tensorflow==2.7.0

And in Jupyter Notebook:

!pip install tensorflow==2.7.0

Please use a virtual environment to ensure that course dependencies don’t interfere with your python setup.

# create a new virtual environment
python -m venv myenv
# activate the virtual environment
source myenv/bin/activate
# install packages
pip install tensorflow==2.7.0

There are many online tutorials on installing docker. Please follow the ones that match your operation system. After that, see the Overview section of the docker hub page I gave you before picking the correct version of the image.

Good luck.

Okay thanks, I thought the notebook will have a mismatch finding different versions of tf.
I tried, but I got an ERROR, saying you can only download 2.8.0 or higher.
So I will try with tf.version 2.8.0

Okay now I got the same problem as the grader had, not knowing that import. My problem now is that I don’t get the import packages. I am not too close to python but I looked into the code of 2.8.0 and there I find the following class definition:
keras_export(‘keras.layers.MaxPool2D’, ‘keras.layers.MaxPooling2D’)
class MaxPooling2D(Pooling2D):

So I would understand the package
I tried to get an API documentation for tf 2.8.0, but I always only found the release notes

Have you got any idea hw I can fix that problem, or where I find the package structure for MaxPooling2D?

So I tried *k eras.layers.MaxPool2D and k eras.layers.MaxPooling2D in the import and both don’t work

Use tf.keras.layers.MaxPool2D

I did already and it looks like some other packages are missing, I get the follwing ERROR:

NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
“Open Examples” button below.

Please click my name and message your notebook as an attachment. Mentors don’t have access to your coursera jupyter workspace. Send the notebook in ipynb format and not in pdf / image format.

The following import is invalid:
from tf.keras.layers.MaxPool2D import MaxPooling2D

Please get familiar with basic python before moving forward. Import statements are common in python and lack of this knowledge can spoil the course experience.

As far as this mistake is concerned, there’s no need for the import statement. Use an instance of tf.keras.layers.MaxPool2D directly inside the sequential model.

Comment these lines out:

# from tf.keras.layers.MaxPool2D import MaxPooling2D
# from keras.layers.serialization import activation

the import statements were already in the notebook. As being a Java Developer I am not so familar with python details, but as the import was done already from the notebook developer I did not expect getting such issues due to different tf versions.
In the end I think these imports should be removed from Cousera in the notebook.