Functional API-Convolutional Model

For The Functional API,

Z1=Conv2D(input_img), after that, should we continue

I got Input 0 of layer max_pooling2d_52 is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [1, None, 64, 64, 8] after running the code.

If I miss any value like Z1,A1,etc, it says ’ ’ object has no attribute ‘shape’

well I actually passed the test after removing ,
what is happening here?

The last argument inside the square brackets should not be followed by a comma.


Right! The point is that the syntax for the TF/Keras Functional API is different from the syntax for the TF/Keras Sequential API. Examples are given in the notebook.

It turns out that adding the trailing commas in the Functional API causes the RHS of the expression to become a “tuple”, which is (in most cases) not what was intended. If the RHS is already a Tensor, that causes it to sprout an unwanted additional dimension.


Thanks for the tip. I’ve been looking everywhere for a mistake in my code until I find here it’s only a problem of syntax. The course should stress on this kind of thing. I spent >1 hour looking for a fundamental problem when I could have passed the exercise in minutes.

Yes, sorry, the level of explanation they give in the notebook of these new and complex Keras constructs does leave a bit to be desired. You can find a lot more on the Keras documentation site or here is an excellent Discourse thread which covers all this and is definitely worth a look.