请求的 tensorflow = float64_ref,实际 = float64
tensorflow requested = 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
的输出:
Metadata-Version: 2.0
Name: tensorflow
Version: 0.11.0rc1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
Installer: pip
License: Apache 2.0
Location: /Users/ethan/env/lib/python2.7/site-packages
Requires: mock, protobuf, numpy, wheel, six
Classifiers:
Development Status :: 4 - Beta
Intended Audience :: Developers
Intended Audience :: Education
Intended Audience :: Science/Research
License :: OSI Approved :: Apache Software License
Programming Language :: Python :: 2.7
Topic :: Scientific/Engineering :: Mathematics
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Software Development :: Libraries
Entry-points:
[console_scripts]
tensorboard = tensorflow.tensorboard.tensorboard:main
谢谢!
我认为这是 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 中,class 张量的 dtype 为 float64_ref,class 变量的 dtype 为 float64。而 BasicRNNCell 需要一个 Tensor 而不是 Variable 作为输入。
在你的代码中,
x = tf.Variable(...)
应该改成
x = tf.convert_to_tensor(...)
我只是想让一个简单的 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
的输出:
Metadata-Version: 2.0 Name: tensorflow Version: 0.11.0rc1 Summary: TensorFlow helps the tensors flow Home-page: http://tensorflow.org/ Author: Google Inc. Author-email: opensource@google.com Installer: pip License: Apache 2.0 Location: /Users/ethan/env/lib/python2.7/site-packages Requires: mock, protobuf, numpy, wheel, six Classifiers: Development Status :: 4 - Beta Intended Audience :: Developers Intended Audience :: Education Intended Audience :: Science/Research License :: OSI Approved :: Apache Software License Programming Language :: Python :: 2.7 Topic :: Scientific/Engineering :: Mathematics Topic :: Software Development :: Libraries :: Python Modules Topic :: Software Development :: Libraries Entry-points: [console_scripts] tensorboard = tensorflow.tensorboard.tensorboard:main
谢谢!
我认为这是 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 中,class 张量的 dtype 为 float64_ref,class 变量的 dtype 为 float64。而 BasicRNNCell 需要一个 Tensor 而不是 Variable 作为输入。
在你的代码中,
x = tf.Variable(...)
应该改成
x = tf.convert_to_tensor(...)