linghu8812 / tensorrt_inference

708 stars 208 forks source link

mmpose.cpp crash on postProcess #134

Open MatchX opened 2 years ago

MatchX commented 2 years ago

在 std::vector<std::vector> mmpose::postProcess(const std::vector &vec_Mat, float *output, const int &outSize)

for (int number = 0; number < num_key_points; number++) { float current_point = current_person + feature_size number; auto max_pos = std::max_element(current_point, current_point + feature_size); key_points[number].prob = max_pos; float x = (max_pos - current_point) % (IMAGE_WIDTH / 4) + ((max_pos + 1) > (max_pos - 1) ? 0.25 : -0.25); float y = (max_pos - current_point) / (IMAGE_WIDTH / 4) + ((max_pos + IMAGE_WIDTH / 4) > (max_pos - IMAGE_WIDTH / 4) ? 0.25 : -0.25); key_points[number].x = int(x ratio 4); key_points[number].y = int(y ratio 4); key_points[number].number = number; } 这里计算x和y偏移值时没有考虑到最左 最右 最上 最下时访问越界的问题 导致崩溃 大致改成如下就行了 std::vector key_points(m_modelInfo.dimInfo[1][1]); float ratio = std::max(static_cast(src_img.cols) / static_cast(inputW), static_cast(src_img.rows) / static_cast(inputH)); float current_person = output + static_cast(index outSize); for (int number = 0; number < m_modelInfo.dimInfo[1][1]; ++number) { float current_point = current_person + static_cast(m_featureSize number); const auto bigpos{ current_point + m_featureSize }; auto max_pos = std::max_element(current_point, bigpos); key_points[number].prob = max_pos; { const float x = static_cast((max_pos - current_point) % (m_modelInfo.dimInfo[1][3])); const float xdiff{ (max_pos > current_point && max_pos < bigpos) ? ((max_pos + 1) > (max_pos - 1) ? 0.25f : -0.25f) : 0.f }; const float y = static_cast(max_pos - current_point) / (static_cast(m_modelInfo.dimInfo[1][3])); const float ydiff = (max_pos - m_modelInfo.dimInfo[1][3] >= current_point && max_pos + m_modelInfo.dimInfo[1][3] <= bigpos) ? ((max_pos + m_modelInfo.dimInfo[1][3]) > (max_pos - m_modelInfo.dimInfo[1][3]) ? 0.25f : -0.25f) : 0.f; key_points[number].x = static_cast((x + xdiff) ratio 4); key_points[number].y = static_cast((y + ydiff) ratio 4); } key_points[number].number = number; } vec_key_points.push_back(key_points); ++index;