tensorflow:将错误传播到占位符

时间:2017-04-12 03:16:50

标签: tensorflow

是否可以将错误传播给占位符?我需要修复模型的参数,只将错误传播给占位符。占位符具有迷你批量向量,批量大小未知。

编辑:(使用@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)

1 个答案:

答案 0 :(得分:0)

是的,tf.gradients允许您传递您喜欢的任何Tensor作为要区分的变量。