I have a problem with the first function in Week3 assignment. I get this error and I can not figure out what did I wrong in box_classes .I used tf.math.argmax function and it seems to be right. The error is copied below. Can anyone help please, thank you in advance.
In line 40 of the above trace, you are assigning tf.boolean_mask the value of a tuple. Why are there two equal signs in that line of code? Then in the next line when you try to use it as a function, it throws an exception.
Note that it looks like you haven’t re-executed the actual yolo_filter_boxes cell since the last time you changed the code.
@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