未验证 提交 41172ec9 编写于 作者: F FeiGeChuanShu 提交者: GitHub

fix yolox input shape w!=h result bug (#1158)

* Update tm_yolox.cpp

* apply code-format changes

* fix yolox input shape bug
Co-authored-by: NFeiGeChuanShu <FeiGeChuanShu@users.noreply.github.com>
上级 f56af4f1
......@@ -183,25 +183,24 @@ struct GridAndStride
int stride;
};
static int generate_grids_and_stride(const int target_size, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
static void generate_grids_and_stride(const int target_w, const int target_h, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
{
for (auto stride : strides)
{
int num_grid = target_size / stride;
for (int g1 = 0; g1 < num_grid; g1++)
int num_grid_w = target_w / stride;
int num_grid_h = target_h / stride;
for (int g1 = 0; g1 < num_grid_h; g1++)
{
for (int g0 = 0; g0 < num_grid; g0++)
for (int g0 = 0; g0 < num_grid_w; g0++)
{
GridAndStride ss;
ss.grid0 = g0;
ss.grid1 = g1;
ss.stride = stride;
grid_strides.push_back(ss);
GridAndStride gs;
gs.grid0 = g0;
gs.grid1 = g1;
gs.stride = stride;
grid_strides.push_back(gs);
}
}
}
return 0;
}
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, float* feat_ptr, float prob_threshold, std::vector<Object>& objects)
......@@ -288,7 +287,7 @@ void get_input_data_focus(const char* image_file, float* input_data, int letterb
img.convertTo(img, CV_32FC3);
// Generate a gray image for letterbox using opencv
cv::Mat img_new(letterbox_cols, letterbox_rows, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
cv::Mat img_new(letterbox_rows, letterbox_cols, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
int top = 0;
int bot = letterbox_rows - resize_rows;
int left = 0;
......@@ -496,7 +495,7 @@ int main(int argc, char* argv[])
std::vector<int> strides = {8, 16, 32}; // might have stride=64
std::vector<GridAndStride> grid_strides;
generate_grids_and_stride(letterbox_rows, strides, grid_strides);
generate_grids_and_stride(letterbox_cols, letterbox_rows, strides, grid_strides);
generate_yolox_proposals(grid_strides, p8_data, prob_threshold, proposals);
qsort_descent_inplace(proposals);
std::vector<int> picked;
......
......@@ -184,25 +184,24 @@ struct GridAndStride
int stride;
};
static int generate_grids_and_stride(const int target_size, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
static void generate_grids_and_stride(const int target_w, const int target_h, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
{
for (auto stride : strides)
{
int num_grid = target_size / stride;
for (int g1 = 0; g1 < num_grid; g1++)
int num_grid_w = target_w / stride;
int num_grid_h = target_h / stride;
for (int g1 = 0; g1 < num_grid_h; g1++)
{
for (int g0 = 0; g0 < num_grid; g0++)
for (int g0 = 0; g0 < num_grid_w; g0++)
{
GridAndStride ss;
ss.grid0 = g0;
ss.grid1 = g1;
ss.stride = stride;
grid_strides.push_back(ss);
GridAndStride gs;
gs.grid0 = g0;
gs.grid1 = g1;
gs.stride = stride;
grid_strides.push_back(gs);
}
}
}
return 0;
}
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, float* feat_ptr, float prob_threshold, std::vector<Object>& objects)
......@@ -288,7 +287,7 @@ void get_input_data_letterbox(const char* image_file, float* input_data, int let
img.convertTo(img, CV_32FC3);
// Generate a gray image for letterbox using opencv
cv::Mat img_new(letterbox_cols, letterbox_rows, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
cv::Mat img_new(letterbox_rows, letterbox_cols, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
int top = 0;
int bot = letterbox_rows - resize_rows;
int left = 0;
......@@ -474,7 +473,7 @@ int main(int argc, char* argv[])
std::vector<int> strides = {8, 16, 32}; // might have stride=64
std::vector<GridAndStride> grid_strides;
generate_grids_and_stride(letterbox_rows, strides, grid_strides);
generate_grids_and_stride(letterbox_cols, letterbox_rows, strides, grid_strides);
generate_yolox_proposals(grid_strides, p8_data, prob_threshold, proposals);
qsort_descent_inplace(proposals);
std::vector<int> picked;
......
......@@ -184,25 +184,24 @@ struct GridAndStride
int stride;
};
static int generate_grids_and_stride(const int target_size, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
static void generate_grids_and_stride(const int target_w, const int target_h, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
{
for (auto stride : strides)
{
int num_grid = target_size / stride;
for (int g1 = 0; g1 < num_grid; g1++)
int num_grid_w = target_w / stride;
int num_grid_h = target_h / stride;
for (int g1 = 0; g1 < num_grid_h; g1++)
{
for (int g0 = 0; g0 < num_grid; g0++)
for (int g0 = 0; g0 < num_grid_w; g0++)
{
GridAndStride ss;
ss.grid0 = g0;
ss.grid1 = g1;
ss.stride = stride;
grid_strides.push_back(ss);
GridAndStride gs;
gs.grid0 = g0;
gs.grid1 = g1;
gs.stride = stride;
grid_strides.push_back(gs);
}
}
}
return 0;
}
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, float* feat_ptr, float prob_threshold, std::vector<Object>& objects)
......@@ -291,7 +290,7 @@ void get_input_data_focus_int8(const char* image_file, int8_t* input_data, int l
img.convertTo(img, CV_32FC3);
// Generate a gray image for letterbox using opencv
cv::Mat img_new(letterbox_cols, letterbox_rows, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
cv::Mat img_new(letterbox_rows, letterbox_cols, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
int top = 0;
int bot = letterbox_rows - resize_rows;
int left = 0;
......@@ -518,7 +517,7 @@ int main(int argc, char* argv[])
std::vector<int> strides = {8, 16, 32}; // might have stride=64
std::vector<GridAndStride> grid_strides;
generate_grids_and_stride(letterbox_rows, strides, grid_strides);
generate_grids_and_stride(letterbox_cols, letterbox_rows, strides, grid_strides);
generate_yolox_proposals(grid_strides, p8_data.data(), prob_threshold, proposals);
qsort_descent_inplace(proposals);
std::vector<int> picked;
......
......@@ -184,25 +184,24 @@ struct GridAndStride
int stride;
};
static int generate_grids_and_stride(const int target_size, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
static void generate_grids_and_stride(const int target_w, const int target_h, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
{
for (auto stride : strides)
{
int num_grid = target_size / stride;
for (int g1 = 0; g1 < num_grid; g1++)
int num_grid_w = target_w / stride;
int num_grid_h = target_h / stride;
for (int g1 = 0; g1 < num_grid_h; g1++)
{
for (int g0 = 0; g0 < num_grid; g0++)
for (int g0 = 0; g0 < num_grid_w; g0++)
{
GridAndStride ss;
ss.grid0 = g0;
ss.grid1 = g1;
ss.stride = stride;
grid_strides.push_back(ss);
GridAndStride gs;
gs.grid0 = g0;
gs.grid1 = g1;
gs.stride = stride;
grid_strides.push_back(gs);
}
}
}
return 0;
}
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, float* feat_ptr, float prob_threshold, std::vector<Object>& objects)
......@@ -291,7 +290,7 @@ void get_input_data_focus_int8(const char* image_file, int8_t* input_data, int l
img.convertTo(img, CV_32FC3);
// Generate a gray image for letterbox using opencv
cv::Mat img_new(letterbox_cols, letterbox_rows, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
cv::Mat img_new(letterbox_rows, letterbox_cols, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
int top = 0;
int bot = letterbox_rows - resize_rows;
int left = 0;
......@@ -525,7 +524,7 @@ int main(int argc, char* argv[])
std::vector<int> strides = {8, 16, 32}; // might have stride=64
std::vector<GridAndStride> grid_strides;
generate_grids_and_stride(letterbox_rows, strides, grid_strides);
generate_grids_and_stride(letterbox_cols, letterbox_rows, strides, grid_strides);
generate_yolox_proposals(grid_strides, p8_data.data(), prob_threshold, proposals);
qsort_descent_inplace(proposals);
std::vector<int> picked;
......
......@@ -184,25 +184,24 @@ struct GridAndStride
int stride;
};
static int generate_grids_and_stride(const int target_size, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
static void generate_grids_and_stride(const int target_w, const int target_h, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
{
for (auto stride : strides)
{
int num_grid = target_size / stride;
for (int g1 = 0; g1 < num_grid; g1++)
int num_grid_w = target_w / stride;
int num_grid_h = target_h / stride;
for (int g1 = 0; g1 < num_grid_h; g1++)
{
for (int g0 = 0; g0 < num_grid; g0++)
for (int g0 = 0; g0 < num_grid_w; g0++)
{
GridAndStride ss;
ss.grid0 = g0;
ss.grid1 = g1;
ss.stride = stride;
grid_strides.push_back(ss);
GridAndStride gs;
gs.grid0 = g0;
gs.grid1 = g1;
gs.stride = stride;
grid_strides.push_back(gs);
}
}
}
return 0;
}
static void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, float* feat_ptr, float prob_threshold, std::vector<Object>& objects)
......@@ -291,7 +290,7 @@ void get_input_data_focus_uint8(const char* image_file, uint8_t* input_data, int
img.convertTo(img, CV_32FC3);
// Generate a gray image for letterbox using opencv
cv::Mat img_new(letterbox_cols, letterbox_rows, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
cv::Mat img_new(letterbox_rows, letterbox_cols, CV_32FC3, cv::Scalar(0, 0, 0) /*cv::Scalar(0.5/scale[0] + mean[0], 0.5/scale[1] + mean[1], 0.5/ scale[2] + mean[2])*/);
int top = 0;
int bot = letterbox_rows - resize_rows;
int left = 0;
......@@ -527,7 +526,7 @@ int main(int argc, char* argv[])
std::vector<int> strides = {8, 16, 32}; // might have stride=64
std::vector<GridAndStride> grid_strides;
generate_grids_and_stride(letterbox_rows, strides, grid_strides);
generate_grids_and_stride(letterbox_cols, letterbox_rows, strides, grid_strides);
generate_yolox_proposals(grid_strides, p8_data.data(), prob_threshold, proposals);
qsort_descent_inplace(proposals);
std::vector<int> picked;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册