'使用输入dim 0指数超出范围'使用'tf.while_loop'时出错

时间:2018-01-23 02:50:15

标签: python tensorflow rnn

使用tf.while_loop创建解码器时遇到此问题

train_decoder = tf.while_loop(self.coarse_decoder_condition, self.coarse_decoder_function,
[self.iter_decoder_c, tf.zeros([1,self.c_dec_size]), tf.ones([self.c_dec_size])] ,\
shape_invariants=[self.iter_decoder_c.get_shape(),\
tf.TensorShape([None,self.c_dec_size]),\
tf.TensorShape([self.c_dec_size]) ] )

这是cmd中出现的内容

```

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2816, in while_loop
    result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2640, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2576, in _BuildLoop
    c = ops.convert_to_tensor(pred(*packed_vars))

  File "C:\Users\HP\Music\Final\nn.py", line 200, in coarse_decoder_condition
    return it[0] < self.oplen_c[0]

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\array_ops.py", line 538, in _SliceHelper
    name=name)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\array_ops.py", line 706, in strided_slice
    shrink_axis_mask=shrink_axis_mask)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 5429, in strided_slice
    name=name)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-
packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_he
lper
    op_def=op_def)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2958, in create_op
    set_shapes_for_outputs(ret)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2209, in set_shapes_for_outputs

    shapes = shape_func(op)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2159, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shap
e_fn
    require_shape_fn)

  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 691, in _call_cpp_sha
pe_fn_impl
    raise ValueError(err.message)
ValueError: Index out of range using input dim 0; input has only 0 dims for 'Coarse_Decoder/while/strided_slice' (op: 'StridedSlice') with input shape
s: [], [1], [1], [1] and with computed input tensors: input[3] = <1>.

```

基本上发生的是while_loop =&gt; buildloop =&gt; _SliceHelper

_sliceHelper选择strided_slice op(需要4个args而不是3个)而不仅仅是slice op

这导致我在传递3个args时出错,这就是我的要求。

类似的问题突出显示here

我无法在strided_slice()

上手动选择slice()

任何帮助将不胜感激

0 个答案:

没有答案