Tensorflow:通过网络组合的渐变

时间:2017-08-03 15:07:21

标签: python tensorflow

假设我们有两个独立的CNN A(x)B(z)并在 Tensorflow 中定义其组成B(A(x))

x = tf.placeholder(tf.float32, shape)
A = CNN1.inference(x)
B = CNN2.inference(A)
y = tf.nn.softmax(B)

现在我们想要一些输出神经元dy/dx的衍生j并写:

dy = tf.gradients(y[j], x)[0]

这会正确计算渐变吗?

让我们从x空间中的随机点开始在X上执行渐变上升:

x_val = np.random.normal(shape)
for _ in range(100):
    x_val += sess.run(dy, feed_dict={x: x_val})

此循环是否实际上正确执行渐变上升?

0 个答案:

没有答案