Below you will find pages that utilize the taxonomy term “tensorflow”
Blogs
Saving state for tf.function-decorated functions
When you decorate a function with `tf.function` decorator, sometimes you need to keep state between invocations of this function.
The problem here is that the changes to the state will not be visible in the decorated function if the state is saved in the Python variables.
To illustrate the problem, Tensorflow 2.2 is used:
import tensorflow as tf print(tf.__version__) 2.2.0 To see the problem, let’s consider the following code. Let’s assume that we need to scale a given Tensor `x` and we do it using `tf.
Blogs
Using `tf.function` for performance in Tensorflow 2
Tensorflow 2 uses so called Eager mode by default. In this mode, it is easy to define tensors interactively, for example, in ipython and see their values. However, in Eager mode the execution is slow, which becomes noticable during model training.
Tensorflow 2 offers another mode of execution called Graph mode. In this mode, first the computational graph is created and then used to compute loss function and its gradient. This mode is more performance efficient.