Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
279139fc
Mace
项目概览
慢慢CG
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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看板
提交
279139fc
编写于
12月 19, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix source converter bug for ndk 12 and move create op to single file.
上级
bf8531f2
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
96 addition
and
56 deletion
+96
-56
mace/examples/BUILD
mace/examples/BUILD
+1
-1
mace/python/tools/model.template
mace/python/tools/model.template
+78
-53
mace/python/tools/source_converter_lib.py
mace/python/tools/source_converter_lib.py
+16
-1
tools/validate_gcn.sh
tools/validate_gcn.sh
+1
-1
未找到文件。
mace/examples/BUILD
浏览文件 @
279139fc
...
...
@@ -31,7 +31,7 @@ cc_test(
cc_binary
(
name
=
"mace_run"
,
srcs
=
glob
([
"models/*/*.cc"
]
+
[
"mace_run.cc"
]),
copts
=
[
"-std=c++11"
,
"-D_GLIBCXX_USE_C99_MATH_TR1"
,
"-v"
,
"-ftime-report"
],
copts
=
[
"-std=c++11"
,
"-D_GLIBCXX_USE_C99_MATH_TR1"
],
linkopts
=
[
"-fopenmp"
],
linkstatic
=
1
,
deps
=
[
...
...
mace/python/tools/model.template
浏览文件 @
279139fc
...
...
@@ -12,41 +12,47 @@ alignas(4) unsigned char {{ tensor.name }}[] = {
};
} // namespace {{tag}}
{% else %}
{% elif mode == 1 %}
#include <vector>
#include <string>
#include "mace/core/mace.h"
namespace {{tag}} {
{% for tensor in tensors %}
extern unsigned char {{ tensor.name }}[];
{% endfor %}
namespace {
static void UpdateOp(mace::OperatorDef &op,
const std::string &name,
const std::string &type,
const std::vector<std::string> &inputs,
const std::vector<std::string> &outputs,
const std::vector<mace::DataType> &output_types) {
op.set_name(name);
op.set_type(type);
op.set_input(inputs);
op.set_output(outputs);
op.set_output_type(output_types);
}
}
} // namespace {{ tag }}
namespace {{tag}}{
namespace {
{% for i in range(start, end) %}
{% if net.arg|length != 0 %}
static void CreateNetArg(mace::NetDef &net_def) {
net_def.mutable_arg().reserve({{ net.arg|length }});
void CreateOperator{{i}}(mace::OperatorDef &op) {
mace::Argument *arg = nullptr;
{% for arg in net.arg %}
{% for arg in net.
op[i].
arg %}
arg =
net_def
.add_arg();
arg =
op
.add_arg();
arg->set_name({{ arg.name|tojson }});
{%- if arg.HasField('f') %}
arg->set_f({{ arg.f }});
{% endif %}
{%- endif %}
{%- if arg.HasField('i') %}
arg->set_i({{ arg.i }});
{% endif %}
{%- endif %}
{%- if arg.HasField('s') %}
arg->set_s({{ arg.s|tojson }});
{% endif %}
{%
-
endif %}
{% if arg.floats|length != 0 %}
arg->set_floats({ {{ arg.floats|join(', ') }} });
...
...
@@ -57,43 +63,68 @@ static void CreateNetArg(mace::NetDef &net_def) {
{% if arg.strings|length != 0 %}
arg->set_strings({ {{ arg.strings|stringfy() }} });
{% endif %}
{% endfor %}
{% if net.op[i].HasField('mem_id') %}
op.set_mem_id({{net.op[i].mem_id}});
{% endif %}
{% for shape in net.op[i].output_shape %}
op.add_output_shape(mace::OutputShape({ {{ shape.dims|join(', ') }} }));
{% endfor %}
}
{% endif %}
UpdateOp(op, {{ net.op[i].name|tojson }}, {{ net.op[i].type|tojson}},
{ {{ net.op[i].input|stringfy }} },
{ {{ net.op[i].output|stringfy }} },
{ {{ net.op[i].output_type|join(', ') }} });
static void UpdateOp(mace::OperatorDef &op,
const std::string &name,
const std::string &type,
const std::vector<std::string> &inputs,
const std::vector<std::string> &outputs,
const std::vector<mace::DataType> &output_types) {
op.set_name(name);
op.set_type(type);
op.set_input(inputs);
op.set_output(outputs);
op.set_output_type(output_types);
}
static void CreateOperators(std::vector<mace::OperatorDef> &ops) {
ops.resize({{ net.op|length }});
{% endfor %}
} // namespace {{tag}}
{% else %}
#include <vector>
#include <string>
#include "mace/core/mace.h"
namespace {{tag}} {
{% for tensor in tensors %}
extern unsigned char {{ tensor.name }}[];
{% endfor %}
{% for i in range(net.op|length) %}
extern void CreateOperator{{i}}(mace::OperatorDef &op);
{% endfor %}
} // namespace {{ tag }}
namespace {
{% if net.arg|length != 0 %}
static void CreateNetArg(mace::NetDef &net_def) {
net_def.mutable_arg().reserve({{ net.arg|length }});
mace::Argument *arg = nullptr;
{% for i in range(net.op|length) %}
{% for arg in net.op[i].arg %}
{% for arg in net.arg %}
arg =
ops[{{i}}]
.add_arg();
arg =
net_def
.add_arg();
arg->set_name({{ arg.name|tojson }});
{%- if arg.HasField('f') %}
arg->set_f({{ arg.f }});
{%- endif %}
{% endif %}
{%- if arg.HasField('i') %}
arg->set_i({{ arg.i }});
{%- endif %}
{% endif %}
{%- if arg.HasField('s') %}
arg->set_s({{ arg.s|tojson }});
{%
-
endif %}
{% endif %}
{% if arg.floats|length != 0 %}
arg->set_floats({ {{ arg.floats|join(', ') }} });
...
...
@@ -104,21 +135,18 @@ static void CreateOperators(std::vector<mace::OperatorDef> &ops) {
{% if arg.strings|length != 0 %}
arg->set_strings({ {{ arg.strings|stringfy() }} });
{% endif %}
{% endfor %}
{% if net.op[i].HasField('mem_id') %}
ops[{{i}}].set_mem_id({{net.op[i].mem_id}});
{% endif %}
}
{% endif %}
{% for shape in net.op[i].output_shape %}
ops[{{i}}].add_output_shape(mace::OutputShape({ {{ shape.dims|join(', ') }} }));
{% endfor %}
UpdateOp(ops[{{i}}], {{ net.op[i].name|tojson }}, {{ net.op[i].type|tojson}},
{ {{ net.op[i].input|stringfy }} },
{ {{ net.op[i].output|stringfy }} },
{ {{ net.op[i].output_type|join(', ') }} });
static void CreateOperators(std::vector<mace::OperatorDef> &ops) {
ops.resize({{ net.op|length }});
{% for i in range(net.op|length) %}
{{tag}}::CreateOperator{{i}}(ops[{{i}}]);
{% endfor %}
}
...
...
@@ -130,10 +158,7 @@ static void CreateTensors(std::vector<mace::TensorProto> &tensors) {
tensors.emplace_back(mace::TensorProto(
{{ tensor.name|tojson }}, {{ tag + '::' + tensor.name }},
{ {{ tensor.dims|join(', ') }} }, {{ tensor.data_type }},
{{ tensor.node_id }}
));
{ {{ tensor.dims|join(', ') }} }, {{ tensor.data_type }}, {{ tensor.node_id }}));
{% endfor %}
}
...
...
mace/python/tools/source_converter_lib.py
浏览文件 @
279139fc
...
...
@@ -110,13 +110,28 @@ def convert_to_source(net_def, template, confuse, model_tag, output):
f
.
write
(
source
)
counter
+=
1
# generate op source files
counter
=
0
op_size
=
len
(
net_def
.
op
)
for
start
in
range
(
0
,
op_size
,
10
):
source
=
j2_env
.
get_template
(
template_name
).
render
(
start
=
start
,
end
=
min
(
start
+
10
,
op_size
),
net
=
net_def
,
tag
=
model_tag
,
mode
=
1
)
with
gfile
.
GFile
(
output_dir
+
'op'
+
str
(
counter
)
+
'.cc'
,
"wb"
)
as
f
:
f
.
write
(
source
)
counter
+=
1
# generate model source files
tensors
=
[
TensorInfo
(
t
)
for
t
in
net_def
.
tensors
]
source
=
j2_env
.
get_template
(
template_name
).
render
(
tensors
=
tensors
,
net
=
net_def
,
tag
=
model_tag
,
mode
=
1
mode
=
2
)
with
gfile
.
GFile
(
output
,
"wb"
)
as
f
:
f
.
write
(
source
)
tools/validate_gcn.sh
浏览文件 @
279139fc
...
...
@@ -30,8 +30,8 @@ python tools/validate.py --generate_data true --random_seed 1 \
# Step 2: convert tf model to mace model
echo
"Step 2: convert tf model to mace model and optimize memory"
echo
$MACE_SOURCE_DIR
bazel build //mace/python/tools:tf_converter
rm
-rf
${
MACE_SOURCE_DIR
}
/mace/examples/models/gcn
mkdir
-p
${
MACE_SOURCE_DIR
}
/mace/examples/models/gcn
bazel-bin/mace/python/tools/tf_converter
--input
=
${
TF_MODEL_FILE_PATH
}
\
--output
=
${
MACE_SOURCE_DIR
}
/mace/examples/models/gcn/mace_gcn.cc
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录