tf.contrib.layers.flatten(x) 张量流的替代函数 [英] Alternative function for tf.contrib.layers.flatten(x) Tensor Flow

查看:230
本文介绍了tf.contrib.layers.flatten(x) 张量流的替代函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Jetson TK1 上使用 Tensor Flow 0.8.0 版本,在 32 位 arm 架构上使用 Cuda 6.5.为此,我无法升级 Tensor Flow 版本,而且我在 Flatten 功能方面遇到了麻烦

i am using Tensor flow 0.8.0 verison on Jetson TK1 with Cuda 6.5 on 32 bit arm architecture. For that i can't upgrade the Tensor Flow version and i am facing trouble in Flatten function

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 是否支持此功能的替代方案

is there any alternative to this function that may be supported in 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

For more details about it, i am following this tutorial https://www.datacamp.com/community/tutorials/tensorflow-tutorial

谢谢

推荐答案

您可以使用 tf.reshape 代替

You can use tf.reshape instead

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

这篇关于tf.contrib.layers.flatten(x) 张量流的替代函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆