Python – tensorflow.GradientTape.stop_recording()
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
# Importing the library import tensorflow as tf x = tf.constant( 4.0 ) # Using GradientTape with tf.GradientTape() as gfg: gfg.watch(x) # Stop recording with gfg.stop_recording(): y = x * x * x # Computing gradient res = gfg.gradient(y, x) # Printing result print ( "res: " , res) |
Output:
res: None
Example 2:
Python3
# Importing the library import tensorflow as tf x = tf.constant( 4.0 ) # Using GradientTape with tf.GradientTape() as gfg: gfg.watch(x) # Stop recording with gfg.stop_recording(): y = x * x * x # Starting the recording again gfg.watch(x) y = x * x # Computing gradient res = gfg.gradient(y, x) # Printing result print ( "res: " , res) |
Output:
res: tf.Tensor(8.0, shape=(), dtype=float32)