在while循环中使用scatter_nd_add op?

时间:2017-09-22 19:39:34

标签: tensorflow

我正在尝试在tf.scatter_nd_add循环中执行tf.while。它给了我一个错误信息。

TypeError: 'ScatterNdAdd' Op requires that input 'ref' be a mutable tensor (e.g.: a tf.Variable)

似乎while循环的工作方式是将输入变量从类型tf.Variable更改为具有其他类型。是否可以在while循环中执行scatter_nd_add操作?

这是一段代码摘录:

self.hough = tf.Variable(tf.zeros((num_points, num_points), dtype=tf.float32),
                             name='hough')
self.i = tf.constant(0)
c = lambda i, hough: tf.less(i, tf.squeeze(tf.shape(self.img_x)))
b = lambda i, hough: self.ProcessPixel(i, hough)
self.r = tf.while_loop(c, b, [self.i, self.hough], back_prop=False)

这是循环的主体:

def ProcessPixel(self, i, hough):
        pixel_x, pixel_y = self.img_x[self.i], self.img_y[self.i]
        result = self.GetLinesThroughPixel(pixel_x, pixel_y)
        idx = tf.stack([tf.range(num_points, dtype=tf.int64), result])
        pixel_val = self.img[tf.to_int32(pixel_x), tf.to_int32(pixel_y)]

        print type(hough)
        updated_hough = tf.scatter_nd_add(hough, tf.transpose(idx),
                                          updates=pixel_val * tf.ones(num_points))

        return tf.add(i, 1), updated_hough

0 个答案:

没有答案
相关问题