Skip to content

Commit 237c326

Browse files
hyeygittensorflower-gardener
authored andcommitted
Eager execution coverage for image_ops_test.py. Removed run_deprecated_v1 decorators.
Part 14 (class FormatTest, NonMaxSuppression*Test) PiperOrigin-RevId: 339106641 Change-Id: I504ff77c3713bc294124e3e5b449cd5bc5807786
1 parent 2eda043 commit 237c326

File tree

3 files changed

+232
-106
lines changed

3 files changed

+232
-106
lines changed

tensorflow/core/kernels/image/non_max_suppression_op.cc

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ static inline void CheckScoreSizes(OpKernelContext* context, int num_boxes,
4343
const Tensor& scores) {
4444
// The shape of 'scores' is [num_boxes]
4545
OP_REQUIRES(context, scores.dims() == 1,
46-
errors::InvalidArgument("scores must be 1-D",
47-
scores.shape().DebugString()));
48-
OP_REQUIRES(context, scores.dim_size(0) == num_boxes,
49-
errors::InvalidArgument("scores has incompatible shape"));
46+
errors::InvalidArgument(
47+
"scores must be 1-D", scores.shape().DebugString(),
48+
" (Shape must be rank 1 but is rank ", scores.dims(), ")"));
49+
OP_REQUIRES(
50+
context, scores.dim_size(0) == num_boxes,
51+
errors::InvalidArgument("scores has incompatible shape (Dimensions must "
52+
"be equal, but are ",
53+
num_boxes, " and ", scores.dim_size(0), ")"));
5054
}
5155

5256
static inline void ParseAndCheckOverlapSizes(OpKernelContext* context,
@@ -67,11 +71,14 @@ static inline void ParseAndCheckBoxSizes(OpKernelContext* context,
6771
const Tensor& boxes, int* num_boxes) {
6872
// The shape of 'boxes' is [num_boxes, 4]
6973
OP_REQUIRES(context, boxes.dims() == 2,
70-
errors::InvalidArgument("boxes must be 2-D",
71-
boxes.shape().DebugString()));
74+
errors::InvalidArgument(
75+
"boxes must be 2-D", boxes.shape().DebugString(),
76+
" (Shape must be rank 2 but is rank ", boxes.dims(), ")"));
7277
*num_boxes = boxes.dim_size(0);
7378
OP_REQUIRES(context, boxes.dim_size(1) == 4,
74-
errors::InvalidArgument("boxes must have 4 columns"));
79+
errors::InvalidArgument("boxes must have 4 columns (Dimension "
80+
"must be 4 but is ",
81+
boxes.dim_size(1), ")"));
7582
}
7683

7784
static inline void CheckCombinedNMSScoreSizes(OpKernelContext* context,
@@ -670,12 +677,16 @@ class NonMaxSuppressionV3Op : public OpKernel {
670677
OP_REQUIRES(
671678
context, TensorShapeUtils::IsScalar(max_output_size.shape()),
672679
errors::InvalidArgument("max_output_size must be 0-D, got shape ",
673-
max_output_size.shape().DebugString()));
680+
max_output_size.shape().DebugString(),
681+
" (Shape must be rank 0 but is ", "rank ",
682+
max_output_size.dims(), ")"));
674683
// iou_threshold: scalar
675684
const Tensor& iou_threshold = context->input(3);
676685
OP_REQUIRES(context, TensorShapeUtils::IsScalar(iou_threshold.shape()),
677686
errors::InvalidArgument("iou_threshold must be 0-D, got shape ",
678-
iou_threshold.shape().DebugString()));
687+
iou_threshold.shape().DebugString(),
688+
" (Shape must be rank 0 but is rank ",
689+
iou_threshold.dims(), ")"));
679690
const T iou_threshold_val = iou_threshold.scalar<T>()();
680691
OP_REQUIRES(context,
681692
iou_threshold_val >= static_cast<T>(0.0) &&

tensorflow/core/kernels/image/non_max_suppression_op.cu.cc

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ limitations under the License.
1515

1616
#if GOOGLE_CUDA || TENSORFLOW_USE_ROCM
1717
#define EIGEN_USE_GPU
18+
#include "tensorflow/core/kernels/image/non_max_suppression_op.h"
19+
1820
#include <limits>
1921

2022
#include "absl/strings/str_cat.h"
@@ -23,7 +25,6 @@ limitations under the License.
2325
#include "tensorflow/core/framework/op_kernel.h"
2426
#include "tensorflow/core/framework/tensor_types.h"
2527
#include "tensorflow/core/kernels/gpu_prim.h"
26-
#include "tensorflow/core/kernels/image/non_max_suppression_op.h"
2728
#include "tensorflow/core/util/gpu_kernel_helper.h"
2829
#include "tensorflow/core/util/gpu_launch_config.h"
2930
#include "tensorflow/stream_executor/stream_executor.h"
@@ -550,30 +551,44 @@ Status CheckValidInputs(const Tensor& boxes, const Tensor& scores,
550551
const Tensor& iou_threshold) {
551552
if (!TensorShapeUtils::IsScalar(max_output_size.shape())) {
552553
return errors::InvalidArgument("max_output_size must be 0-D, got shape ",
553-
max_output_size.shape().DebugString());
554+
max_output_size.shape().DebugString(),
555+
" (Shape must be rank 0 but is ", "rank ",
556+
max_output_size.dims(), ")");
554557
}
555558
if (!TensorShapeUtils::IsScalar(iou_threshold.shape())) {
556559
return errors::InvalidArgument("iou_threshold must be 0-D, got shape ",
557-
iou_threshold.shape().DebugString());
560+
iou_threshold.shape().DebugString(),
561+
" (Shape must be rank 0 but is rank ",
562+
iou_threshold.dims(), ")");
558563
}
559564
const float iou_threshold_val = iou_threshold.scalar<float>()();
560565
if (iou_threshold_val < 0 || iou_threshold_val > 1) {
561566
return errors::InvalidArgument("iou_threshold must be in [0, 1]");
562567
}
563568
if (boxes.dims() != 2) {
564-
return errors::InvalidArgument("boxes must be a rank 2 tensor!");
569+
return errors::InvalidArgument(
570+
"boxes must be a rank 2 tensor! (Shape must "
571+
"be rank 2 but is rank ",
572+
boxes.dims(), ")");
565573
}
566574
int num_boxes = boxes.dim_size(0);
567575
if (boxes.dim_size(1) != 4) {
568-
return errors::InvalidArgument("boxes must be Nx4");
576+
return errors::InvalidArgument(
577+
"boxes must be Nx4 (Dimension must be 4 but"
578+
" is ",
579+
boxes.dim_size(1), ")");
569580
}
570581
if (scores.dims() != 1) {
571-
return errors::InvalidArgument("scores must be a vector!");
582+
return errors::InvalidArgument(
583+
"scores must be a vector! (Shape must be "
584+
"rank 1 but is rank ",
585+
scores.dims(), ")");
572586
}
573587
if (scores.dim_size(0) != num_boxes) {
574588
return errors::InvalidArgument(
575-
"scores has incompatible shape"); // message must be exactly this
576-
// otherwise tests fail!
589+
"scores has incompatible shape " // message must be exactly this
590+
"(Dimensions must be equal, but are ", // otherwise tests fail!
591+
num_boxes, " and ", scores.dim_size(0), ")");
577592
}
578593
return Status::OK();
579594
}

0 commit comments

Comments
 (0)