我在使用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
答案 0 :(得分:1)
形状(?, 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。
希望有所帮助!