0

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], [], [], [].

bassma
  • 1
  • Could you post some code to illustrute your attempt to solve as well as description of the problem you faced? – Artem Sep 14 '18 at 09:46
  • I'm using tensorflow to detect object in Video. when I called the pre build function " tf.image.non_max_suppression " the error mentioned earlier came up. selected_indices = tf.image.non_max_suppression(boxes, scores, 3, 0.6) selected_boxes = tf.gather(boxes, selected_indices) – bassma Sep 17 '18 at 08:33
  • thanks a lot, bassma, it would be nice if you edit your question and add the information in the comment into the text. – Artem Sep 17 '18 at 11:51

1 Answers1

0

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Markus Kaukonen
  • 334
  • 4
  • 10