tf.gradients()返回无

时间:2019-07-12 11:30:18

标签: python tensorflow

我正在尝试在一个玩具示例中实现integratedGradients。生成的数据和占位符定义如下:

x_pure = np.random.randint(-10,10,[10, 227, 227, 11])
y_test = np.sum(x_pure**2,axis=(1,2,3))

x = tf.placeholder(tf.float32, name='x_input', shape=[None, 227, 227, 11])
y = tf.placeholder(tf.float32, name='y_input', shape=[None,1])

此函数中发生损坏:

res = ig.build_ig(inter, stepsize, pred, num_steps=50)
# INPUT: samples: linearly interpolated samples between input samples and references. output of linear_interpolation()
#        stepsizse: output of linear_interpolation()
#        _output: output tensor to be explained. It needs to be connected to samples.
# OUTPUT: explanations: A list of tensors with explanation values. 

def build_ig(samples, stepsizes, _output, num_steps=50):
    grads = tf.gradients(ys=_output, xs=samples)

在调试器中:

_output=Tensor("Sum:0", shape=(?,), dtype=float32)
samples=Tensor("Reshape:0", shape=(?, 227, 227, 11), dtype=float32)
grads=<class 'list'>: [None]

由于tf.gradients()函数返回None,因此无法执行下一个操作。我什至应该从哪里开始寻找解决此错误的方法?

0 个答案:

没有答案