Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Keras in TensorFlow 2.0?

Actually, I find the problem already in TensorFlow 1.13.0. (tensorflow1.12.0 works well).

My code is listed as a simple example:

def Lambda layer(temp):
    print(temp)
    return temp

which is used as a lambda layer in my Keras model. In tensorflow1.12.0, the print(temp) can output the detail data like following

[<tf.Tensor: id=250, shape=(1024, 2, 32), dtype=complex64, numpy=
array([[[ 7.68014073e-01+0.95353246j,  7.01403618e-01+0.64385843j,
          8.30483198e-01+1.0340731j , ..., -8.88018191e-01+0.4751519j ,
         -1.20197642e+00+0.6313924j , -1.03787208e+00+0.22964947j],
        [-7.94382274e-01+0.56390345j, -4.73938555e-01+0.55901265j,
         -8.73749971e-01+0.67095983j, ..., -5.81580341e-01-0.91620034j,
         -7.04443693e-01-1.2709806j , -3.23135853e-01-1.0887597j ]],

It is because I use the 1024 as batch_size. But when I update to tensorflow1.13.0 or TensorFlow 2.0, the same code's output

Tensor("lambda_1/truediv:0", shape=(None, 1), dtype=float32)

This is terrible since I can not know the exact mistakes. So, any idea about how to solve it?

like image 463
LinTIna Avatar asked Apr 15 '19 05:04

LinTIna


1 Answers

You see that output because the Keras model is being converted to its graph representation, and thus print printes the tf.Tensor graph description.

To see the content of a tf.Tensor when using Tensorflow 2.0 you should use tf.print instead of print since the former gets converted to its graph representation while the latter doesn't.

like image 141
nessuno Avatar answered Oct 15 '22 14:10

nessuno