Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve shape function of NonMaxSuppression #16890

Merged
merged 2 commits into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions tensorflow/core/ops/image_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ REGISTER_OP("NonMaxSuppression")
TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 0, &max_output_size));
// The boxes is a 2-D float Tensor of shape [num_boxes, 4].
DimensionHandle unused;
// The boxes[0] and scores[0] are both num_boxes.
TF_RETURN_IF_ERROR(
c->Merge(c->Dim(boxes, 0), c->Dim(scores, 0), &unused));
// The boxes[1] is 4.
TF_RETURN_IF_ERROR(c->WithValue(c->Dim(boxes, 1), 4, &unused));

c->set_output(0, c->Vector(c->UnknownDim()));
Expand All @@ -643,6 +647,10 @@ REGISTER_OP("NonMaxSuppressionV2")
TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 0, &iou_threshold));
// The boxes is a 2-D float Tensor of shape [num_boxes, 4].
DimensionHandle unused;
// The boxes[0] and scores[0] are both num_boxes.
TF_RETURN_IF_ERROR(
c->Merge(c->Dim(boxes, 0), c->Dim(scores, 0), &unused));
// The boxes[1] is 4.
TF_RETURN_IF_ERROR(c->WithValue(c->Dim(boxes, 1), 4, &unused));

c->set_output(0, c->Vector(c->UnknownDim()));
Expand Down
9 changes: 9 additions & 0 deletions tensorflow/python/ops/image_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3174,6 +3174,15 @@ def testInvalidShape(self):
selected_indices = image_ops.non_max_suppression(
boxes, scores, 3, 0.5)

# The boxes is of shape [num_boxes, 4], and the scores is
# of shape [num_boxes]. So an error will thrown.
with self.assertRaisesRegexp(
ValueError, 'Dimensions must be equal, but are 1 and 2'):
boxes = constant_op.constant([[0.0, 0.0, 1.0, 1.0]])
scores = constant_op.constant([0.9, 0.75])
selected_indices = image_ops.non_max_suppression(
boxes, scores, 3, 0.5)

# The scores should be 1D of shape [num_boxes].
with self.assertRaisesRegexp(
ValueError, 'Shape must be rank 1 but is rank 2'):
Expand Down