Skip to content
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

accurate confidence #45

Open
fatalfeel opened this issue Dec 19, 2024 · 0 comments
Open

accurate confidence #45

fatalfeel opened this issue Dec 19, 2024 · 0 comments

Comments

@fatalfeel
Copy link

for (auto& detection : detections)
{
for (int i = 0; i < detection.rows; i++)
{
cv::Mat onerow = detection.row(i);
cv::Mat scores = onerow.colRange(5, onerow.cols);
cv::minMaxLoc(scores, 0, &maxscore, 0, &classIdPoint);
finalConf = onerow.at(4) * maxscore;

    //if (maxscore > threshold)
    if (finalConf > threshold)
    {
        int centerX = static_cast<int>(onerow.at<float>(0) * resize_3840_bgr.cols);
        int centerY = static_cast<int>(onerow.at<float>(1) * resize_3840_bgr.rows);
        int width   = static_cast<int>(onerow.at<float>(2) * resize_3840_bgr.cols);
        int height  = static_cast<int>(onero{
for (int i = 0; i < detection.rows; i++)
{
    cv::Mat onerow = detection.row(i);
    cv::Mat scores = onerow.colRange(5, onerow.cols);
    cv::minMaxLoc(scores, 0, &maxscore, 0, &classIdPoint);
    finalConf = onerow.at<float>(4) * maxscore;

    //if (maxscore > threshold)
    if (finalConf > threshold)
    {
        int centerX = static_cast<int>(onerow.at<float>(0) * resize_3840_bgr.cols);
        int centerY = static_cast<int>(onerow.at<float>(1) * resize_3840_bgr.rows);
        int width   = static_cast<int>(onerow.at<float>(2) * resize_3840_bgr.cols);
        int height  = static_cast<int>(onerow.at<float>(3) * resize_3840_bgr.rows);
        int left    = centerX - width   / 2;
        int top     = centerY - height  / 2;

        boxes.push_back(cv::Rect(left, top, width, height));
        //classIds.push_back(classId);
        //confidences.push_back((float)maxscore);
        confidences.push_back((float)finalConf);
    }
}

}w.at(3) * resize_3840_bgr.rows);
int left = centerX - width / 2;
int top = centerY - height / 2;

        boxes.push_back(cv::Rect(left, top, width, height));
        //classIds.push_back(classId);
        //confidences.push_back((float)maxscore);
        confidences.push_back((float)finalConf);
    }
}

}

In YOLO, the decision-making process involves:

Locating objects: Based on the objectness score (onerow.at<float>(4)).
Classifying objects: Based on the class confidence scores (onerow.at<float>(5) through onerow.at<float>(10)).

By multiplying the objectness score and the class confidence score, you get a combined measure (finalConf) that represents the likelihood of a specific class being present in the bounding box.
Example:

For a row with the following values:

[0.5, 0.5, 0.2, 0.4, 0.9, 0.1, 0.7, 0.2, 0.05, 0.03, 0.02]

Center X = 0.5 (50% of image width).
Center Y = 0.5 (50% of image height).
Width = 0.2 (20% of image width).
Height = 0.4 (40% of image height).
Objectness Score = 0.9 (90% confidence that there is an object in this box).
Class Scores:
    Class 0: 0.1
    Class 1: 0.7
    Class 2: 0.2
    Class 3: 0.05
    Class 4: 0.03
    Class 5: 0.02

If the highest class confidence score is 0.7 (for Class 1):

finalConf = 0.9 * 0.7 = 0.63.

This final confidence is compared to the threshold to decide whether to keep this detection.
Screenshot from 2024-12-19 11-39-34

//python
maxcore = scores[class_id]
finalConf = detection[4] * maxcore
#if maxcore > CONF_THRESH:
if finalConf > CONF_THRESH:
center_x = int(detection[0] * im_w)
center_y = int(detection[1] * im_h)
width = int(detection[2] * im_w)
height = int(detection[3] * im_h)
left = int(center_x - width / 2)
top = int(center_y - height / 2)
class_ids.append(int(class_id))
#confidences.append(float(maxcore))
confidences.append(float(finalConf))
boxes.append([left, top, width, height])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant