TensorFlow是Google设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
stop_recording()用于暂时停止记录操作。如果磁带未在录制,则会引发错误。
用法:tensorflow.GradientTape.stop_recording()
参数:它不接受任何参数。
返回:空
raise :
- RunTimeError:如果磁带没有及时录制,它将引发RunTimeError。
范例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)
输出:
res: None
范例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)
输出:
res: tf.Tensor(8.0, shape=(), dtype=float32)
相关用法
注:本文由纯净天空筛选整理自aman neekhara大神的英文原创作品 Python – tensorflow.GradientTape.stop_recording()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。