spacewalk01/tensorrt-yolov9

Customize with data 3 classes

ThanhPham1987 opened this issue · 5 comments

Hi @spacewalk01 ,
I build model with 3 classes and convert to .engine. After converted to engine. I changed like this:

const vector coconame = {
"class 1", "class 2", "class 3",
};

and changed int out_rows = 84;--> int out_rows = 7
in yolov9.cpp file.

I am facing problem:

terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.8.0) /home/velox/opencv/modules/core/src/matrix.cpp:766: error: (-215:Assertion failed) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function 'Mat'

Aborted (core dumped)

Do you know how to solve?
PeterPham

Hi @ThanhPham1987 Will you make sure your onnx model output is like [1, 7, 8400]
image

Screenshot from 2024-03-04 16-35-35
Hi @spacewalk01 . yes, 1, 7, 8400. My output like this
Screenshot from 2024-03-04 16-33-15

You are modifying following code right:?

    int out_rows = 84;
    int out_cols = 8400;
    const cv::Mat det_output(out_rows, out_cols, CV_32F, (float*)mCpuBuffers[1]);

    for (int i = 0; i < det_output.cols; ++i) {
        const cv::Mat classes_scores = det_output.col(i).rowRange(4, 84);

Please change like following

const cv::Mat classes_scores = det_output.col(i).rowRange(4, 84); ->

const cv::Mat classes_scores = det_output.col(i).rowRange(4, 7);

Thanks