Questions tagged [gradienttape]
147 questions
1
vote
0 answers
Implementing Inverting Gradients [PDQN,MPDQN] in Tensorflow 2.7
I am trying to reimplement inverting gradients with gradienttape in tensorflow 2.7. In this example i use the pendulum domain which has an observation size of 3, action size of 1 and no discrete actions.
as shown in this paper:…

Unnamed
- 11
- 2
1
vote
1 answer
The below code is giving 'UnreadVariable' error in tensorflow
# importing libraries
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.losses import MSE
#…

Soumya Chakraborty
- 83
- 8
1
vote
0 answers
Customized regularization function with customized training in tf.keras (TF2) using GradientTape
I want to define my own customised regulizer and I am making use of GradientTape. I am making use of the following code, however no matter how large I choose the tuning parameters to be, the results always stay the same. Does someone know how I can…

user11453289
- 67
- 6
1
vote
1 answer
Custom loss function with Gradient Tape, TF2.6
I am trying to use a custom loss function in my Keras sequential model (TensorFlow 2.6.0). This custom loss (ideally) will calculate the data loss plus the residual of a physical equation (say, diffusion equation, Navier Stokes, etc.). This residual…

Milad S
- 23
- 4
1
vote
0 answers
Inputs to eager execution function cannot be Keras symbolic tensors, Custom loss function, Tensorflow 2, Gradient Tape
I am trying to use a custom loss function in my Keras model (TensorFlow 2). This custom loss (ideally) will calculate the data loss plus the residual of a physical equation (say, diffusion equation, Navier Stokes, etc.). This residual error is based…

Milad S
- 23
- 4
1
vote
0 answers
Modify gradients of a hidden layer and backpropagate modified gradients to find gradients of remaining layers
Consider a neural network with 2 hidden layers. I want to calculate gradients of parameters of 2nd hidden layer wrt loss, modify it and then use the modified gradients to backpropagate and find gradients of 1st hidden layer.
I am currently doing it…

ad28
- 251
- 3
- 7
1
vote
0 answers
ZeroDivisionError when getting gradients with Tensorflow ODE Solver?
I'm trying to implement a mechanistic model using TensorFlow which will be used as part of a GAN, based on the approach shown in this paper: https://arxiv.org/abs/2009.08267. I am using tensorflow 2.5.0 and tensorflow-probability 0.13.0.
The…

rihimetebmahk
- 41
- 1
- 3
1
vote
1 answer
Calculating gradients in Custom training loop, difference in performace TF vs Torch
I have attempted to translate pytorch implementation of a NN model which calculates forces and energies in molecular structures to TensorFlow. This needed a custom training loop and custom loss function so I implemented to different one step…

scosh_lr
- 11
- 5
1
vote
2 answers
tf.GradientTape() returns None value for my neural network function
So I created my own neural network and I want to do an automatic differentiation for it with respect to the input variable. My code for the neural network goes like this
n_input = 1
n_hidden_1 = 50
n_hidden_2 = 50
n_output = 1
weights =…

Helmi Aziz
- 25
- 4
1
vote
1 answer
Weights were not updated using Gradient Tape and apply_gradients()
I am building a DNN with a custom loss function and I am training this DNN using Gradient Tape in TensorFlow.kerasenter code here. The code runs without any errors, however, as far as I can check the weights of the DNN, the weights were not being…

sondv89
- 13
- 2
1
vote
1 answer
Gradient accumulation in tensorflow 2.x / keras
I'm trying to implement Gradient accumulation on TF2.x. All implementations I've found are either for TF1.x or for the old keras interface. I don't think there is an implementation out there (though I'd be very happy to be proven wrong on…

mbtg
- 95
- 1
- 8
1
vote
1 answer
Gradient are None for sliced input in TensorFlow
Following is my code
import tensorflow as tf
import numpy as np
def forward(x):
z = tf.Variable(tf.zeros_like(x), trainable=False)
s = tf.shape(x)[0]
for i in range(s):
z[i].assign(x[i]**i)
return z
a = tf.Variable(np.ones([5])*3)
with…

Lawhatre
- 1,302
- 2
- 10
- 28
1
vote
1 answer
tf.tape.gradient() returns None for my numerical function model
I'm trying to use tf.GradientTape().
But the problem is tape.gradientreturns None, so that the error output (TypeError : unsupported operand type(s) for *: 'float' and 'NoneType') popped up.
As you can see in my code, dloss_dparams =…

Yong KIM
- 11
- 3
1
vote
1 answer
Python, Tensorflow ValueError: No gradients provided for any variable
I have a class called RL_Brain:
class RL_Brain():
def __init__(self, n_features, n_action, memory_size=10, batch_size=32, gamma=0.9, fi_size=10):
self.n_features = n_features
self.n_actions = n_action
self.encoder =…

wang heng
- 15
- 5
1
vote
2 answers
GradientTape compute saliency in the loss function
I'm trying to build an LSTM network to classify sentences and provide explanation for the classification using saliency. This network must learn from the true class y_true as well as from which words he shouldn't pay attention Z (binary mask).
This…

Yoann
- 112
- 6