如何在Tensorflow中的GPU上处理字符串张量?

如何在Tensorflow中的GPU上处理字符串张量?,tensorflow,Tensorflow,我想预处理一些数据作为Tensorflow的输入,但是文件太大了,我想Tensorflow可以在GPU上加速这个过程。我在库中找到了一些字符串库的操作,但是,当我做一个简单的测试时,Tensorflow似乎不支持GPU上的操作,如果有人有一些想法,可以在Tensorflow或其他先进的GPU上处理字符串数据?现在,我只是想也许我必须在CUDA级别上做这件事 以下是测试代码: import tensorflow as tf sess = tf.InteractiveSession() with

我想预处理一些数据作为Tensorflow的输入,但是文件太大了,我想Tensorflow可以在GPU上加速这个过程。我在库中找到了一些字符串库的操作,但是,当我做一个简单的测试时,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)]]
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975]创建tensorflow设备(/gpu:0)->(设备:0,名称:GeForce GTX 1070,pci总线id:0000:01:00.0)
回溯(最近一次呼叫最后一次):
文件“/media/freshfield/BUFFER/LEARN_TENSORFLOW/11_tensorboard_graph/testing.py”,第51行,输入
打印结果。eval()
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/framework/sparse_tensor.py”,第225行,评估中
(会议)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/framework/ops.py”,第3797行,使用默认会话进行评估
返回会话。运行(张量、提要)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/client/session.py”,第767行,正在运行
运行_元数据_ptr)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/client/session.py”,第965行,正在运行
提要(dict字符串、选项、运行元数据)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/client/session.py”,第1015行,在运行中
目标\u列表、选项、运行\u元数据)
文件“/home/freshfield/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py”,第1035行,在
提升类型(e)(节点定义、操作、消息)
tensorflow.python.framework.errors\u impl.InvalidArgumentError:无法将设备分配给节点“打包”:无法满足显式设备规范“/device:GPU:0”,因为没有支持的GPU设备内核可用。
[[Node:packed=Pack[N=1,T=DT_字符串,axis=0,_device=“/device:GPU:0”](左)]]
由op u“打包”引起,定义为:
文件“/media/freshfield/BUFFER/LEARN_TENSORFLOW/11_tensorboard_graph/testing.py”,第50行,输入
结果=tf.string_split([文本],分隔符=)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/ops/string_ops.py”,第104行,字符串分割
source=ops.convert_to_tensor(source,dtype=dtypes.string)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/framework/ops.py”,第651行,转换为tensor
as_ref=False)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/framework/ops.py”,第716行,内部转换为tensor
ret=conversion\u func(值,dtype=dtype,name=name,as\u ref=as\u ref)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/ops/array_ops.py”,第923行,在_autopacking_conversion_函数中
返回_autopacking_helper(v、推断的_数据类型、名称或“打包”)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/ops/array_ops.py”,第886行,在自动打包帮助程序中
返回gen_数组操作包(元素作为张量,名称=范围)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/ops/gen_array_ops.py”,第2041行,在包中
结果=_op_def_lib.apply_op(“Pack”,value=value,axis=axis,name=name)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/framework/op_def_library.py”,第763行,在apply_op
op_def=op_def)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/framework/ops.py”,第2395行,在create_op中
初始值=自身值。\默认值\初始值,初始值=初始值)
文件“/home/freshfield/anaconda2/lib/python2.7/site packages/tensorflow/python/framework/ops.py”,第1264行,在__
self.\u traceback=\u extract\u stack()
InvalidArgumentError(回溯请参见上文):无法将设备分配给节点“打包”:无法满足显式设备规范“/device:GPU:0”,因为没有支持的GPU设备内核可用。
[[Node:packed=Pack[N=1,T=DT_字符串,axis=0,_device=“/device:GPU:0”](左)]]

TensorFlow不支持GPU(CPU)上操作x数据类型的完全叉积。最好在GitHub上以功能请求的形式询问这一点。