I think it’s a mistake to use tf.square with the constant integer terms there (n_C, n_W and n_H). Try using np.square and using floating point constants like 2. and 4. instead of 2 and 4. The problem is caused by TF being much more strict about integer types, whereas base python and numpy are a bit more forgiving.