请求tensorflow = float64_ref,actual = float64
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请求tensorflow = float64_ref,actual = float64相关的知识,希望对你有一定的参考价值。
我只是想让一个简单的RNNCell工作。这个简单的代码:
with tf.Session() as sess:
x = tf.Variable(np.ones((2, 3)))
tf.initialize_all_variables().run()
out, state = BasicRNNCell(4)(x, x)
引发以下错误:
Traceback (most recent call last):
File "scrap.py", line 38, in <module>
g, _ = tf.nn.rnn_cell.BasicRNNCell(2)(x, x)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/rnn_cell.py", line 199, in __call__
output = self._activation(_linear([inputs, state], self._num_units, True))
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/rnn_cell.py", line 903, in _linear
"Matrix", [total_arg_size, output_size], dtype=dtype)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1022, in get_variable
custom_getter=custom_getter)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 849, in get_variable
custom_getter=custom_getter)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 345, in get_variable
validate_shape=validate_shape)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 330, in _true_getter
caching_device=caching_device, validate_shape=validate_shape)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 676, in _get_single_variable
validate_shape=validate_shape)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 215, in __init__
dtype=dtype)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 288, in _init_from_args
initial_value(), name="initial_value", dtype=dtype)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 666, in <lambda>
shape.as_list(), dtype=dtype, partition_info=partition_info)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/init_ops.py", line 280, in _initializer
dtype, seed=seed)
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/ops/random_ops.py", line 232, in random_uniform
minval = ops.convert_to_tensor(minval, dtype=dtype, name="min")
File "/Users/ethan/env/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 671, in convert_to_tensor
dtype.name, ret.dtype.name))
RuntimeError: min: Conversion function <function _constant_tensor_conversion_function at 0x112053c08> for type <type 'object'> returned incompatible dtype: requested = float64_ref, actual = float64
这是pip show tensorflow
的输出:
元数据 - 版本:2.0名称:tensorflow版本:0.11.0rc1摘要:TensorFlow帮助张量流程主页:http://tensorflow.org/作者:Google Inc.作者电子邮件:opensource@google.com安装程序:pip许可证:Apache 2.0位置:/ Users /ethan/env/lib/python2.7/site-packages需要:mock,protobuf,numpy,wheel,six分类器:开发状态:: 4 - Beta预期受众::开发人员目标受众::教育目标受众::科学/研究许可证:: OSI批准:: Apache软件许可证编程语言:: Python :: 2.7主题::科学/工程::数学主题::软件开发::库:: Python模块主题::软件开发::库输入 - points:[console_scripts] tensorboard = tensorflow.tensorboard.tensorboard:main
谢谢!
在TensorFlow中,类Tensor的dtype为float64_ref,类Variable的dtype为float64。并且BasicRNNCell需要除变量之外的Tensor作为输入。在您的代码中,x = tf.Variable(...)
应更改为x = tf.convert_to_tensor(...)
我认为这是Tensorflow中的一个错误,我邀请你加入open an issue on GitHub。
要解决此问题,您可以使用tf.identity
创建float64_ref
而不是float64
x
并将此值作为inputs
参数传递。
import tensorflow as tf
import numpy as np
with tf.Session() as sess:
x = tf.Variable(np.ones((2, 3)))
sess.run(tf.initialize_all_variables())
out, state = tf.nn.rnn_cell.BasicRNNCell(4)(tf.identity(x), x)
以上是关于请求tensorflow = float64_ref,actual = float64的主要内容,如果未能解决你的问题,请参考以下文章
如何使 TensorFlow Hub 模型为 TensorFlow Serving REST 请求做好准备(使用 base64 编码图像)?
tensorflow:无法加载动态库“cudart64_110.dll”; dlerror: 未找到 cudart64_110.dll