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

识别类型person(人)问题。 #71

Open
caiyongrt opened this issue Feb 5, 2025 · 0 comments
Open

识别类型person(人)问题。 #71

caiyongrt opened this issue Feb 5, 2025 · 0 comments

Comments

@caiyongrt
Copy link

识别类型person(人),如果是固定场景的人物,能否增加人物唯一标识的ID,已区分是哪个人物?
以下代码没有可以识别人物标识ID的功能:
num_classTemp = 80;//类别总量

const int num_class = num_classTemp;
const int reg_max_1 = 16;

for (int i = 0; i < num_points; i++)
{
    const float* scores = pred.row(i) + 4 * reg_max_1;
    // find label with max score
    int label = -1;
    float score = -FLT_MAX;
    for (int k = 0; k < num_class; k++)
    {
        float confidence = scores[k];
        if (confidence > score)
        {
            label = k;
            score = confidence;
        }
    }
    float box_prob = sigmoid(score);
    if (box_prob >= prob_threshold)
    {
        ncnn::Mat bbox_pred(reg_max_1, 4, (void*)pred.row(i));
        {
            ncnn::Layer* softmax = ncnn::create_layer("Softmax");

            ncnn::ParamDict pd;
            pd.set(0, 1); // axis
            pd.set(1, 1);
            softmax->load_param(pd);

            ncnn::Option opt;
            opt.num_threads = 1;
            opt.use_packing_layout = false;

            softmax->create_pipeline(opt);

            softmax->forward_inplace(bbox_pred, opt);

            softmax->destroy_pipeline(opt);

            delete softmax;
        }

        float pred_ltrb[4];
        for (int k = 0; k < 4; k++)
        {
            float dis = 0.f;
            const float* dis_after_sm = bbox_pred.row(k);
            for (int l = 0; l < reg_max_1; l++)
            {
                dis += l * dis_after_sm[l];
            }

            pred_ltrb[k] = dis * grid_strides[i].stride;
        }

        float pb_cx = (grid_strides[i].grid0 + 0.5f) * grid_strides[i].stride;
        float pb_cy = (grid_strides[i].grid1 + 0.5f) * grid_strides[i].stride;

        float x0 = pb_cx - pred_ltrb[0];
        float y0 = pb_cy - pred_ltrb[1];
        float x1 = pb_cx + pred_ltrb[2];
        float y1 = pb_cy + pred_ltrb[3];

        Object obj;
        obj.rect.x = x0;
        obj.rect.y = y0;
        obj.rect.width = x1 - x0;
        obj.rect.height = y1 - y0;
        obj.label = label;
        obj.prob = box_prob;
        objects.push_back(obj);
    }
}
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