Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
as350144
Mace
提交
b4f79b94
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,发现更多精彩内容 >>
提交
b4f79b94
编写于
12月 20, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Minor fix for mace_run.cc
上级
29a66673
变更
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
浏览文件 @
b4f79b94
...
@@ -12,10 +12,10 @@
...
@@ -12,10 +12,10 @@
* --output_file=mace.out \
* --output_file=mace.out \
* --device=NEON
* --device=NEON
*/
*/
#include <sys/time.h>
#include <fstream>
#include <fstream>
#include "mace/core/net.h"
#include "mace/core/net.h"
#include "mace/utils/command_line_flags.h"
#include "mace/utils/command_line_flags.h"
#include "mace/utils/env_time.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
mace
;
using
namespace
mace
;
...
@@ -90,20 +90,40 @@ int main(int argc, char **argv) {
...
@@ -90,20 +90,40 @@ int main(int argc, char **argv) {
vector
<
index_t
>
shape
;
vector
<
index_t
>
shape
;
ParseShape
(
input_shape
,
&
shape
);
ParseShape
(
input_shape
,
&
shape
);
// load model
int64_t
t0
=
utils
::
NowMicros
();
// ifstream file_stream(model_file, ios::in | ios::binary);
// NetDef net_def;
// net_def.ParseFromIstream(&file_stream);
// file_stream.close();
NetDef
net_def
=
mace
::
MACE_MODEL_FUNCTION
();
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
);
DeviceType
device_type
=
ParseDeviceType
(
device
);
VLOG
(
0
)
<<
device_type
;
VLOG
(
1
)
<<
"Device Type"
<<
device_type
;
Workspace
ws
;
Workspace
ws
;
ws
.
LoadModelTensor
(
net_def
,
device_type
);
ws
.
LoadModelTensor
(
net_def
,
device_type
);
Tensor
*
input_tensor
=
Tensor
*
input_tensor
=
ws
.
CreateTensor
(
input_node
+
":0"
,
GetDeviceAllocator
(
device_type
),
DT_FLOAT
);
ws
.
CreateTensor
(
input_node
+
":0"
,
GetDeviceAllocator
(
device_type
),
DT_FLOAT
);
input_tensor
->
Resize
(
shape
);
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
);
Tensor
::
MappingGuard
input_guard
(
input_tensor
);
float
*
input_data
=
input_tensor
->
mutable_data
<
float
>
();
float
*
input_data
=
input_tensor
->
mutable_data
<
float
>
();
...
@@ -115,34 +135,20 @@ int main(int argc, char **argv) {
...
@@ -115,34 +135,20 @@ int main(int argc, char **argv) {
in_file
.
close
();
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
// warm up
for
(
int
i
=
0
;
i
<
1
;
++
i
)
{
VLOG
(
0
)
<<
"Warm up"
;
net
->
Run
();
t0
=
utils
::
NowMicros
();
}
net
->
Run
();
t1
=
utils
::
NowMicros
();
LOG
(
INFO
)
<<
"1st run duration: "
<<
t1
-
t0
<<
"us"
;
VLOG
(
0
)
<<
"run"
;
VLOG
(
0
)
<<
"Run"
;
timeval
tv1
,
tv2
;
t0
=
utils
::
NowMicros
();
gettimeofday
(
&
tv1
,
NULL
);
for
(
int
i
=
0
;
i
<
round
;
++
i
)
{
for
(
int
i
=
0
;
i
<
round
;
++
i
)
{
net
->
Run
();
net
->
Run
();
}
}
gettimeofday
(
&
tv2
,
NULL
);
t1
=
utils
::
NowMicros
();
cout
<<
"avg duration: "
LOG
(
INFO
)
<<
"Average duration: "
<<
(
t1
-
t0
)
/
round
<<
"us"
;
<<
((
tv2
.
tv_sec
-
tv1
.
tv_sec
)
*
1000
+
(
tv2
.
tv_usec
-
tv1
.
tv_usec
)
/
1000
)
/
round
<<
endl
;
// save output
// save output
const
Tensor
*
output
=
ws
.
GetTensor
(
output_node
+
":0"
);
const
Tensor
*
output
=
ws
.
GetTensor
(
output_node
+
":0"
);
...
@@ -159,9 +165,8 @@ int main(int argc, char **argv) {
...
@@ -159,9 +165,8 @@ int main(int argc, char **argv) {
ss
<<
"Output shape: ["
;
ss
<<
"Output shape: ["
;
for
(
int
i
=
0
;
i
<
output
->
dim_size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
output
->
dim_size
();
++
i
)
{
ss
<<
output
->
dim
(
i
)
<<
", "
;
ss
<<
output
->
dim
(
i
)
<<
", "
;
}
}
ss
<<
"]"
;
ss
<<
"]"
;
VLOG
(
0
)
<<
ss
.
str
();
VLOG
(
0
)
<<
ss
.
str
();
}
}
}
}
\ No newline at end of file
tools/validate.py
浏览文件 @
b4f79b94
...
@@ -37,10 +37,10 @@ def valid_output(out_shape, mace_out_file, tf_out_value):
...
@@ -37,10 +37,10 @@ def valid_output(out_shape, mace_out_file, tf_out_value):
if
mace_out_value
.
size
!=
0
:
if
mace_out_value
.
size
!=
0
:
similarity
=
(
1
-
spatial
.
distance
.
cosine
(
tf_out_value
.
flat
,
mace_out_value
))
similarity
=
(
1
-
spatial
.
distance
.
cosine
(
tf_out_value
.
flat
,
mace_out_value
))
print
'MACE VS TF similarity: '
,
similarity
print
'MACE VS TF similarity: '
,
similarity
if
similarity
>
0.99
9
:
if
similarity
>
0.99
5
:
print
'=======================
Passed! Haha
======================'
print
'=======================
Similarity Test Passed
======================'
mace_out_value
=
mace_out_value
.
reshape
(
out_shape
)
else
:
np
.
testing
.
assert_allclose
(
mace_out_value
,
tf_out_value
,
rtol
=
0.05
)
print
'=======================Similarity Test Failed======================'
else
:
else
:
print
'=======================Skip empty node==================='
print
'=======================Skip empty node==================='
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录