Commit 9ad2a12b authored by yangql's avatar yangql
Browse files

Update main.cpp

parent ee004690
......@@ -4,6 +4,8 @@
#include <SimpleLog.h>
#include <Filesystem.h>
#include <Classifier.h>
#include <iostream>
#include <fstream>
int main()
{
......@@ -37,6 +39,13 @@ int main()
double time2 = cv::getTickCount();
double elapsedTime = (time2 - time1)*1000 / cv::getTickFrequency();
LOG_INFO(stdout, "inference time:%f ms\n", elapsedTime);
// 读取分类列表
std::ifstream file("../Resource/synset.txt");
if (!file.is_open()) {
std::cerr << "无法打开synset.txt文件" << std::endl;
return 1;
}
// 获取推理结果
LOG_INFO(stdout,"========== Classification Results ==========\n");
......@@ -45,11 +54,24 @@ int main()
// 一个batch中第i幅图像的结果
LOG_INFO(stdout,"========== %d result ==========\n",i);
std::vector<ortSamples::ResultOfPrediction> resultOfPredictions=predictions[i];
double maxConfidence = -DBL_MAX;
int maxLabel = -1;
for(int j=0;j<resultOfPredictions.size();++j)
{
ortSamples::ResultOfPrediction prediction=resultOfPredictions[j];
LOG_INFO(stdout,"label:%d,confidence:%f\n",prediction.label,prediction.confidence);
if (prediction.confidence > maxConfidence) {
maxConfidence = prediction.confidence;
maxLabel = prediction.label;
}
}
std::string line;
int currentLine = 0;
while (currentLine < maxLabel+1 && std::getline(file, line)) {
currentLine++;
}
LOG_INFO(stdout, "class=%s ;probability=%f\n", line.c_str(), maxConfidence);
}
file.close();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment