[英]TensorFlow missing CPU Op for FFT (InvalidArgumentError: No OpKernel was registered to support Op 'FFT' with these attrs)
I am new to tensorflow and want to create a graph which performs fft on real data, similar to numpys rfft function: 我是tensorflow的新手,并且想要创建一个对实际数据执行fft的图形,类似于numpys rfft函数:
def rfftOp(_in, name='rfft', graph=tf.get_default_graph()):
with graph.as_default():
with tf.device('/cpu:0'):
with tf.name_scope(name):
cast = tf.complex(tf.cast(_in, tf.float32, name='cast_to_float32'), tf.constant(0.0, dtype=tf.float32), name='cast_to_complex')
fftOp = tf.fft(cast, name='fft')
half, _ = tf.split(0, 2, fftOp, name='split')
double = tf.mul(tf.constant(2.0, dtype=tf.complex64), half)
return double
sess = tf.InteractiveSession()
inp = tf.placeholder(np.float64, shape=(256,), name='input')
fftOp = rfftOp(inp)
print(sess.run(fftOp, feed_dict={inp: d}))
However, I am getting the following error message: 但是,我收到以下错误消息:
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-18-0f6d789c912c> in <module>()
6 inp = tf.placeholder(np.float64, shape=(256,), name='input')
7 fftOp = rfftOp(inp)
----> 8 print(sess.run(fftOp, feed_dict={inp: d}))
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
338 try:
339 result = self._run(None, fetches, feed_dict, options_ptr,
--> 340 run_metadata_ptr)
341 if run_metadata:
342 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
562 try:
563 results = self._do_run(handle, target_list, unique_fetches,
--> 564 feed_dict_string, options, run_metadata)
565 finally:
566 # The movers are no longer used. Delete them.
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
635 if handle is None:
636 return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
--> 637 target_list, options, run_metadata)
638 else:
639 return self._do_call(_prun_fn, self._session, handle, feed_dict,
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _do_call(self, fn, *args)
657 # pylint: disable=protected-access
658 raise errors._make_specific_exception(node_def, op, error_message,
--> 659 e.code)
660 # pylint: enable=protected-access
661
InvalidArgumentError: No OpKernel was registered to support Op 'FFT' with these attrs
[[Node: rfft_4/fft = FFT[_device="/device:CPU:0"](rfft_4/cast_to_complex)]]
Caused by op u'rfft_4/fft', 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 "/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py", line 3, in <module>
app.launch_new_instance()
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 596, in launch_instance
app.start()
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelapp.py", line 442, in start
ioloop.IOLoop.instance().start()
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/ioloop.py", line 162, in start
super(ZMQIOLoop, self).start()
File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 883, in start
handler_func(fd_obj, events)
File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 276, in dispatcher
return self.dispatch_shell(stream, msg)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
handler(stream, idents, msg)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 391, in execute_request
user_expressions, allow_stdin)
File "/usr/local/lib/python2.7/dist-packages/ipykernel/ipkernel.py", line 199, in do_execute
shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2723, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2825, in run_ast_nodes
if self.run_code(code, result):
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2885, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-18-0f6d789c912c>", line 7, in <module>
fftOp = rfftOp(inp)
File "<ipython-input-17-e44d5219afe4>", line 6, in rfftOp
fftOp = tf.fft(cast, name='fft')
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_math_ops.py", line 518, in fft
return _op_def_lib.apply_op("FFT", in_=in_, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2154, 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 1154, in __init__
self._traceback = _extract_stack()
indicating that the Op for tensorflows fft is missing. 表示缺少tensorflows fft的运算符。 I've found a similar issue , but it focus on the GPU Op.
我发现了类似的问题 ,但它着重于GPU Op。 I am using the tensorflow/tensorflow docker image.
我正在使用tensorflow / tensorflow docker镜像。
So, is there anything missing in the docker image or do I have to use tensorflows fft another way? 那么,Docker映像中是否缺少任何东西,还是我必须以其他方式使用tensorflows吗?
You are forcing TensorFlow to try to run the FFT operation on CPU by calling with tf.device('/cpu:0')
. 您正在通过
with tf.device('/cpu:0')
调用来迫使TensorFlow尝试在CPU上运行FFT操作。 However the FFT operations are currently only implemented for GPU, which is why you end up with an error message. 但是,目前仅针对GPU实现FFT操作,这就是为什么您会收到一条错误消息的原因。
If you have a GPU available you can simply remove the call to tf.device(). 如果您有可用的GPU,则只需删除对tf.device()的调用即可。 TensorFlow will then automatically run the FFT operation on GPU.
TensorFlow随后将在GPU上自动运行FFT操作。
在TensorFlow的1.3版中解决了此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.