DLS_C4_W1_Assign2_Exercise 2 - convolutional_model

Hello! I hope you are doing well.

I am stuck in DLS_C4_W1_Assign2_Exercise 2 - convolutional_model. Getting this 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.

I tried to find the solution here in a community and no one faced that error. However, I found that someone shared the whole code of that exercise, I copied that and passed all test.

But I am curious to know the following things:

  1. Given that tfl.Conv2D(filters= … , kernel_size= … , padding=‘same’)(input_img). What is happening between these two brackets? One bracket with **kwargs and another with input_img. This guide only shows one bracket.
  2. Previously, I did ReLU(Z1) and got error but ReLU()(Z1) is correct. What is difference between these two. Relu guide shows only one bracket.

I passed this assignment by copying code from here. However, I am curious to know about the above error and two points. And admin! need to delete the code from where I copied.

Saif.

Please go through tensorflow functional api

It’s very lengthy but I will do that after completing course 4. Thank Balaji.

The syntax we’re using for the functional API does two things in one line:

  • Creates the layer, including any arguments required to define the layer. The arguments are inside the first set of parenthesis.
  • Passes a dataflow to it. This is what the second set of parenthesis does. Typically this is is the output of a previous layer.
1 Like

In other words, the Layer function is a function that returns another function as its return value. Then you invoke that returned function with the appropriate input tensor(s). That’s why you end up with two separate sets of parentheses in one of those expressions.

Here’s another thread that gives a nice introduction to the TF/Keras Sequential and Functional APIs.

1 Like