Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
f1c1ec72
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f1c1ec72
编写于
8月 03, 2020
作者:
C
cjh9368
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
benchmark print model name, calculate benchmark accuracy formula
上级
8ff7c0b6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
23 deletion
+35
-23
mindspore/lite/tools/benchmark/benchmark.cc
mindspore/lite/tools/benchmark/benchmark.cc
+33
-20
mindspore/lite/tools/benchmark/benchmark.h
mindspore/lite/tools/benchmark/benchmark.h
+2
-3
未找到文件。
mindspore/lite/tools/benchmark/benchmark.cc
浏览文件 @
f1c1ec72
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <cmath>
#include <cmath>
#include <algorithm>
#include <algorithm>
#include <utility>
#include <utility>
#include <cfloat>
#include "src/common/common.h"
#include "src/common/common.h"
#include "include/ms_tensor.h"
#include "include/ms_tensor.h"
#include "include/context.h"
#include "include/context.h"
...
@@ -191,11 +192,16 @@ float Benchmark::CompareData(const std::string &nodeName, std::vector<int> msSha
...
@@ -191,11 +192,16 @@ float Benchmark::CompareData(const std::string &nodeName, std::vector<int> msSha
std
::
cout
<<
msTensorData
[
j
]
<<
" "
;
std
::
cout
<<
msTensorData
[
j
]
<<
" "
;
}
}
if
(
std
::
isnan
(
msTensorData
[
j
])
||
std
::
isinf
(
msTensorData
[
j
]))
{
MS_LOG
(
ERROR
)
<<
"Output tensor has nan or inf data, compare fail"
;
return
RET_ERROR
;
}
auto
tolerance
=
absoluteTolerance
+
relativeTolerance
*
fabs
(
calibTensor
->
data
.
at
(
j
));
auto
tolerance
=
absoluteTolerance
+
relativeTolerance
*
fabs
(
calibTensor
->
data
.
at
(
j
));
auto
absoluteError
=
std
::
fabs
(
msTensorData
[
j
]
-
calibTensor
->
data
.
at
(
j
));
auto
absoluteError
=
std
::
fabs
(
msTensorData
[
j
]
-
calibTensor
->
data
.
at
(
j
));
if
(
absoluteError
>
tolerance
)
{
if
(
absoluteError
>
tolerance
)
{
// just assume that atol = rtol
// just assume that atol = rtol
meanError
+=
absoluteError
/
(
fabs
(
calibTensor
->
data
.
at
(
j
))
+
1
);
meanError
+=
absoluteError
/
(
fabs
(
calibTensor
->
data
.
at
(
j
))
+
FLT_MIN
);
errorCount
++
;
errorCount
++
;
}
}
}
}
...
@@ -296,16 +302,10 @@ int Benchmark::MarkPerformance() {
...
@@ -296,16 +302,10 @@ int Benchmark::MarkPerformance() {
}
}
if
(
_flags
->
loopCount
>
0
)
{
if
(
_flags
->
loopCount
>
0
)
{
timeAvg
/=
_flags
->
loopCount
;
timeAvg
/=
_flags
->
loopCount
;
// MS_LOG(INFO) << "CSV:%s:%d:%f:%f:%f\n", _flags->modelPath.substr(_flags->modelPath.find_last_of(DELIM_SLASH) +
MS_LOG
(
INFO
)
<<
"Model = "
<<
_flags
->
modelPath
.
substr
(
_flags
->
modelPath
.
find_last_of
(
DELIM_SLASH
)
+
1
).
c_str
()
// 1).c_str(),
<<
", NumThreads = "
<<
_flags
->
numThreads
<<
", MinRunTime = "
<<
timeMin
/
1000.0
f
// _flags->numThreads, timeMin / 1000.0f, timeMax / 1000.0f, timeAvg / 1000.0f);
<<
", MaxRuntime = "
<<
timeMax
/
1000.0
f
<<
", AvgRunTime = "
<<
timeAvg
/
1000.0
f
;
// MS_LOG(INFO) <<"Modle = %s, numThreads = %d, MinRunTime = %f ms, MaxRuntime = %f ms, AvgRunTime = %f ms",
printf
(
"Model = %s, NumThreads = %d, MinRunTime = %f ms, MaxRuntime = %f ms, AvgRunTime = %f ms
\n
"
,
// _flags->modelPath.substr(_flags->modelPath.find_last_of(DELIM_SLASH) + 1).c_str(), _flags->numThreads,
// timeMin / 1000.0f, timeMax / 1000.0f, timeAvg / 1000.0f);
printf
(
"CSV:%s:%d:%f:%f:%f
\n
"
,
_flags
->
modelPath
.
substr
(
_flags
->
modelPath
.
find_last_of
(
DELIM_SLASH
)
+
1
).
c_str
(),
_flags
->
numThreads
,
timeMin
/
1000.0
f
,
timeMax
/
1000.0
f
,
timeAvg
/
1000.0
f
);
printf
(
"Modle = %s, numThreads = %d, MinRunTime = %f ms, MaxRuntime = %f ms, AvgRunTime = %f ms
\n
"
,
_flags
->
modelPath
.
substr
(
_flags
->
modelPath
.
find_last_of
(
DELIM_SLASH
)
+
1
).
c_str
(),
_flags
->
numThreads
,
_flags
->
modelPath
.
substr
(
_flags
->
modelPath
.
find_last_of
(
DELIM_SLASH
)
+
1
).
c_str
(),
_flags
->
numThreads
,
timeMin
/
1000.0
f
,
timeMax
/
1000.0
f
,
timeAvg
/
1000.0
f
);
timeMin
/
1000.0
f
,
timeMax
/
1000.0
f
,
timeAvg
/
1000.0
f
);
}
}
...
@@ -325,13 +325,22 @@ int Benchmark::MarkAccuracy() {
...
@@ -325,13 +325,22 @@ int Benchmark::MarkAccuracy() {
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
}
}
auto
status
=
session
->
RunGraph
();
auto
status
=
session
->
RunGraph
();
if
(
status
!=
0
)
{
if
(
status
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Inference error %d"
<<
status
;
MS_LOG
(
ERROR
)
<<
"Inference error "
<<
status
;
return
status
;
}
status
=
ReadCalibData
();
if
(
status
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Read calib data error "
<<
status
;
return
status
;
return
status
;
}
}
ReadCalibData
();
status
=
CompareOutput
();
CompareOutput
();
if
(
status
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Compare output error "
<<
status
;
return
status
;
}
return
0
;
return
0
;
}
}
...
@@ -371,10 +380,10 @@ int Benchmark::RunBenchmark(const std::string &deviceType) {
...
@@ -371,10 +380,10 @@ int Benchmark::RunBenchmark(const std::string &deviceType) {
msInputs
=
session
->
GetInputs
();
msInputs
=
session
->
GetInputs
();
auto
endPrepareTime
=
GetTimeUs
();
auto
endPrepareTime
=
GetTimeUs
();
#if defined(__arm__)
#if defined(__arm__)
MS_LOG
(
INFO
)
<<
"PrepareTime =
%lld ms, "
<<
(
endPrepareTime
-
startPrepareTime
)
/
1000
;
MS_LOG
(
INFO
)
<<
"PrepareTime =
"
<<
(
endPrepareTime
-
startPrepareTime
)
/
1000
<<
" ms"
;
printf
(
"PrepareTime = %lld ms, "
,
(
endPrepareTime
-
startPrepareTime
)
/
1000
);
printf
(
"PrepareTime = %lld ms, "
,
(
endPrepareTime
-
startPrepareTime
)
/
1000
);
#else
#else
MS_LOG
(
INFO
)
<<
"PrepareTime =
%ld ms, "
<<
(
endPrepareTime
-
startPrepareTime
)
/
1000
;
MS_LOG
(
INFO
)
<<
"PrepareTime =
"
<<
(
endPrepareTime
-
startPrepareTime
)
/
1000
<<
" ms "
;
printf
(
"PrepareTime = %ld ms, "
,
(
endPrepareTime
-
startPrepareTime
)
/
1000
);
printf
(
"PrepareTime = %ld ms, "
,
(
endPrepareTime
-
startPrepareTime
)
/
1000
);
#endif
#endif
...
@@ -383,18 +392,21 @@ int Benchmark::RunBenchmark(const std::string &deviceType) {
...
@@ -383,18 +392,21 @@ int Benchmark::RunBenchmark(const std::string &deviceType) {
auto
status
=
LoadInput
();
auto
status
=
LoadInput
();
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
MS_LOG
(
ERROR
)
<<
"Generate input data error"
;
MS_LOG
(
ERROR
)
<<
"Generate input data error"
;
delete
graphBuf
;
return
status
;
return
status
;
}
}
if
(
!
_flags
->
calibDataPath
.
empty
())
{
if
(
!
_flags
->
calibDataPath
.
empty
())
{
status
=
MarkAccuracy
();
status
=
MarkAccuracy
();
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
MS_LOG
(
ERROR
)
<<
"Run MarkAccuracy error: %d"
<<
status
;
MS_LOG
(
ERROR
)
<<
"Run MarkAccuracy error: %d"
<<
status
;
delete
graphBuf
;
return
status
;
return
status
;
}
}
}
else
{
}
else
{
status
=
MarkPerformance
();
status
=
MarkPerformance
();
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
MS_LOG
(
ERROR
)
<<
"Run MarkPerformance error: %d"
<<
status
;
MS_LOG
(
ERROR
)
<<
"Run MarkPerformance error: %d"
<<
status
;
delete
graphBuf
;
return
status
;
return
status
;
}
}
}
}
...
@@ -509,13 +521,14 @@ int RunBenchmark(int argc, const char **argv) {
...
@@ -509,13 +521,14 @@ int RunBenchmark(int argc, const char **argv) {
}
}
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
MS_LOG
(
ERROR
)
<<
"Run Benchmark Error : "
<<
status
;
MS_LOG
(
ERROR
)
<<
"Run Benchmark "
<<
flags
.
modelPath
.
substr
(
flags
.
modelPath
.
find_last_of
(
DELIM_SLASH
)
+
1
).
c_str
()
<<
" Failed : "
<<
status
;
return
1
;
return
1
;
}
}
MS_LOG
(
INFO
)
<<
"end of benchmark"
;
MS_LOG
(
INFO
)
<<
"Run Benchmark "
<<
flags
.
modelPath
.
substr
(
flags
.
modelPath
.
find_last_of
(
DELIM_SLASH
)
+
1
).
c_str
()
<<
" Success."
;
return
0
;
return
0
;
}
}
}
// namespace lite
}
// namespace lite
}
// namespace mindspore
}
// namespace mindspore
mindspore/lite/tools/benchmark/benchmark.h
浏览文件 @
f1c1ec72
...
@@ -37,8 +37,8 @@
...
@@ -37,8 +37,8 @@
namespace
mindspore
::
lite
{
namespace
mindspore
::
lite
{
enum
MS_API
InDataType
{
kImage
=
0
,
kBinary
=
1
};
enum
MS_API
InDataType
{
kImage
=
0
,
kBinary
=
1
};
constexpr
float
relativeTolerance
=
0.01
;
constexpr
float
relativeTolerance
=
1e-5
;
constexpr
float
absoluteTolerance
=
0.01
;
constexpr
float
absoluteTolerance
=
1e-8
;
struct
MS_API
CheckTensor
{
struct
MS_API
CheckTensor
{
CheckTensor
(
const
std
::
vector
<
size_t
>
&
shape
,
const
std
::
vector
<
float
>
&
data
)
{
CheckTensor
(
const
std
::
vector
<
size_t
>
&
shape
,
const
std
::
vector
<
float
>
&
data
)
{
...
@@ -143,4 +143,3 @@ class MS_API Benchmark {
...
@@ -143,4 +143,3 @@ class MS_API Benchmark {
int
MS_API
RunBenchmark
(
int
argc
,
const
char
**
argv
);
int
MS_API
RunBenchmark
(
int
argc
,
const
char
**
argv
);
}
// namespace mindspore::lite
}
// namespace mindspore::lite
#endif // MINNIE_BENCHMARK_BENCHMARK_H_
#endif // MINNIE_BENCHMARK_BENCHMARK_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录