Tensorflow의 매개 변수 행렬 "X"에 대한 텐서 "Y"의 그래디언트를 계산하고 싶습니다. 특히, "X"의 "인덱스"집합에 대해서만 그라디언트를 계산하려고합니다. I는 다음에 기초하여 상기 파라미터 매트릭스 "X"의 원하는 인덱스를 업데이트 할 수 Tensorflow의 "tf.scatter_sub 사용"Tensorflow의 "tf.gather"와 "tf.gradients"를 함께 사용하십시오.
Y=some_function_of_X
grad=tf.gradients(Y,X)
grads_i_want_to_compute=tf.gather(grad,indices)
를 다음 코드는 원하는 인덱스에 대응하는 그 기울기를 반환 제 전체 기울기를 계산 그래디언트 강하 :
tf.scatter_sub(X,indices,learning_rate*grads_i_want_to_compute)
이 작업은 제대로 작동하지만 모든 시간 변화가 계산됩니다. 처리 속도를 위해서 모든 그라데이션을 계산하고 싶지는 않습니다. 그래서 이것을 시도 :
Y=some_function_of_X
sparse_X=tf.gather(X,indices)
grads_i_want_to_compute = tf.gradient(Y,sparse_X)
tf.scatter_sub(X,indices,learning_rate*grads_i_want_to_compute)
후자에서 "tf.gradient"는 "None"개체를 반환하므로 처리 할 수 없습니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까?