print("\ncomputed 1")
x=tfe.Variable(np.random.uniform(size=[166,]), name='x', dtype=tf.float64)
print(compute_cost(tf.constant(normed_data[:10], dtype=tf.float64), x))
print("\ncomputed 2")
x=tfe.Variable(np.random.uniform(size=[166,]), name='x', dtype=tf.float64)
print(compute_cost(tf.constant(normed_data[:10], dtype=tf.float64), x))
print("\ncomputed 0")
x=tfe.Variable(np.zeros((166,)), name='x', dtype=tf.float64)
print(compute_cost(tf.constant(normed_data[:10], dtype=tf.float64), x))
print("\ncomputed 0")
x=tfe.Variable(np.zeros((166,)), name='x', dtype=tf.float64)
print(compute_cost(tf.constant(normed_data[:10], dtype=tf.float64), x))
输出:
computed 1
tf.Tensor(0.00627350861776064, shape=(), dtype=float64)
computed 2
tf.Tensor(0.0032756996843633264, shape=(), dtype=float64)
computed 0
tf.Tensor(19.318829784931626, shape=(), dtype=float64)
computed 0
tf.Tensor(19.318829784931626, shape=(), dtype=float64)
显然tfe.变量x影响损失函数,所以梯度不应该是无/0。然而它是。。。你知道吗
x=tfe.Variable(np.random.uniform(size=[166,]), name='x', dtype=tf.float64)
f_grad = tfe.gradients_function(lambda s: compute_cost(tf.constant(normed_data[:10], dtype=tf.float64), s), params=['s'])
print("\nGradient " + str(f_grad(x)))
输出:
Gradient [None]
有人能解释怎么了吗?使用Tensorflow 1.10.1和急切执行。你知道吗
返回值
None
表示函数的输出和变量之间没有依赖关系。你知道吗查看链接到的}) in there ,它将打破可微操作的“跟踪”。请注意,TensorFlow只能通过TensorFlow操作计算梯度。你知道吗
compute_cost
函数I see a numpy operation (^{与your other question类似,将numpy操作替换为相应的TensorFlow操作(^{} )应该可以做到这一点。你知道吗
希望有帮助。你知道吗
相关问题 更多 >
编程相关推荐