Week 1 Assignment 2 Exercise 2 OperatorNotAllowedInGraphError in ReLU

I get the following error:

OperatorNotAllowedInGraphError: using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.

when running the code:
in convolutional_model(input_shape)
42 Z1 = tf.keras.layers.Conv2D(8,(4,4),strides=1,padding=‘SAME’)(input_img)
43 ## RELU
—> 44 A1 = tf.keras.layers.ReLU(Z1)

Looks like the output of Conv2D layer Z1 cannot be evaluated in ReLU function.
Any help how to overcome this problem?

Please understand functional API to know the difference between layer creation via __init__ and invoking the layer via __call__.

1 Like

Here is a thread which gives a good introduction to the Keras Sequential and Functional APIs.

1 Like