I've read that I can see contents of tf variables by using tf.print
inside my tf.function
definition. It doesn't work. My __tf.version__
is 2.5.0. I run the following function inside Jupyter notebook:
tf.compat.v1.disable_eager_execution()
@tf.function
def tf_fun(inputs):
x = tf.strings.lower(inputs)
tf.print(x)
return x
- without print
tf_fun(inputs)
<tf.Tensor 'StatefulPartitionedCall_6:0' shape=(7,) dtype=string>
- with print
print(tf_fun(inputs))
Tensor("StatefulPartitionedCall_5:0", shape=(7,), dtype=string)
I want eager execution to be disabled because I use some functions from tf.Transform
module that works only in graph mode somewhere else in this notebook.
How can I see the contents of tensor to make sure that my function produces exactly what I want?
Another problem (less important) is that if I try to assing returned value to a variable for further processing tf.print
prints anything only when it's the first call to tf_fun
(I know it has something to do with tracing, but I don't understand it and would like to know how to fix it.)
Edit: after adding something from tf.Transorm
module I got an error.
@tf.function
def transform_product1(inputs, top_k_products):
product = tf.strings.lower(inputs)
product = tf.strings.reduce_join(product, -1, separator = ' ')
product = tft.vocabulary(product, top_k= 4)
return product
prod = transform_product1(inputs,4)
sess = tf.compat.v1.Session()
print(sess.run(prod))
InvalidArgumentError: You must feed a value for placeholder tensor 'PartitionedCall_7/vocabulary/temporary_analyzer_output_1/Placeholder' with dtype string
[[{{node vocabulary/temporary_analyzer_output_1/Placeholder}}]]