未指定索引的分割张量

时间:2019-07-11 11:58:03

标签: python tensorflow

我正在尝试使用tf.split()函数用某些索引分割张量。

这是tensorflow 1.8版本

python张量流代码

feature_context = <tf.Tensor 'concat:0' shape=(8, 32, ?, 65) dtype=float32>
boundary_logit = <tf.Tensor 'Cast_32:0' shape=(8, ?) dtype=bool>
boundary_index = <tf.Tensor 'Where:0' shape=(?, 2) dtype=int64>

我知道了

Traceback (most recent call last):
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/pydevd.py", line 1758, in <module>
    main()
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/pydevd.py", line 1752, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/pydevd.py", line 1147, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/media/jw/E/scenetext/from_hancom/train_Union.py", line 157, in <module>
    tf.app.run()
  File "/home/jw/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/media/jw/E/scenetext/from_hancom/train_Union.py", line 106, in main
    char_features = tf.split(feature_context, boundary_index, 1)
  File "/home/jw/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1322, in split
    raise ValueError("Cannot infer num from shape %s" % num_or_size_splits)
ValueError: Cannot infer num from shape Tensor("Where:0", shape=(?, 2), dtype=int64)

我想按boundary_index对批处理中的每个要素拆分feature_context。因此,我想要一个具有shape(32,?,65)的张量列表。但是char_features行显示错误消息

boundary_logit = tf.to_int32(boundary_logit > threshold)
boundary_logit = tf.cast(boundary_logit, tf.bool)

boundary_logit = tf.split(boundary_logit, FLAGS.batch_size, axis=0)

for i in range(FLAGS.batch_size):
    boundary_index = tf.where(boundary_logit[i])
    char_features = tf.split(feature_context[i], boundary_index[:, i], 1)

我也尝试过

Traceback (most recent call last):
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/pydevd.py", line 1758, in <module>
    main()
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/pydevd.py", line 1752, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/pydevd.py", line 1147, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/jw/pycharm-2019.1.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/media/jw/E/scenetext/from_hancom/train_Union.py", line 160, in <module>
    tf.app.run()
  File "/home/jw/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/media/jw/E/scenetext/from_hancom/train_Union.py", line 109, in main
    char_features = tf.split(feature_context[i], boundary_index[:, i], 1)
  File "/home/jw/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1322, in split
    raise ValueError("Cannot infer num from shape %s" % num_or_size_splits)
ValueError: Cannot infer num from shape Tensor("strided_slice_1:0", shape=(?,), dtype=int64)

但是在这里,我收到了错误消息

{{1}}

有什么方法可以在训练时间内为每个批次更改具有动态形状的张量吗?

0 个答案:

没有答案