Course 4, Week 3, Part 1: yolo_filter_boxes function problem "TypeError: 'tuple' object is not callable"

@paulinpaloalto has definitely identified a source of trouble. While it is legal Python to have two assignment operators (equal signs) in one line of code, it isn’t what is needed or appropriate here. It also has unintended side effects.

    #this is fine
b = a = 8
print(b)

==> 8

    #this code is also fine
import numpy as np
import tensorflow as tf

print(type(tf.boolean_mask))
<class 'function'>

z = np.ones((3,1))
mask_applied = tf.boolean_mask(z, (True,True,True))
print(mask_applied)

tf.Tensor(
[[1.]
 [1.]
 [1.]], shape=(3, 1), dtype=float64)
    #this code runs, but doesn't do what is intended
not_as_intended = tf.boolean_mask = 8
print(not_as_intended)
print(tf.boolean_mask)
print(type(tf.boolean_mask))

==> 8
==> 8
==> <class ‘int’>

The type of the variable tf.boolean_mask has been changed.

And once its type has been changed from class function to anything else, you can’t treat it as if it were a function and invoke, or call, it. Further, the type won’t be reset until the kernel is restarted and you import tensorflow again.

   #function call that worked above no longer does
try_to_apply_mask_again = tf.boolean_mask(z, (True,True,True))
print(try_to_apply_mask_again)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/var/folders/v3/cqv82ph57nq2c4sggjqqlm180000gn/T/ipykernel_7931/3912514312.py in <module>
----> 1 try_to_apply_mask_again = tf.boolean_mask(z, (True,True,True))
      2 print(try_to_apply_mask_again)

TypeError: 'int' object is not callable
1 Like