是否可以将错误传播给占位符?我需要修复模型的参数,只将错误传播给占位符。占位符具有迷你批量向量,批量大小未知。
编辑:(使用@Alexandre Passos建议的tf.gradient)
import tensorflow as tf
import numpy as np
X = tf.placeholder('float', shape=[None, 100])
Z = tf.constant(list(range(100,200)), dtype='float')
cost = tf.reduce_mean(tf.square(X - Z))
grad = tf.gradients(cost, X)
appl = X - tf.multiply(grad[0], 1)
with tf.Session() as sess:
x0 = np.random.normal(size=[2,100])
for _ in range(500):
x0,c = sess.run([appl, cost], feed_dict={X:x0})
print(c)
print(x0)
答案 0 :(得分:0)
是的,tf.gradients
允许您传递您喜欢的任何Tensor
作为要区分的变量。