tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

tape.gradient computes none after model in model training

Open VictorvanWeelden opened this issue 2 years ago • 3 comments

Click to expand!

Issue Type

Bug

Have you reproduced the bug with TF nightly?

Yes

Source

source

Tensorflow Version

2.11.0

Custom Code

Yes

OS Platform and Distribution

No response

Mobile device

No response

Python version

3.8

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

grads = tape.gradient(class_channel, last_conv_layer_output) does produce NONE after performing first a regression on a "inner" model (trained and tested with MNIST and CIFAR10), before freezing the "inner" model network and then training a "outer" model over the "inner" model. After even unfreezing the "inner" model tape.gradient does not produce a result when asking for the final layer of the "inner" model as used in Grad-CAM.

Standalone code to reproduce the issue

The minimal code is in the link. Everything can be run, till the final cell where the bug is.

https://colab.research.google.com/drive/1HhFORTW3kQnsr0HMrk6Kl9brAguPvf_t?usp=sharing

Relevant log output

AttributeError                            Traceback (most recent call last)
<ipython-input-12-17e9c91a6483> in <module>
      4 print(class_channel.shape)
      5 grads = tape.gradient(class_channel, last_conv_layer_output)
----> 6 print(grads.shape)

AttributeError: 'NoneType' object has no attribute 'shape'

VictorvanWeelden avatar Feb 11 '23 17:02 VictorvanWeelden

can you put your code in detail to solve this issue?

Keyurbagadiya avatar Feb 12 '23 17:02 Keyurbagadiya

Hi, @VictorvanWeelden

Apologize for the delay and I was able to replicate the issue on Google colab with TF2.11 and also tried with pre release tensorflow 2.12.0rc0, I have added both gist files here tf-2.11 and tensorflow 2.12.0rc0 but I'm also getting the same error but with pre release tensorflow 2.12.0rc0 I noticed different error RuntimeError: A non-persistent GradientTape can only be used to compute one set of gradients (or jacobians) but it got resolved by passing persistent=True to with tf.GradientTape() so We will have to dig more into this issue and we will update soon here and thank you for noticing this issue. Thank you!

gaikwadrahul8 avatar Feb 16 '23 16:02 gaikwadrahul8

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] avatar Feb 23 '23 17:02 google-ml-butler[bot]

Hi, @VictorvanWeelden

Apologize for the delayed response and It seems like there is some issue while calculating the gradient and it's returning none so for your reference I have added one gist file which may be one of the reason for tape.gradient computes none after model in model training so could you please have a look into that gist-file and check whether is it resolving your issue ?, if not please let us know for investigation to find out root cause for your issue. Thank you!

gaikwadrahul8 avatar Mar 29 '23 08:03 gaikwadrahul8

This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Apr 06 '23 01:04 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.

github-actions[bot] avatar Apr 14 '23 01:04 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Apr 14 '23 01:04 google-ml-butler[bot]