The inference statement used is this:
Mat score = net.forward("outputs");
The output format of the model is float [1x2x512x648]
The input image looks like this:
I can parse the correct results using these few codes.
cv::Mat output1(512, 648, CV_32F, (float*)score.data);
cv::Mat output2(512, 648, CV_32F, (float*)score.data+648*512);
cv::Mat sum = output2 - output1;
cv::threshold(sum, sum, 0, 255, cv::THRESH_BINARY);
But using the method I wrote myself, the parsing result is incorrect. May I know how to modify my code.
const int OUTPUT_H = 512;
const int OUTPUT_W = 648;
const int NUM_CLASSES = 2;
void postprocess(const uchar* output, Mat& result)
{
result.create(OUTPUT_H, OUTPUT_W, CV_8U);
//result.create(OUTPUT_H, OUTPUT_W, CV_32SC1);
for (int i = 0; i < OUTPUT_H; ++i) {
for (int j = 0; j < OUTPUT_W; ++j) {
int idx = i * OUTPUT_W + j;
int max_idx = -1;
float max_val = -FLT_MAX;
for (int k = 0; k < NUM_CLASSES; ++k) {
float val = output[idx * NUM_CLASSES + k];
if (val > max_val) {
max_val = val;
max_idx = k;
}
}
result.at<uint8_t>(i, j) = max_idx * 100;
//result.at<int>(i, j) = max_idx * 100;
}
}
}
// Postprocess output
Mat result;
postprocess(score.data, result);
please help me.
The src image,result image, output1 image, output2 image ,sum image like this: