Tensorflow 2. 0 自动求梯度
Tensorflow 自动求梯度
import tensorflow as tf
import timeit
a = tf.constant(1.)
b = tf.constant(2.)
c = tf.constant(3.)
w = tf.constant(4.)
with tf.GradientTape() as tape:
tape.watch([w])
y = a * w **2 + b *w +c
[dy_dw] = tape.gradient(y, [w])
print
原创
2020-11-27 14:57:21 ·
178 阅读 ·
0 评论