Questions tagged [gradienttape]
147 questions
0
votes
1 answer
Model not improving with GradientTape but with model.fit()
I am currently trying to train a model using tf.GradientTape, as model.fit(...) from keras will not be able to handle my data input in the future. However, while a test run with model.fit(...) and my model works perfectly, tf.GradientTape does…

Matteo Pilz
- 11
- 2
0
votes
1 answer
Declaring Variables inside the Tensorflow GradientTape
I have a model with a complex loss, computed per class of the model output.
As you can see below, I'm computing the loss with some custom loss function, assigning this value to the variable, as tensor are immutable in tensorflow.
def…

Spivakoa
- 11
- 4
0
votes
1 answer
Calculate gradients of variables used in assignment of other variable using tf.GradientTape
How can one calculate the gradient on a variable with respect to another variable used in a linear combination? The following code is executed in TensorFlow eager mode.
Some more digging in older questions, a similar question showed up. However, it…

user19087072
- 13
- 4
0
votes
1 answer
Varational autoencoder using tf.GradientTape
Here is an example of tensorflow GradientTape provided by keras for a typical variotional autoencoder:
VAE-keras-example
The train_step function is implemented inside the model and it is trained with the "model.fit()". The example performs great and…

ir0098
- 127
- 1
- 13
0
votes
1 answer
Tensorflow Gradient Tape returns null
I'm trying to compute gradients using Gradient Tape in tensorflow.
Description -
A - tf.constant
X - tf.Variable
Y - tf.Variable
Functions
get_regularization_loss - computes the L1/L2 penalty
construct_loss_function - computes the…

kaiser
- 948
- 8
- 11
0
votes
0 answers
Trying to learn deep kernel with tensorflow, getting 'ValueError: No gradients provided for any variable' error
Hi stack overflow community,
I am fairly new to tensorflow and programming, hence there may be obvious errors I just overlook.
My dev environment consists of vs code running in a tensorflow docker container + venv (tf 2.5.3, python 3.8.10) running…

NIG-ITPS
- 1
- 1
0
votes
1 answer
Gradient tape is not giving gradient as expected
I am trying to find the gradient of a simple model where the output is a concatenated vector. But gradient tape is returning a scalar value instead of a vector. I am attaching my code here.
p0=tf.keras.Input(shape=(1,1), name="p0")
X0 =…

Nab
- 1
0
votes
0 answers
Correct way to take gradients in tensorflow?
I am trying to use a new NN architecture named Physics Informed Neural Networks, the aim is to solve a PDE or ODE using NN. So I have to take the derivative of my network with respect to the data, as in the u_prima function below, and then with…

Rosendo Ocaña
- 33
- 4
0
votes
1 answer
how to Edit the GradientTape function in the keras source code
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/eager/backprop.py#L994-L1095 here is the source code for the 'GradientTape' function, however making changes in the source code does not affect the function in the subsequent…
0
votes
1 answer
Keras GradientType: Calculating gradients with respect to the output node
For startes: this question does not ask for help regarding reinforcement learning (RL), RL is only used as an example.
The Keras documentation contains an example actor-critic reinforcement learning implementation using Gradient Tape. Basically,…

CLRW97
- 470
- 4
- 15
0
votes
1 answer
Tape gradient gives wrong output
I am trying to compute gradient using tape.gradient() but it gives me wrong answer. The error is in the lines u_z=tape.gradient(u,z,unconnected_gradients=tf.UnconnectedGradients.ZERO) and two lines that follow it from below code. The function u is…

ForumWhiner
- 121
- 1
- 9
0
votes
1 answer
Extract the value of a Tensorflow/Keras GradientTape gradient of a variable
In short: I have a custom loss layer in Tensorflow/Keras 2+, which implements a loss function involving two variables, which also go through minimization. And it works, as can be seen below. I wish to track the loss gradients with respect to these…

Giora Simchoni
- 3,487
- 3
- 34
- 72
0
votes
0 answers
In Gradient Tape Tensorflow gradients are coming as 0.s
Here is part of a model I am working. Being new in calculation gradients in tf, I got confused when I found all the gradient values are coming as 0. Here is the code:
class A:
def __init__(self, inputA_dim, inputB_dim):
self.inputA_dim =…

MAN-MADE
- 187
- 7
0
votes
1 answer
Tensorflow gradient tape calculation
I am trying to understand the purpose of TF GRADIENT TAPE, in the following code:
import tensorflow as tf
var = tf.Variable(5.0)
with tf.GradientTape() as tape:
op = (2*var)+(var*var)
diff = tape.gradient(op,var)
print (diff)
Op:
diff =…

data_person
- 4,194
- 7
- 40
- 75
0
votes
1 answer
Calling __exit_ after GradientTape(persistent=True)
I start recording the gradients with tf.GradientTape(persistent=True) in order be able to call gradient_tape.gradient() more than one time. Since this means that the gradients are not being released after calling the gradient() method, do I have to…

anut
- 1