bassma
bassma

Reputation: 1

Shape must be rank 2 but is rank 3 for NonMaxSuppressionV3: ERROR

I'm facing this error while trying to use tf.image.non_max_suppression while video object detection. Tensorflow version is 1.10.0

ValueError: Shape must be rank 2 but is rank 3 for 'non_max_suppression/NonMaxSuppressionV3' (op: 'NonMaxSuppressionV3') with input shapes: [1,500,4], [1,500], [], [], [].

Upvotes: 0

Views: 984

Answers (1)

Markus Kaukonen
Markus Kaukonen

Reputation: 414

I get this same error with tensorflow2.1 and the reason is that (as it says in the error) that the batch dimension cannot be there.

tf.image.non_max_suppression( boxes, scores, max_output_size, iou_threshold=0.5, score_threshold=float('-inf'), name=None )

boxes A 2-D float Tensor of shape [num_boxes, 4].

Example:

selected_indices = tf.image.non_max_suppression(
    boxes=boxes,
    scores=scores,
    max_output_size=7,
    iou_threshold=0.5)

You should remove the first(batch) dimension of the tensors (boxes and scores in the example above) In case your batch dimension is 1 you can use

boxes = tf.squeeze(boxes)
scores = tf.squeeze(scores)

It seems that you can have batch dimension is in this beast: https://www.tensorflow.org/api_docs/python/tf/image/combined_non_max_suppression

Upvotes: 0

Related Questions