[Fix] swap width and height in Resize and Pad according to upstream codebases ()

* swap width and height in Resize and Pad according to upstream codebases

* fix UT

* better?

* add comments
pull/2064/head^2
AllentDan 2023-05-15 11:30:50 +08:00 committed by GitHub
parent 26b66ef511
commit 5fd0e8957f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions
csrc/mmdeploy/preprocess/transform
tests/test_csrc/preprocess

View File

@ -82,9 +82,9 @@ class Pad : public Transform {
data["pad_fixed_size"].push_back(pad_h);
data["pad_fixed_size"].push_back(pad_w);
} else {
padding = {0, 0, size_[1] - width, size_[0] - height};
data["pad_fixed_size"].push_back(size_[0]);
padding = {0, 0, size_[0] - width, size_[1] - height};
data["pad_fixed_size"].push_back(size_[1]);
data["pad_fixed_size"].push_back(size_[0]);
}
} else if (size_divisor_ != 1) {
auto pad_h = (height + size_divisor_ - 1) / size_divisor_ * size_divisor_;

View File

@ -27,9 +27,15 @@ class Resize : public Transform {
MMDEPLOY_ERROR("'size' expects an array of size 2, but got {}", args["size"].size());
throw_exception(eInvalidArgument);
}
auto height = args["size"][0].get<int>();
auto width = args["size"][1].get<int>();
img_scale_ = {height, width};
// the order in openmmalb config is [width, height], while in SDK it is [height, width]
// keep the last dim -1
auto width = args["size"][0].get<int>();
auto height = args["size"][1].get<int>();
if (-1 == height) {
img_scale_ = {width, -1};
} else {
img_scale_ = {height, width};
}
} else {
MMDEPLOY_ERROR("'size' is expected to be an integer or and array of size 2");
throw_exception(eInvalidArgument);

View File

@ -111,7 +111,7 @@ TEST_CASE("transform 'Pad'", "[pad]") {
constexpr int width = 800;
for (auto& mat : mats) {
for (auto& mode : modes) {
Value cfg{{"type", "Pad"}, {"size", {height, width}}, {"padding_mode", mode}};
Value cfg{{"type", "Pad"}, {"size", {width, height}}, {"padding_mode", mode}};
auto [pad_left, pad_top, pad_right, pad_bottom] = GetPadSize(mat, height, width);
TestPad(cfg, mat, pad_top, pad_left, pad_bottom, pad_right, border_map[mode], 0);
}

View File

@ -230,7 +230,7 @@ TEST_CASE("resize transform: size", "[resize]") {
for (auto& mat : mats) {
for (auto& interp : interpolations) {
Value cfg{{"type", "Resize"},
{"size", {dst_height, dst_width}},
{"size", {dst_width, dst_height}},
{"keep_ratio", keep_ratio},
{"interpolation", interp}};
TestResize(cfg, kHost, mat, dst_height, dst_width);