Skip to content

Commit 5fd0e89

Browse files
authored
[Fix] swap width and height in Resize and Pad according to upstream codebases (#2063)
* swap width and height in Resize and Pad according to upstream codebases * fix UT * better? * add comments
1 parent 26b66ef commit 5fd0e89

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

csrc/mmdeploy/preprocess/transform/pad.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ class Pad : public Transform {
8282
data["pad_fixed_size"].push_back(pad_h);
8383
data["pad_fixed_size"].push_back(pad_w);
8484
} else {
85-
padding = {0, 0, size_[1] - width, size_[0] - height};
86-
data["pad_fixed_size"].push_back(size_[0]);
85+
padding = {0, 0, size_[0] - width, size_[1] - height};
8786
data["pad_fixed_size"].push_back(size_[1]);
87+
data["pad_fixed_size"].push_back(size_[0]);
8888
}
8989
} else if (size_divisor_ != 1) {
9090
auto pad_h = (height + size_divisor_ - 1) / size_divisor_ * size_divisor_;

csrc/mmdeploy/preprocess/transform/resize.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ class Resize : public Transform {
2727
MMDEPLOY_ERROR("'size' expects an array of size 2, but got {}", args["size"].size());
2828
throw_exception(eInvalidArgument);
2929
}
30-
auto height = args["size"][0].get<int>();
31-
auto width = args["size"][1].get<int>();
32-
img_scale_ = {height, width};
30+
// the order in openmmalb config is [width, height], while in SDK it is [height, width]
31+
// keep the last dim -1
32+
auto width = args["size"][0].get<int>();
33+
auto height = args["size"][1].get<int>();
34+
if (-1 == height) {
35+
img_scale_ = {width, -1};
36+
} else {
37+
img_scale_ = {height, width};
38+
}
3339
} else {
3440
MMDEPLOY_ERROR("'size' is expected to be an integer or and array of size 2");
3541
throw_exception(eInvalidArgument);

tests/test_csrc/preprocess/test_pad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ TEST_CASE("transform 'Pad'", "[pad]") {
111111
constexpr int width = 800;
112112
for (auto& mat : mats) {
113113
for (auto& mode : modes) {
114-
Value cfg{{"type", "Pad"}, {"size", {height, width}}, {"padding_mode", mode}};
114+
Value cfg{{"type", "Pad"}, {"size", {width, height}}, {"padding_mode", mode}};
115115
auto [pad_left, pad_top, pad_right, pad_bottom] = GetPadSize(mat, height, width);
116116
TestPad(cfg, mat, pad_top, pad_left, pad_bottom, pad_right, border_map[mode], 0);
117117
}

tests/test_csrc/preprocess/test_resize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ TEST_CASE("resize transform: size", "[resize]") {
230230
for (auto& mat : mats) {
231231
for (auto& interp : interpolations) {
232232
Value cfg{{"type", "Resize"},
233-
{"size", {dst_height, dst_width}},
233+
{"size", {dst_width, dst_height}},
234234
{"keep_ratio", keep_ratio},
235235
{"interpolation", interp}};
236236
TestResize(cfg, kHost, mat, dst_height, dst_width);

0 commit comments

Comments
 (0)