Questions tagged [eager-execution]

TensorFlow's eager execution is an imperative programming environment that evaluates operations immediately, without building graphs: operations return concrete values instead of constructing a computational graph to run later. This makes it easy to get started with TensorFlow and debug models, and it reduces boilerplate as well. To follow along with this guide, run the code samples below in an interactive python interpreter.

146 questions
2
votes
2 answers

How to convert model in eager execution to static graph and save in .pb file?

Imagine that I have model (tf.keras.Model): class ContextExtractor(tf.keras.Model): def __init__(self): super().__init__() self.model = self.__get_model() def call(self, x, training=False, **kwargs): features =…
2
votes
0 answers

How to obtain second derivatives of a Loss function with respect to the parameters of a neural network using gradient tape in Tensorflow eager mode

I am creating a basic auto-encoder for the MNIST dataset using TensorFlow eager mode. I would like to observe the second-order partial derivatives of my loss function with respect to the parameters of the network as it trains. Currently, calling…
Devon Jarvis
  • 118
  • 8
2
votes
0 answers

How to eval model with batch_size=1 and use trained parameters for BatchNorm rather than InstanceNorm?

When I run my model(training=False) with batch_size = 2, model uses trained parameters for BatchNorm, but when I run model with batch_size = 1, my model don't use trained parameters and do InstanceNorm in fact. How can I run model with batch_size =…
2
votes
1 answer

AttributeError: object has no attribute '_lazy_read'

I am using python 3 with tensorflow 1.12 & eager eval I am trying to use scatter update as explained here I am getting the following error: AttributeError: 'EagerTensor' object has no attribute '_lazy_read' Is there a workaround or another…
2
votes
0 answers

Manually access and update trainable variables from keras model when eager execution is enabled

How does one access and update trainable variables when using eager execution and a keras sequential model? I see some code in the tf optimizer that seems to handle both graph mode and eager execution, but it's really hard for me to follow. I'd…
user3496060
  • 800
  • 10
  • 20
2
votes
1 answer

Difference between tf.train.Checkpoint and tf.train.Saver

I found there are different ways to save/restore models and variables in Tensorflow. These ways including: tf.saved_model.simple_save tf.train.Checkpoint tf.train.Saver In tensorflow's documentations, I found some differences between…
Amir
  • 16,067
  • 10
  • 80
  • 119
1
vote
1 answer

Keras LSTM - looping over variable sequence length

I want to manually loop over the varying sequence lengths of the input sequences but Tensorflow automatically makes the time axis to None after noticing varying sequence lengths. Is there any work around for this? Sample example import tensorflow as…
Vigneswaran C
  • 461
  • 3
  • 14
1
vote
1 answer

tensorflow.py_function fails to temporarily switch to eager execution while in graph mode

I'm not sure if this is a Tensorflow bug or my misunderstanding about what this function is supposed to do, but I can't get tf.py_function to return an EagerTensor while in graph mode. Consequently, calling .numpy() on the output of this function…
42bsk
  • 76
  • 1
  • 10
1
vote
0 answers

Tensorflow access tensor.numpy() in .map function but using py_function slows down iterator generation

I want to one hot encoder a tensor with my own one hot encoder. For this, I have to call tf.keras.backend.get_value() in .map which is only possible when using tf.py_function: def one_hot_encode(categories,input): encoded_input = [] data =…
Quasi
  • 576
  • 4
  • 13
1
vote
1 answer

Module 'tensorflow' has no attribute 'enable_eager_execution' - with TensorFlow 2.6

I have TensorFlow 2.6 installed with Python 3.9. However, I get the following errors: tf.enable_eager_execution() AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution' When I run tf.executing_eagerly() I get False. I…
Steve
  • 129
  • 1
  • 14
1
vote
0 answers

TensorFlow 2.0: Unable to train subclass model with custom fit in graph mode

The code snippet below is a vanila implementation of a TensorFlow model in which I am using subclass model and a custom fit function (implemented through train_step and test_step). The code works fine in the eager execution mode (default mode of…
1
vote
0 answers

run_eagerly=True make the training result different in Tensorflow 2.3.2

Recently I come across a strange question in Running Neural network code on TensorFlow 2.3.2. The question is that when I only changed run_eagerly=True to run_eagerly=False in the config model.compile( loss={"label": "binary_crossentropy"}, …
blisslee
  • 9
  • 2
1
vote
0 answers

Defining a callable "loss" function

I am trying to optimize a loss function (defined using evidence lower bound) with tf.train.AdamOptimizer.minimize() on Tensorflow version 1.15.2 with eager execution enabled. I tried the following: learning_rate = 0.01 optim =…
1
vote
0 answers

tf.placeholder() is not compatible with eager execution

I am working on a project and am trying to replace this block of code with something that works. I am using version 2.5.0 of tensorflow and am faced with the following error. AttributeError: module 'tensorflow' has no attribute 'placeholder' When…
1
vote
0 answers

LSTM nan loss in tensorflow

I have a classification model with LSTMs to process sequential data. It trains perfectly when I enable eager mode by this command; tf.config.experimental_run_functions_eagerly(True) When I turned it off, the model computes the loss in the first…
maktukmak
  • 11
  • 1