다음과 같이 선형 모델을 가지고 있으므로 W와 b와 관련하여 그라디언트 벡터를 얻고 싶습니다.tf.gradients가 TensorFlow에서 작동하는 방법
# tf Graph Input
X = tf.placeholder("float")
Y = tf.placeholder("float")
# Set model weights
W = tf.Variable(rng.randn(), name="weight")
b = tf.Variable(rng.randn(), name="bias")
# Construct a linear model
pred = tf.add(tf.mul(X, W), b)
# Mean squared error
cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples)
그러나 나는 비용이 cost(x,y,w,b)
의 함수 같은 것을 시도하고 나는 단지 w and b
에 대한 그라디언트하려면 다음
grads = tf.gradients(cost, tf.all_variable())
내 자리도 포함됩니다 (X 및 Y) . [x,y,w,b]
으로 그래디언트를 얻더라도 각 매개 변수에 속하는 요소가 그라디언트의 각 요소에 속하는지는 어떻게 알 수 있습니까? 매개 변수가 파생 된 이름이없는 목록 일 뿐이므로?
이 질문에서 나는이 code의 일부를 사용하고 있습니다. 나는 this 질문을 만들었습니다.
이것은 http://stats.stackexchange.com – Sentry
에 가야한다 @ 센트 나는 동의하지 않는다, 이것은 여기에 속한다. – Priyatham
@Priyatham 당신 말이 맞아요, 너무 성급했습니다 – Sentry