|
34 | 34 | namespace { |
35 | 35 | constexpr char saliency_map_name[]{"saliency_map"}; |
36 | 36 | constexpr char feature_vector_name[]{"feature_vector"}; |
| 37 | +constexpr float box_area_threshold = 1.0f; |
37 | 38 |
|
38 | 39 | struct NumAndStep { |
39 | 40 | size_t detectionsNum, objectSize; |
@@ -83,6 +84,11 @@ std::vector<std::string> filterOutXai(const std::vector<std::string>& names) { |
83 | 84 | std::copy_if (names.begin(), names.end(), std::back_inserter(filtered), [](const std::string& name){return name != saliency_map_name && name != feature_vector_name;}); |
84 | 85 | return filtered; |
85 | 86 | } |
| 87 | + |
| 88 | + |
| 89 | +float clamp_and_round(float val, float min, float max) { |
| 90 | + return std::round(std::max(min, std::min(max, val))); |
| 91 | +} |
86 | 92 | } |
87 | 93 |
|
88 | 94 | std::string ModelSSD::ModelType = "ssd"; |
@@ -214,23 +220,14 @@ std::unique_ptr<ResultBase> ModelSSD::postprocessMultipleOutputs(InferenceResult |
214 | 220 | desc.confidence = confidence; |
215 | 221 | desc.labelID = labels[i]; |
216 | 222 | desc.label = getLabelName(desc.labelID); |
217 | | - desc.x = clamp( |
218 | | - round((boxes[i * numAndStep.objectSize] * widthScale - padLeft) * invertedScaleX), |
219 | | - 0.f, |
220 | | - floatInputImgWidth); |
221 | | - desc.y = clamp( |
222 | | - round((boxes[i * numAndStep.objectSize + 1] * heightScale - padTop) * invertedScaleY), |
223 | | - 0.f, |
224 | | - floatInputImgHeight); |
225 | | - desc.width = clamp( |
226 | | - round((boxes[i * numAndStep.objectSize + 2] * widthScale - padLeft) * invertedScaleX), |
227 | | - 0.f, |
228 | | - floatInputImgWidth) - desc.x; |
229 | | - desc.height = clamp( |
230 | | - round((boxes[i * numAndStep.objectSize + 3] * heightScale - padTop) * invertedScaleY), |
231 | | - 0.f, |
232 | | - floatInputImgHeight) - desc.y; |
233 | | - result->objects.push_back(desc); |
| 223 | + desc.x = clamp_and_round((boxes[i * numAndStep.objectSize] * widthScale - padLeft) * invertedScaleX, 0.f, floatInputImgWidth); |
| 224 | + desc.y = clamp_and_round((boxes[i * numAndStep.objectSize + 1] * heightScale - padTop) * invertedScaleY, 0.f, floatInputImgHeight); |
| 225 | + desc.width = clamp_and_round((boxes[i * numAndStep.objectSize + 2] * widthScale - padLeft) * invertedScaleX, 0.f, floatInputImgWidth) - desc.x; |
| 226 | + desc.height = clamp_and_round((boxes[i * numAndStep.objectSize + 3] * heightScale - padTop) * invertedScaleY, 0.f, floatInputImgHeight) - desc.y; |
| 227 | + |
| 228 | + if (desc.width * desc.height >= box_area_threshold) { |
| 229 | + result->objects.push_back(desc); |
| 230 | + } |
234 | 231 | } |
235 | 232 | } |
236 | 233 |
|
|
0 commit comments