简体   繁体   中英

TensorFlow: Value Error Shape and Rank Do Not Match: ValueError: Shape (?, 128, 128, 2) must have rank 2

I'm getting this exception when running a prediction using a deconv neural network. The rank and shape seem to be the same so I'm not sure what the issue is.

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) is a rank 4 tensor, but the softmax operator apparently expected a rank 2 tensor.

It looks to me like you are using an old version of Tensorflow. In version 0.10, tf.nn.softmax required that its input be rank 2: https://www.tensorflow.org/versions/r0.10/api_docs/python/nn/classification#softmax

In current versions of Tensorflow, tf.nn.softmax accepts inputs of any rank: https://www.tensorflow.org/api_docs/python/nn/classification#softmax

Try using a newer version of Tensorflow.

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM