Skip to content

Fix TensorFlow GradientTape example returning None due to tensor not …#284

Open
Lenakeiz wants to merge 1 commit intofchollet:masterfrom
Lenakeiz:fix-gradient-example
Open

Fix TensorFlow GradientTape example returning None due to tensor not …#284
Lenakeiz wants to merge 1 commit intofchollet:masterfrom
Lenakeiz:fix-gradient-example

Conversation

@Lenakeiz
Copy link

Fix incorrect TensorFlow GradientTape example in Chapter 2

The original example initializes x using tf.zeros(), which creates a Tensor that is not automatically watched by GradientTape. As a result, the gradient computation returns NoneType.

This PR add explicitly the scalar tensor to be watched so it can be tracked by te gradient. Alternatively the scalar tensor could have been initialised as tf.Variable(0.0) which are automatically tracked.

Tested with TensorFlow 2.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant