-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added mask overlay to output image, changed fprintf info messages to … #55
Changes from 1 commit
cd83c71
6c5663a
c34201b
e83fc8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,35 @@ int main(int argc, char *argv[]) { | |
return 1; | ||
} | ||
|
||
fprintf(stderr, "bbox_count=%d\n", *res_count); | ||
fprintf(stdout, "bbox_count=%d\n", *res_count); | ||
|
||
for (int i = 0; i < *res_count; ++i) { | ||
const auto &box = bboxes[i].bbox; | ||
fprintf(stderr, "box %d, left=%.2f, top=%.2f, right=%.2f, bottom=%.2f, label=%d, score=%.4f\n", | ||
const auto &mask = bboxes[i].mask; | ||
|
||
fprintf(stdout, "box %d, left=%.2f, top=%.2f, right=%.2f, bottom=%.2f, label=%d, score=%.4f\n", | ||
i, box.left, box.top, box.right, box.bottom, bboxes[i].label_id, bboxes[i].score); | ||
|
||
// skip detections with invalid bbox coordinates | ||
if (box.left < 1 && box.top < 1) { | ||
continue; | ||
} | ||
|
||
// generate mask overlay if model exports masks | ||
if (mask != nullptr) { | ||
fprintf(stdout, "mask %d, height=%d, width=%d\n", i, mask->height, mask->width); | ||
|
||
cv::Mat imgMask(mask->height, mask->width, CV_8UC1, &mask->data[0]); | ||
cv::Rect roi((int)box.left - 1, (int)box.top - 1, mask->width, mask->height); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current logic of the post-processing of instance segmentation is like auto x0 = std::max(std::floor(bbox[0]) - 1, 0.f);
auto y0 = std::max(std::floor(bbox[1]) - 1, 0.f); It is preferred to keep the same logic when recovering the whole-image mask so that the benchmark results would stay the same. Also, the top-left corner of invalid boxes (either FP or dummy outputs from backends) is not well defined and not reliable for box filtering. In this case, edge length or area thresholding is can used in combination with score thresholding to get better visual results. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lzhangzz So if I understand correctly, we should do something like: auto x0 = std::max(std::floor(box.left) - 1, 0.f);
auto y0 = std::max(std::floor(box.top) - 1, 0.f);
cv::Rect roi((int) x0, (int) y0, mask->width, mask->height); And for filtering the invalid boxes, we should look at not just the top-left but the side or area, in case it is zero, indicating an invalid bbox? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes
Don't use the top-left coordinate, just size/area and score. And actually there is a "min_bbox_size" property for detection models, however it is default to 0 in most model configs. So for demostration & visualization purpose, we can perform the filtering again on the detections returned by API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lzhangzz OK, I have updated it now according to your suggestions. |
||
|
||
// split the RGB channels, overlay mask to a specific color channel | ||
cv::Mat ch[3]; | ||
split(img, ch); | ||
int col = 0; // int col = i % 3; | ||
cv::bitwise_or(imgMask, ch[col](roi), ch[col](roi)); | ||
merge(ch, 3, img); | ||
} | ||
|
||
cv::rectangle(img, cv::Point{(int)box.left, (int)box.top}, | ||
cv::Point{(int)box.right, (int)box.bottom}, cv::Scalar{0, 255, 0}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
box.left == 0 || box.top == 0
is invalid coordinate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lvhan028 In my list of detections, I get a number of "invalid" detections with a very low score and all zero coordinates.
The bbox coordinates of these detections are usually zero and must be ignored. I figured that left/top will always be zero for these invalid detections, but after testing, it looks like valid detections can occur with a left/top coordinate of (0,0).
Maybe it would be better to look at left/top/right/bottom and make sure they are all zero. Alternatively, the score can be used to remove invalid detections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot. I think this is MMDeploy's bug. We need to investigate it.