tf.contrib.layers.flatform(x)张量流的替代函数



我在Jetson TK1上使用Tensor flow 0.8.0 verison,在32位arm架构上使用Cuda 6.5。为此,我无法升级Tensor Flow版本,我在Flatten函数中遇到了麻烦

x = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28])
y = tf.placeholder(dtype = tf.int32, shape = [None])
images_flat = tf.contrib.layers.flatten(x)

我现在得到的错误是

AttributeError: 'module' object has no attribute 'flatten'

Tensor Flow V0.8 中是否支持该功能的替代方案

到目前为止,我尝试的是

images_flat = tf.reshape(x, (tf.shape(x)[0], -1))

但为此我得到以下错误

File "demo_code.py", line 113, in <module>
images_flat = tf.reshape(x, (tf.shape(x)[0], -1))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1092, in reshape
name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 411, in apply_op
as_ref=input_arg.is_ref)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 566, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/constant_op.py", line 179, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/constant_op.py", line 162, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 332, in make_tensor_proto
_AssertCompatible(values, dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 272, in _AssertCompatible
(dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

有关它的更多详细信息,我将遵循本教程https://www.datacamp.com/community/tutorials/tensorflow-tutorial

感谢

您可以使用tf.reshape代替

images_flat = tf.reshape(x, [x.get_shape(x).as_list()[0], -1])

最新更新