'What's the difference between the print inside and outside
I am learning the tensorflow which version is 2.8.0 on my MacBook M1. For debugging the code in the map function of dataset, I want to print tensor value in my function.
def function(i):
print("in: ", i)
if i < 2:
i = i - 1
return i
dataset = tf.data.Dataset.range(1, 6)
dataset = dataset.map(lambda x: tf.py_function(function, inp=[x], Tout=tf.int64))
for x in dataset:
print("out:", x)
I got the output as blew:
in: tf.Tensor(1, shape=(), dtype=int64)
out: tf.Tensor(0, shape=(), dtype=int64)
in: tf.Tensor(2, shape=(), dtype=int64)
out: tf.Tensor(2, shape=(), dtype=int64)
in: tf.Tensor(3, shape=(), dtype=int64)
out: tf.Tensor(3, shape=(), dtype=int64)
in: tf.Tensor(4, shape=(), dtype=int64)
out: tf.Tensor(4, shape=(), dtype=int64)
in: tf.Tensor(5, shape=(), dtype=int64)
out: tf.Tensor(5, shape=(), dtype=int64)
After I delete the print outside, I did not get any output. What's the difference between the print inside and the print outside. I don't understand why it can only take effect when the prints appear at the same time. Beside that, what the difference between print and tf.print?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
