Questions tagged [gradienttape]

147 questions
1
vote
0 answers

Python Tensorflow - how does GradientTape operate and why can it give None as a result?

Abstract I am trying to create a neural network with custom training. In my attempts I ended up with a ValueError: No gradients provided for any variable error. While trying to figure it out, I've found out that the problem appears because…
1
vote
1 answer

Can tf.gradienttape() calculate gradient of other library's function

If I include inside the tf.GradientTape() some functions from other Python libraries, like `sklearn.decomposition.PCA.inverse_transform()', can TensorFlow calculate gradients from that function? Specifically, can tf automatically differetiate…
1
vote
0 answers

Setting shape of RaggedTensor with Known Shape

I'm working with RaggedTensors to manipulate a dense tensor. Something like this : out_left = tf.ragged.boolean_mask(input, index) index = tf.math.logical_not(index) out_right = tf.ragged.boolean_mask(input, index) …
1
vote
0 answers

sampling within GradientTape

I am computing the different terms of the ELBO and its expectations to illustrate and get a better grasp of the reparametrization trick, as nicely explained here under undifferentiable expectations. As a simplified example in this journey, I have a…
1
vote
1 answer

Gradient Tape returns 0 for all weights

I am trying to reverse the output of LRP as heatmap back to model's weights. I have decieded to minimize the loss of the between the relevence of the untrained model weights and the desired heatmap relevence score so in theory it should make the…
1
vote
0 answers

tf.batch_jacobian Unexpected Behavior

import tensorflow as tf with tf.GradientTape() as g: x = tf.constant([[1., 2.], [3., 4.]], dtype=tf.float32) z = tf.constant([[5., 6., 3.], [7., 8., 4.]], dtype=tf.float32) g.watch(x) g.watch(z) y1 = x * x y2 = z * z y =…
AMIT SINGH
  • 21
  • 2
1
vote
1 answer

How to make predictions on new dataset with tensorflow's gradient tape

While I'm able to understand how to use model.fit(x_train, y_train), I can't figure out how to make predictions on new data using tensorflow's gradient tape. My github repository with runnable code (up to an error) can be found here. What is…
Relative0
  • 1,567
  • 4
  • 17
  • 23
1
vote
0 answers

Tensorflow 2: Error computing gradients from a list of tf.Variables

What's wrong with the code below ? vars = [tf.Variable(0.0), tf.Variable(1.0)] with tf.GradientTape() as g: y = tf.reduce_mean(tf.concat(vars,axis=0)) grads = g.gradient(y, vars) The above gives error : "ZeroDivisionError: integer division or…
anksh
  • 35
  • 7
1
vote
0 answers

Is the number of uses of 'gradient' in GradientTape limited?

I'm trying to solve the following problems : So, I tried by using tf.GradientTape 4 times. The following is my code : import tensorflow as tf import matplotlib.pyplot as plt import numpy as np import math from scipy import io…
HJ_Kwon
  • 11
  • 2
1
vote
1 answer

GradientTape for variable weighted sum of two Sequential models in TensorFlow

Suppose we want to minimize the following equation using gradient descent: min f(alpha * v + (1-alpha)*w) with v and w the model weights and alpha the weight, between 0 and 1, for the sum resulting in the combined model v_bar or ū (here referred to…
1
vote
1 answer

Negative gradients when calculating GradCAM heatmap

I have a Segmentation network model trained for 2 classes and am able to see accurate results. But when using grad-cam for the heatmap, I am able to see good results for the last convolution layer for both the classes but having issues when trying…
1
vote
1 answer

How can I calculate gradients of each element in a tensor using GradientTape?

I would like to calculate the gradient of each element in a tensor with respect to a list of watched tensors. When I use GradientTape's gradient() on y directly, the resulting dy_dx has the dimension of my x. For example: x = [ tf.constant(3.0),…
Morten Grum
  • 962
  • 1
  • 10
  • 25
1
vote
1 answer

Tensorflow Gradient tape 'unknown value for unconnected gradients'

I'm trying to understand why im getting an error when using gradient tape to take the derivative of a function. Try to take the derivative of Power with respect to T, defined as: import tensorflow as tf import numpy as np from scipy.fft…
J Crane
  • 11
  • 2
1
vote
1 answer

In a GAN with custom training loop, how can I train the discriminator more times than the generator (such as in WGAN) in tensorflow

I'm working in a code based on the [Pix2Pix tensorflow tutorial][tutorial] and I'm trying to follow the Wasserstein GAN (WGAN) requirements: (a) weight clipping, (b) linear activation for the discriminator, (c) Wasserstein loss, and (d) training the…
fegemo
  • 2,475
  • 6
  • 20
  • 40
1
vote
1 answer

tensorflow: Obtain RNN hidden states gradients with respect to input

My model consists of an Embedding layer and a SimpleRNN layer. I have obtained the hidden states at all steps with model.predict, and plotted them against the steps. I find that the hidden states converge to zero but I am not sure if I can infer…
1 2
3
9 10