Python – tensorflow.GradientTape.stop_recording()
Last Updated :
20 Jan, 2022
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
stop_recording() is used to temporarily stop recording operation. If the Tape is not recording it will raise an error.
Syntax: tensorflow.GradientTape.stop_recording()
Parameters: It doesn’t accept any parameters.
Returns: None
Raises:
- RunTimeError: It will raise RunTimeError if tape is not recording currently.
Example 1:
Python3
import tensorflow as tf
x = tf.constant( 4.0 )
with tf.GradientTape() as gfg:
gfg.watch(x)
with gfg.stop_recording():
y = x * x * x
res = gfg.gradient(y, x)
print ( "res: " , res)
|
Output:
res: None
Example 2:
Python3
import tensorflow as tf
x = tf.constant( 4.0 )
with tf.GradientTape() as gfg:
gfg.watch(x)
with gfg.stop_recording():
y = x * x * x
gfg.watch(x)
y = x * x
res = gfg.gradient(y, x)
print ( "res: " , res)
|
Output:
res: tf.Tensor(8.0, shape=(), dtype=float32)
Share your thoughts in the comments
Please Login to comment...