请求的tensorflow=float64\u ref,实际值=float64

请求的tensorflow=float64\u ref,实际值=float64,tensorflow,type-conversion,recurrent-neural-network,Tensorflow,Type Conversion,Recurrent Neural Network,我只是想让一个简单的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 &

我只是想让一个简单的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
回溯(最近一次呼叫最后一次):
文件“scrap.py”,第38行,在
g、 基本单元(2)(x,x)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/rnn_cell.py”,第199行,在调用中__
输出=自我激活(_线性([输入,状态],自我数量单位,真))
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/rnn_cell.py”,第903行,以线性形式显示
“矩阵”,[total_arg_size,output_size],dtype=dtype)
get_变量中的文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variable_scope.py”,第1022行
custom\u getter=custom\u getter)
get_变量中的文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variable_scope.py”,第849行
custom\u getter=custom\u getter)
get_变量中的文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variable_scope.py”,第345行
验证形状=验证形状)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variable\u scope.py”,第330行,在“true\u getter”中
缓存\设备=缓存\设备,验证\形状=验证\形状)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variable\u scope.py”,第676行,在“get\u single\u variable”中
验证形状=验证形状)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variables.py”,第215行,在__
dtype=dtype)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variables.py”,第288行,在参数的_init_中
初始值(),name=“初始值”,dtype=dtype)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/variable_scope.py”,第666行,在
shape.as\u list(),dtype=dtype,partition\u info=partition\u info)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/init_ops.py”,第280行,在初始化器中
数据类型,种子=种子)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/ops/random_ops.py”,第232行,随机统一格式
minval=ops。将_转换为_张量(minval,dtype=dtype,name=“min”)
文件“/Users/ethan/env/lib/python2.7/site packages/tensorflow/python/framework/ops.py”,第671行,在convert_to_tensor中
dtype.name,ret.dtype.name)
RuntimeError:min:type的转换函数返回了不兼容的数据类型:requested=float64\u ref,actual=float64
这是
pip show tensorflow
的输出:

元数据版本:2.0 名称:tensorflow 版本:0.11.0rc1 摘要:张量流有助于张量流 主页: 作者:谷歌公司。 作者电子邮件:opensource@google.com 安装程序:pip 许可证:Apache2.0 位置:/Users/ethan/env/lib/python2.7/site-packages 要求:模拟,原型,numpy,轮子,六个 分类器: 开发状态::4-测试版 目标受众::开发人员 目标受众:教育 目标受众:科学/研究 许可证::OSI批准::Apache软件许可证 编程语言::Python::2.7 主题:科学/工程:数学 主题::软件开发::库::Python模块 主题::软件开发::库 入境点: [控制台脚本] tensorboard=tensorflow.tensorboard.tensorboard:main


谢谢

我认为这是Tensorflow中的一个bug,我邀请您加入

要解决此问题,可以使用
tf.identity
创建
float64\u ref
而不是
float64
x
,并将此值作为
输入
参数传递

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中,类Tensor的数据类型为float64\u ref,类变量的数据类型为float64。基本细胞需要一个张量而不是一个变量作为输入。 在代码中,
x=tf.变量(…)
应改为
x=tf.convert\u to\u tensor(…)

终于开始讨论这个问题了。谢谢你的推荐。有什么真正的解决办法吗?我得到了同样的错误,即使是简单的代码也会导致这样的错误:
>>将tensorflow导入为tf>>>tf.Variable(初始值=[0.0],dtype=tf.float64)
您使用的是什么tf版本?使用最新版本,我在运行您的codec时没有问题。我确认您的解决方案有效,但这让我有点困惑。为什么它不能接受一个变量作为输入?