Skip to content

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

@caiyongrt

Description

@caiyongrt

识别类型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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions