吴裕雄--天生自然TensorFlow2教程:梯度下降简介

吴裕雄--天生自然TensorFlow2教程:梯度下降简介

 

 吴裕雄--天生自然TensorFlow2教程:梯度下降简介

import tensorflow as tf

w = tf.constant(1.)
x = tf.constant(2.)
y = x * w
with tf.GradientTape() as tape:
    tape.watch([w])
    y2 = x * w

grad1 = tape.gradient(y, [w])
grad1
with tf.GradientTape() as tape:
    tape.watch([w])
    y2 = x * w

grad2 = tape.gradient(y2, [w])
grad2
try:
    grad2 = tape.gradient(y2, [w])
except Exception as e:
    print(e)

with tf.GradientTape(persistent=True) as tape:
    tape.watch([w])
    y2 = x * w
grad2 = tape.gradient(y2, [w])
grad2
with tf.GradientTape() as t1:
    with tf.GradientTape() as t2:
        y = x * w + b
    dy_dw, dy_db = t2.gradient(y, [w, b])

d2y_dw2 = t1.gradient(dy_dw, w)
上一篇:tensorflow2.x(一)


下一篇:外卖侠cps V5.6版本小程序源码_支持多种CPS收益和流量主收益