Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_onnxruntime
Commits
9ad2a12b
Commit
9ad2a12b
authored
Oct 20, 2023
by
yangql
Browse files
Update main.cpp
parent
ee004690
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletion
+23
-1
Src/main.cpp
Src/main.cpp
+23
-1
No files found.
Src/main.cpp
View file @
9ad2a12b
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include <SimpleLog.h>
#include <SimpleLog.h>
#include <Filesystem.h>
#include <Filesystem.h>
#include <Classifier.h>
#include <Classifier.h>
#include <iostream>
#include <fstream>
int
main
()
int
main
()
{
{
...
@@ -37,7 +39,14 @@ int main()
...
@@ -37,7 +39,14 @@ int main()
double
time2
=
cv
::
getTickCount
();
double
time2
=
cv
::
getTickCount
();
double
elapsedTime
=
(
time2
-
time1
)
*
1000
/
cv
::
getTickFrequency
();
double
elapsedTime
=
(
time2
-
time1
)
*
1000
/
cv
::
getTickFrequency
();
LOG_INFO
(
stdout
,
"inference time:%f ms
\n
"
,
elapsedTime
);
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
"
);
LOG_INFO
(
stdout
,
"========== Classification Results ==========
\n
"
);
for
(
int
i
=
0
;
i
<
predictions
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
predictions
.
size
();
++
i
)
...
@@ -45,11 +54,24 @@ int main()
...
@@ -45,11 +54,24 @@ int main()
// 一个batch中第i幅图像的结果
// 一个batch中第i幅图像的结果
LOG_INFO
(
stdout
,
"========== %d result ==========
\n
"
,
i
);
LOG_INFO
(
stdout
,
"========== %d result ==========
\n
"
,
i
);
std
::
vector
<
ortSamples
::
ResultOfPrediction
>
resultOfPredictions
=
predictions
[
i
];
std
::
vector
<
ortSamples
::
ResultOfPrediction
>
resultOfPredictions
=
predictions
[
i
];
double
maxConfidence
=
-
DBL_MAX
;
int
maxLabel
=
-
1
;
for
(
int
j
=
0
;
j
<
resultOfPredictions
.
size
();
++
j
)
for
(
int
j
=
0
;
j
<
resultOfPredictions
.
size
();
++
j
)
{
{
ortSamples
::
ResultOfPrediction
prediction
=
resultOfPredictions
[
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
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment