TensorArray中的切片和写入行为不符合预期

时间:2018-09-23 20:38:11

标签: python tensorflow

我当前正在调试问题,并将其简化为这两个// select all DOM elements of type 'input' with css class 'radio-2' that are checked! if ($('input.radio-2 :checked').size() > 0) { //call function 1 } else { //call function 2 } 循环,这些循环将输入张量的一部分切成小段并将其写入while。但是我得到的值从未在输入和切片中出现(例如TensorArray)。

这是一个最小的示例(在[[[900.]]]]tf.while_loop上有两个x):

y

我不确定是什么问题; def demo(input): # Shapes input_shape = tf.shape(input) i_height = input_shape[1] i_width = input_shape[2] i_c = input_shape[3] ta = tf.TensorArray(dtype=input.dtype, size=i_height*i_width) def body1(i, ta): x = tf.constant(0) condition2 = lambda x, i, result: tf.less(x, i_height) def body2(x, y, ta): sl = input[:, x:(x+1), y:(y+1)] return x + 1, y, ta.write(index = x * i_height + y, value = sl) x, i, ta = tf.while_loop(condition2, body2, loop_vars=[x, i, ta]) return i+1, ta y = tf.constant(0) condition1 = lambda y, result: tf.less(y, i_width) y, ta = tf.while_loop(condition1, body1, [y, ta]) return ta.stack() #return tf.reshape(ta.stack(), [-1, i_height, i_width, i_c]) HEIGHT = 10 WIDTH = 10 IN_CHANNELS = 1 with tf.Session() as sess: imgs = tf.placeholder(tf.float32, [None, HEIGHT, WIDTH, IN_CHANNELS], name="imgs") imgs_random = np.arange(10 * HEIGHT * WIDTH * IN_CHANNELS).reshape((10, HEIGHT, WIDTH, IN_CHANNELS)).astype('f') feed_dict={imgs: imgs_random} res = demo(imgs) sess.run(tf.global_variables_initializer()) value = sess.run(res, feed_dict=feed_dict)#, options=options, run_metadata=run_metadata) print("result", value.shape) print("value", value) print("rand", imgs_random[0]) 的文档非常缺乏。

0 个答案:

没有答案