Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions onnxruntime/contrib_ops/cpu/crop.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class CropBase {

// scale = (height, width)
if (!scale_.empty()) {
if (scale_.size() != 2) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Attribute scale needs to be specified with two elements (height, width), got ",
scale_.size());
}
int64_t bottomLimit = topBorder + scale_[0];
int64_t rightLimit = leftBorder + scale_[1];

Expand Down
20 changes: 20 additions & 0 deletions onnxruntime/test/contrib_ops/crop_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "gtest/gtest.h"
#include "test/providers/provider_test_utils.h"
#include "test/util/include/default_providers.h"

namespace onnxruntime {
namespace test {
Expand Down Expand Up @@ -30,5 +31,24 @@ TEST(CropOpTest, Crop_Scale) {
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}

TEST(CropOpTest, Crop_Invalid_Scale_Size) {
OpTester test("Crop", 1, onnxruntime::kOnnxDomain);
test.AddInput<float>("x", {1, 1, 4, 4}, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0});

std::vector<int64_t> border{1, 1, 1, 1};
test.AddAttribute("border", border);

std::vector<int64_t> scale{2}; // invalid: must be exactly 2 elements
test.AddAttribute("scale", scale);

test.AddOutput<float>("y", {1, 1, 2, 2}, {6.0, 7.0, 10.0, 11.0});

std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCpuExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectFailure,
"Attribute scale needs to be specified with two elements (height, width), got 1",
{}, nullptr, &execution_providers);
}

} // namespace test
} // namespace onnxruntime
Loading