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

Tensorflow tf.contrib.layers.flatten(x)张量流的替代函数,tensorflow,tensorflow2.0,tensor,tensorflow-datasets,tensorflow-serving,Tensorflow,Tensorflow2.0,Tensor,Tensorflow Datasets,Tensorflow Serving,我在Jetson TK1上使用Tensor flow 0.8.0 verison,在32位arm架构上使用Cuda 6.5。因此,我无法升级张量流版本,而且我在展平函数方面遇到了麻烦 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)

我在Jetson TK1上使用Tensor flow 0.8.0 verison,在32位arm架构上使用Cuda 6.5。因此,我无法升级张量流版本,而且我在展平函数方面遇到了麻烦

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.

文件“demo_code.py”,第113行,在
图像_flat=tf.重塑(x,(tf.形状(x)[0],-1))
文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_-array_-ops.py”,第1092行,在“重塑”中
名称=名称)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/op_def_library.py”,第411行,在apply_op
as_ref=输入参数为
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/framework/ops.py”,第566行,在convert_to_tensor中
ret=conversion\u func(值,dtype=dtype,name=name,as\u ref=as\u ref)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/constant_op.py”,第179行,在_constant_tensor_conversion_函数中
返回常量(v,dtype=dtype,name=name)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/constant_op.py”,第162行,常量
tensor_util.make_tensor_proto(值,dtype=dtype,shape=shape))
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/framework/tensor_util.py”,第332行,在make_tensor_proto中
_资产可兼容(值、数据类型)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/framework/tensor_util.py”,第272行,在_AssertCompatible中
(dtype.name、repr(不匹配)、type(不匹配)。\uu name
TypeError:应为int32,但得到了包含“\u Message”类型张量的列表。
关于它的更多细节,我将学习本教程

谢谢

您可以改用

images\u flat=tf.reformate(x,[x.get\u shape(x).as\u list()[0],-1])
您可以使用

images\u flat=tf.reformate(x,[x.get\u shape(x).as\u list()[0],-1])

这是否回答了您的问题?不幸的是没有。我已经尝试了那篇文章中建议的所有3个选项。我在我的帖子中发布了这三种解决方案之一的错误。如果您愿意,我也可以为其他人做。请现在尝试解决方案,我已经编辑了它(使用
x.get\u shape().as\u list()
),这是否回答了您的问题?不幸的是没有。我已经尝试了那篇文章中建议的所有3个选项。我在我的帖子中发布了这三种解决方案之一的错误。如果您愿意,我也可以为其他人做。请立即尝试解决方案,我已经编辑过(使用
x.get_shape().as_list()
)是的,我尝试过,但仍然得到错误:File“/usr/local/lib/python2.7/dist packages/tensorflow/python/framework/tensor_util.py”,第272行,在RTCASSETCompatible(dtype.name,repr(mismatch),type(mismatch)中.uuuu name(uuuu))TypeError:应为int32,改为获取包含“\u Message”类型的张量的列表。我已在原始postyes中将完整错误添加到此命令中。我尝试了此操作,但仍然得到错误:文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/framework/tensor_util.py”,第272行,在AssertCompatible(dtype.name,repr)中(不匹配),类型(不匹配)。\uuuu name(uuuu))TypeError:应为int32,但获取的列表包含“\u Message”类型的张量。我已在原始帖子中将完整错误添加到此命令