【发布时间】:2018-07-03 04:17:45
【问题描述】:
我更改了我的问题以更好地解释我的问题:
我有一个函数:output_image = my_dunc(x) x 应该是 (1, 4, 4, 1)
请帮我修复这部分的错误:
out = tf.Variable(tf.zeros([1, 4, 4, 3]))
index = tf.constant(0)
def condition(index):
return tf.less(index, tf.subtract(tf.shape(x)[3], 1))
def body(index):
out[:, :, :, index].assign(my_func(x[:, :, :, index]))
return tf.add(index, 1), out
out = tf.while_loop(condition, body, [index])
ValueError:这两个结构没有相同的嵌套结构。
第一个结构:type=list str=[]
第二种结构:type=list str=[<tf.Tensor 'while_10/Add_3:0' shape=() dtype=int32>, <tf.Variable 'Variable_2:0' shape=(1, 4, 4, 3) dtype=float32_ref>]
更具体地说:这两个结构没有相同数量的元素。第一个结构:type=list str=[<tf.Tensor 'while_10/Identity:0' shape=() dtype=int32>]。第二种结构:type=list str=[<tf.Tensor 'while_10/Add_3:0' shape=() dtype=int32>, <tf.Variable 'Variable_2:0' shape=(1, 4, 4, 3) dtype=float32_ref>]
我测试了我的代码,我可以从 out = my_func(x[:, :, :, i]) 获得不同的 i 值的结果,当我评论 out[:, :, :, index].assign(my_func(x[:, :, :, index])) 行时,while_loop 也可以工作。那行有问题。
【问题讨论】:
-
请澄清。你想如何组合 x 的通道?
-
对于组合,我想将它们连接起来。我的意思是我将拥有 3 个 (1, 4, 4, 1),我需要拥有一个 (1, 4, 4, 3)。我不确定,但我认为在 keras 中使用连接运算符是可能的。
-
你能回答我编辑的问题吗
标签: tensorflow tensorflow-serving tensorflow-estimator