Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
as350144
Mace
提交
6e617b6d
Mace
项目概览
as350144
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
2
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6e617b6d
编写于
12月 20, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'mace_run' into 'master'
Minor fix for mace_run.cc See merge request !171
上级
29a66673
b4f79b94
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
36 deletion
+41
-36
mace/examples/mace_run.cc
mace/examples/mace_run.cc
+37
-32
tools/validate.py
tools/validate.py
+4
-4
未找到文件。
mace/examples/mace_run.cc
浏览文件 @
6e617b6d
...
...
@@ -12,10 +12,10 @@
* --output_file=mace.out \
* --device=NEON
*/
#include <sys/time.h>
#include <fstream>
#include "mace/core/net.h"
#include "mace/utils/command_line_flags.h"
#include "mace/utils/env_time.h"
using
namespace
std
;
using
namespace
mace
;
...
...
@@ -90,20 +90,40 @@ int main(int argc, char **argv) {
vector
<
index_t
>
shape
;
ParseShape
(
input_shape
,
&
shape
);
// load model
// ifstream file_stream(model_file, ios::in | ios::binary);
// NetDef net_def;
// net_def.ParseFromIstream(&file_stream);
// file_stream.close();
int64_t
t0
=
utils
::
NowMicros
();
NetDef
net_def
=
mace
::
MACE_MODEL_FUNCTION
();
int64_t
t1
=
utils
::
NowMicros
();
LOG
(
INFO
)
<<
"CreateNetDef duration: "
<<
t1
-
t0
<<
"us"
;
int64_t
init_micros
=
t1
-
t0
;
t0
=
utils
::
NowMicros
();
DeviceType
device_type
=
ParseDeviceType
(
device
);
VLOG
(
0
)
<<
device_type
;
VLOG
(
1
)
<<
"Device Type"
<<
device_type
;
Workspace
ws
;
ws
.
LoadModelTensor
(
net_def
,
device_type
);
Tensor
*
input_tensor
=
ws
.
CreateTensor
(
input_node
+
":0"
,
GetDeviceAllocator
(
device_type
),
DT_FLOAT
);
input_tensor
->
Resize
(
shape
);
t1
=
utils
::
NowMicros
();
init_micros
+=
t1
-
t0
;
LOG
(
INFO
)
<<
"CreateWorkspaceTensor duration: "
<<
t1
-
t0
<<
"us"
;
// Init model
VLOG
(
0
)
<<
"Run init"
;
t0
=
utils
::
NowMicros
();
auto
net
=
CreateNet
(
net_def
,
&
ws
,
device_type
,
NetMode
::
INIT
);
net
->
Run
();
t1
=
utils
::
NowMicros
();
init_micros
+=
t1
-
t0
;
LOG
(
INFO
)
<<
"Net init duration: "
<<
t1
-
t0
<<
"us"
;
// run model
t0
=
utils
::
NowMicros
();
net
=
CreateNet
(
net_def
,
&
ws
,
device_type
);
t1
=
utils
::
NowMicros
();
init_micros
+=
t1
-
t0
;
LOG
(
INFO
)
<<
"Total init duration: "
<<
init_micros
<<
"us"
;
{
Tensor
::
MappingGuard
input_guard
(
input_tensor
);
float
*
input_data
=
input_tensor
->
mutable_data
<
float
>
();
...
...
@@ -115,34 +135,20 @@ int main(int argc, char **argv) {
in_file
.
close
();
}
// Init model
VLOG
(
0
)
<<
"Run init"
;
auto
net
=
CreateNet
(
net_def
,
&
ws
,
device_type
,
NetMode
::
INIT
);
net
->
Run
();
VLOG
(
0
)
<<
"Run model"
;
// run model
net
=
CreateNet
(
net_def
,
&
ws
,
device_type
);
VLOG
(
0
)
<<
"warm up"
;
// warm up
for
(
int
i
=
0
;
i
<
1
;
++
i
)
{
net
->
Run
();
}
VLOG
(
0
)
<<
"Warm up"
;
t0
=
utils
::
NowMicros
();
net
->
Run
();
t1
=
utils
::
NowMicros
();
LOG
(
INFO
)
<<
"1st run duration: "
<<
t1
-
t0
<<
"us"
;
VLOG
(
0
)
<<
"run"
;
timeval
tv1
,
tv2
;
gettimeofday
(
&
tv1
,
NULL
);
VLOG
(
0
)
<<
"Run"
;
t0
=
utils
::
NowMicros
();
for
(
int
i
=
0
;
i
<
round
;
++
i
)
{
net
->
Run
();
}
gettimeofday
(
&
tv2
,
NULL
);
cout
<<
"avg duration: "
<<
((
tv2
.
tv_sec
-
tv1
.
tv_sec
)
*
1000
+
(
tv2
.
tv_usec
-
tv1
.
tv_usec
)
/
1000
)
/
round
<<
endl
;
t1
=
utils
::
NowMicros
();
LOG
(
INFO
)
<<
"Average duration: "
<<
(
t1
-
t0
)
/
round
<<
"us"
;
// save output
const
Tensor
*
output
=
ws
.
GetTensor
(
output_node
+
":0"
);
...
...
@@ -159,9 +165,8 @@ int main(int argc, char **argv) {
ss
<<
"Output shape: ["
;
for
(
int
i
=
0
;
i
<
output
->
dim_size
();
++
i
)
{
ss
<<
output
->
dim
(
i
)
<<
", "
;
}
ss
<<
"]"
;
VLOG
(
0
)
<<
ss
.
str
();
}
}
\ No newline at end of file
}
tools/validate.py
浏览文件 @
6e617b6d
...
...
@@ -37,10 +37,10 @@ def valid_output(out_shape, mace_out_file, tf_out_value):
if
mace_out_value
.
size
!=
0
:
similarity
=
(
1
-
spatial
.
distance
.
cosine
(
tf_out_value
.
flat
,
mace_out_value
))
print
'MACE VS TF similarity: '
,
similarity
if
similarity
>
0.99
9
:
print
'=======================
Passed! Haha
======================'
mace_out_value
=
mace_out_value
.
reshape
(
out_shape
)
np
.
testing
.
assert_allclose
(
mace_out_value
,
tf_out_value
,
rtol
=
0.05
)
if
similarity
>
0.99
5
:
print
'=======================
Similarity Test Passed
======================'
else
:
print
'=======================Similarity Test Failed======================'
else
:
print
'=======================Skip empty node==================='
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录