tensorflow-gpu2.0の自動派生

輸入TFとしてtensorflow
 「」」
グラデーション:デリバティブや偏微分
点での誘導体点(A、B、C、W)=(1,2,3,4):誘導体のどの時点で1
2.環境勾配
    派生誰に:ワットの導出
    関数:Y = ** 2 + B * W + C W *

上記の3件の必要な情報が自動的誘導体であります
'' ' 
#1どのような派生ポイント、ポイントを作成テンソル 
A = tf.constant(1 )。
B = tf.constant(3 )。
C = tf.constant(6 )。
W(2 = tf.constant 。)
#2誘導体環境、誘導体誰に 
tf.GradientTape(と)テープAS: #建設環境命じられる 
    ([W])tape.watchを              #1 、Wの#誘導体[W] 
    Y = A * ** W 2 C + W + B *             #機能#誘導体 
[dy_dw] = tape.gradient(Y、[W])
 プリント(dy_dw)

输出:tf.Tensor(7.0、形状=()、DTYPE =のfloat32)

説明:

1.定数を作成します(テンソル)の使用tf.constant

2.剃髪環境:tf.GradientTape()

3.デリバティブ:tape.watch([W])

おすすめ

転載: www.cnblogs.com/liuhuacai/p/12329188.html