Should I use @tf.function for all functions?

TLDR: It depends on your function and whether you are in production or development. Don’t use tf.function if you want to be able to debug your function easily, or if it falls under the limitations of AutoGraph or tf.v1 code compatibility. I would highly recommend watching the Inside TensorFlow talks about AutoGraph and Functions, not … Read more

How to use windows created by the Dataset.window() method in TensorFlow 2.0?

The solution is to call flat_map() like this: dataset = dataset.flat_map(lambda window: window.batch(5)) Now each item in the dataset is a window, so you can split it like this: dataset = dataset.map(lambda window: (window[:-1], window[-1:])) So the full code is: import tensorflow as tf dataset = tf.data.Dataset.from_tensor_slices(tf.range(10)) dataset = dataset.window(5, shift=1, drop_remainder=True) dataset = dataset.flat_map(lambda … Read more

ModuleNotFoundError: No module named ‘tensorflow_core.estimator’ for tensorflow 2.1.0

TL;DR: Just solved this issue by making sure that both tensorflow and tensorflow-estimator were in the same version. (in my case, I needed to downgrade tensorflow-estimator, so conda install tensorflow-estimator=2.1.0 solved it for me) As you may have noticed, some tensorflow versions do not play well with certain GPUs, so I would first check some … Read more

Running the Tensorflow 2.0 code gives ‘ValueError: tf.function-decorated function tried to create variables on non-first call’. What am I doing wrong?

As you are trying to use function decorator in TF 2.0, please enable run function eagerly by using below line after importing TensorFlow: tf.config.experimental_run_functions_eagerly(True) Since the above is deprecated(no longer experimental?), please use the following instead: tf.config.run_functions_eagerly(True) If you want to know more do refer to this link.

tech