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

编程入门 行业动态 更新时间:2024-10-15 10:18:38
本文介绍了tf.contrib.layers.flatten(x) 张量流的替代函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在 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/community/tutorials/tensorflow-tutorial

For more details about it, i am following this tutorial https://www.datacamp/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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 05:53:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405305.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:张量   函数   contrib   tf   flatten

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!