如何在Tensorflow中处理GPU上的String Tensor?

时间:2017-04-06 01:07:18

标签: tensorflow

我想预处理一些数据作为Tensorflow的输入,但文件很大,我想Tensorflow可能会加速GPU上的这个过程。我在库中找到了一些String base的操作,但是,当我做一个简单的测试时,似乎Tensorflow不支持GPU上的操作,如果有人有想法在Tensorflow上处理GPU上的字符串数据或其他一些进展?现在,我想也许我必须在CUDA级别上这样做。

这是测试代码:

import tensorflow as tf
sess = tf.InteractiveSession()

with tf.device('/gpu:0'):
    text = tf.constant("aa a", name="LEFT")
    result = tf.string_split([text], delimiter=" ")
print result.eval()

和错误信息:

I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
Traceback (most recent call last):
  File "/media/freshield/BUFFER/LEARN_TENSORFLOW/11_tensorboard_graph/testing.py", line 51, in <module>
    print result.eval()
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/sparse_tensor.py", line 225, in eval
    session)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3797, in _eval_using_default_session
    return session.run(tensors, feed_dict)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 767, in run
    run_metadata_ptr)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 965, in _run
    feed_dict_string, options, run_metadata)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1015, in _do_run
    target_list, options, run_metadata)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1035, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device to node 'packed': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
     [[Node: packed = Pack[N=1, T=DT_STRING, axis=0, _device="/device:GPU:0"](LEFT)]]

Caused by op u'packed', defined at:
  File "/media/freshield/BUFFER/LEARN_TENSORFLOW/11_tensorboard_graph/testing.py", line 50, in <module>
    result = tf.string_split([text], delimiter=" ")
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/string_ops.py", line 104, in string_split
    source = ops.convert_to_tensor(source, dtype=dtypes.string)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 651, in convert_to_tensor
    as_ref=False)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 716, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 923, in _autopacking_conversion_function
    return _autopacking_helper(v, inferred_dtype, name or "packed")
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 886, in _autopacking_helper
    return gen_array_ops._pack(elems_as_tensors, name=scope)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2041, in _pack
    result = _op_def_lib.apply_op("Pack", values=values, axis=axis, name=name)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2395, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/freshield/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1264, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Cannot assign a device to node 'packed': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
     [[Node: packed = Pack[N=1, T=DT_STRING, axis=0, _device="/device:GPU:0"](LEFT)]]

0 个答案:

没有答案