未实现的错误:TensorArray的大小为零

时间:2017-05-01 00:43:52

标签: tensorflow

在尝试训练序列到张量流中的序列模型时,我遇到了这个奇怪的错误。序列模型的序列是视频字幕系统。我已经在SequenceExampleProto的序列特征中编码了视频的帧。在我预取包含jpeg编码字符串列表的功能后,我使用以下函数解码它们:

video = tf.map_fn(lambda x: tf.image.decode_jpeg(x, channels=3), encoded_video, dtype=tf.uint8)

模型编译但在训练期间,我收到以下由此代码引起的错误。错误表示TensorArray为零,而TensorArray不应为零。任何帮助表示赞赏:

tensorflow.python.framework.errors_impl.UnimplementedError: TensorArray has size zero, but element shape [?,?,3] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
     [[Node: input_fn/decode/map/TensorArrayStack/TensorArrayGatherV3 = TensorArrayGatherV3[_class=["loc:@input_fn/decode/map/TensorArray_1"], dtype=DT_UINT8, element_shape=[?,?,3], _device="/job:localhost/replica:0/task:0/cpu:0"](input_fn/decode/map/TensorArray_1, input_fn/decode/map/TensorArrayStack/range, input_fn/decode/map/while/Exit_1/_479)]]

Caused by op u'input_fn/decode/map/TensorArrayStack/TensorArrayGatherV3', defined at:
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/ubuntu/ASLNet/seq2seq/bin/train.py", line 277, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "/home/ubuntu/ASLNet/seq2seq/bin/train.py", line 272, in main
    schedule=FLAGS.schedule)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/learn_runner.py", line 111, in run
    return _execute_schedule(experiment, schedule)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/learn_runner.py", line 46, in _execute_schedule
    return task()
  File "seq2seq/contrib/experiment.py", line 104, in continuous_train_and_eval
    monitors=self._train_monitors)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py", line 281, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 430, in fit
    loss = self._train_model(input_fn=input_fn, hooks=hooks)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 925, in _train_model
    features, labels = input_fn()
  File "seq2seq/training/utils.py", line 274, in input_fn
    frame_format="jpeg")
  File "seq2seq/training/utils.py", line 365, in process_video
    video = tf.map_fn(lambda x: tf.image.decode_jpeg(x, channels=3), encoded_video, dtype=tf.uint8)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/functional_ops.py", line 390, in map_fn
    results_flat = [r.stack() for r in r_a]
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/tensor_array_ops.py", line 301, in stack
    return self.gather(math_ops.range(0, self.size()), name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/tensor_array_ops.py", line 328, in gather
    element_shape=element_shape)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 2244, in _tensor_array_gather_v3
    element_shape=element_shape, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
    self._traceback = _extract_stack()

UnimplementedError (see above for traceback): TensorArray has size zero, but element shape [?,?,3] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
     [[Node: input_fn/decode/map/TensorArrayStack/TensorArrayGatherV3 = TensorArrayGatherV3[_class=["loc:@input_fn/decode/map/TensorArray_1"], dtype=DT_UINT8, element_shape=[?,?,3], _device="/job:localhost/replica:0/task:0/cpu:0"](input_fn/decode/map/TensorArray_1, input_fn/decode/map/TensorArrayStack/range, input_fn/decode/map/while/Exit_1/_479)]]

1 个答案:

答案 0 :(得分:0)

固定。我按照tensorflow map_fn TensorArray has inconsistent shapes的建议执行了以下操作:

with tf.name_scope("decode", values=[encoded_video]):
    input_jpeg_strings = tf.TensorArray(tf.string, video_length)
    input_jpeg_strings = input_jpeg_strings.unstack(encoded_video)
    init_array = tf.TensorArray(tf.float32, size=video_length)

    def cond(i, ta):
        return tf.less(i, video_length)

    def body(i, ta):
        image = input_jpeg_strings.read(i)
        image = tf.image.decode_jpeg(image, 3, name='decode_image')
        image = tf.image.convert_image_dtype(image, dtype=tf.float32)
        assert (resize_height > 0) == (resize_width > 0)
        image = tf.image.resize_images(image, size=[resize_height, resize_width], method=tf.image.ResizeMethod.BILINEAR)
        return i + 1, ta.write(i, image)

    _, input_image = tf.while_loop(cond, body, [0, init_array])