gpt4 book ai didi

python - TensorFlow:值错误形状和等级不匹配:ValueError:形状 (?, 128, 128, 2) must have rank 2

转载 作者:太空宇宙 更新时间:2023-11-04 05:15:18 24 4
gpt4 key购买 nike

我在使用 deconv 神经网络运行预测时遇到此异常。等级和形状似乎相同,所以我不确定是什么问题。

File "/home/Workspace/image-recognition/app/model/per_pixel_deconv.py", line 141, in Model
softmax = tf.nn.softmax(output, name=None)

File "/home/anaconda2/envs/image-recognition/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 1396, in softmax
result = _op_def_lib.apply_op("Softmax", logits=logits, name=name)

File "/home/anaconda2/envs/image-recognition/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op
op_def=op_def)

File "/home/anaconda2/envs/image-recognition/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2319, in create_op
set_shapes_for_outputs(ret)

File "/home/anaconda2/envs/image-recognition/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1711, in set_shapes_for_outputs
shapes = shape_func(op)

File "/home/anaconda2/envs/image-recognition/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 45, in _ShapeFunction
return [op.inputs[0].get_shape().with_rank(rank)]

File "/home/anaconda2/envs/image-recognition/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 641, in with_rank
raise ValueError("Shape %s must have rank %d" % (self, rank))
ValueError: Shape (?, 128, 128, 2) must have rank 2

最佳答案

Shape (?, 128, 128, 2) 是 4 阶张量,但 softmax 运算符显然需要 2 阶张量。

在我看来,您使用的是旧版本的 Tensorflow。在 0.10 版本中,tf.nn.softmax 要求其输入为 2 阶: https://www.tensorflow.org/versions/r0.10/api_docs/python/nn/classification#softmax

在当前版本的 Tensorflow 中,tf.nn.softmax 接受任何等级的输入: https://www.tensorflow.org/api_docs/python/nn/classification#softmax

尝试使用更新版本的 Tensorflow。

希望对您有所帮助!

关于python - TensorFlow:值错误形状和等级不匹配:ValueError:形状 (?, 128, 128, 2) must have rank 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41900775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com