As the title says.
It's best not to use f-string
intf.print ()
.
In fact, let's run the following code and compare the output.
import numpy as np
import tensorflow as tf
@tf.function
def add_a_b(a, b):
c = tf.add(a, b)
print("(1):", c)
tf.print("(2):", f"{c}")
tf.print("(3):", c)
return c
a = tf.constant(np.asarray([[1, 2], [3, 4]]), dtype=tf.float32)
b = tf.constant(np.asarray([[4, 3], [2, 1]]), dtype=tf.float32)
c = add_a_b(a, b)
The output looks like this.
You can see that (2) is f-string
but does not benefit fromtf.print ()
.
(1): Tensor("Add:0", shape=(2, 2), dtype=float32)
(2): Tensor("Add:0", shape=(2, 2), dtype=float32)
(3): [[5 5]
[5 5]]
Recommended Posts