Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
ac0a6951
Mace
项目概览
冰之2023
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac0a6951
编写于
5月 21, 2018
作者:
Y
yejianwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support float in gpu
上级
1e95672a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
26 addition
and
9 deletion
+26
-9
mace/python/tools/converter.py
mace/python/tools/converter.py
+4
-1
mace/python/tools/source_converter_lib.py
mace/python/tools/source_converter_lib.py
+5
-5
tools/generate_model_code.sh
tools/generate_model_code.sh
+4
-0
tools/mace_tools.py
tools/mace_tools.py
+13
-3
未找到文件。
mace/python/tools/converter.py
浏览文件 @
ac0a6951
...
...
@@ -55,8 +55,11 @@ def main(unused_args):
FLAGS
.
data_type
,
FLAGS
.
runtime
,
FLAGS
.
winograd
)
if
FLAGS
.
output_type
==
'source'
:
gpu_data_type
=
""
if
FLAGS
.
runtime
==
'gpu'
:
gpu_data_type
=
FLAGS
.
data_type
source_converter_lib
.
convert_to_source
(
output_graph_def
,
model_checksum
,
FLAGS
.
template
,
FLAGS
.
obfuscate
,
FLAGS
.
model_tag
,
FLAGS
.
output
,
FLAGS
.
runtime
,
FLAGS
.
embed_model_data
)
FLAGS
.
model_tag
,
FLAGS
.
output
,
FLAGS
.
runtime
,
FLAGS
.
embed_model_data
,
gpu_data_type
)
else
:
with
open
(
FLAGS
.
output
,
"wb"
)
as
f
:
f
.
write
(
output_graph_def
.
SerializeToString
())
...
...
mace/python/tools/source_converter_lib.py
浏览文件 @
ac0a6951
...
...
@@ -78,11 +78,11 @@ def rename_tensor(net_def):
op
.
output
[
i
]
=
tensor_map
[
op
.
output
[
i
]]
class
TensorInfo
:
def
__init__
(
self
,
id
,
t
,
runtime
):
def
__init__
(
self
,
id
,
t
,
runtime
,
gpu_data_type
):
self
.
id
=
id
self
.
data_type
=
mace_pb2
.
DataType
.
Name
(
t
.
data_type
)
if
t
.
data_type
==
mace_pb2
.
DT_FLOAT
:
if
runtime
==
'gpu'
:
if
runtime
==
'gpu'
and
gpu_data_type
==
'half'
:
self
.
data_type
=
mace_pb2
.
DT_HALF
self
.
data
=
bytearray
(
np
.
array
(
t
.
float_data
).
astype
(
np
.
float16
).
tobytes
())
else
:
...
...
@@ -96,7 +96,7 @@ class TensorInfo:
def
stringfy
(
value
):
return
', '
.
join
(
'"{0}"'
.
format
(
w
)
for
w
in
value
)
def
convert_to_source
(
net_def
,
mode_pb_checksum
,
template_dir
,
obfuscate
,
model_tag
,
output
,
runtime
,
embed_model_data
):
def
convert_to_source
(
net_def
,
mode_pb_checksum
,
template_dir
,
obfuscate
,
model_tag
,
output
,
runtime
,
embed_model_data
,
gpu_data_type
):
if
obfuscate
:
obfuscate_name
(
net_def
)
else
:
...
...
@@ -115,7 +115,7 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, model_
offset
=
0
counter
=
0
for
t
in
net_def
.
tensors
:
tensor_info
=
TensorInfo
(
counter
,
t
,
runtime
)
tensor_info
=
TensorInfo
(
counter
,
t
,
runtime
,
gpu_data_type
)
# align
if
tensor_info
.
data_type
!=
'DT_UINT8'
and
offset
%
4
!=
0
:
padding
=
4
-
offset
%
4
...
...
@@ -167,7 +167,7 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, model_
# generate model source files
template_name
=
'model.jinja2'
tensors
=
[
TensorInfo
(
i
,
net_def
.
tensors
[
i
],
runtime
)
for
i
in
range
(
len
(
net_def
.
tensors
))]
tensors
=
[
TensorInfo
(
i
,
net_def
.
tensors
[
i
],
runtime
,
gpu_data_type
)
for
i
in
range
(
len
(
net_def
.
tensors
))]
source
=
j2_env
.
get_template
(
template_name
).
render
(
tensors
=
tensors
,
net
=
net_def
,
...
...
tools/generate_model_code.sh
浏览文件 @
ac0a6951
...
...
@@ -3,6 +3,10 @@
CURRENT_DIR
=
`
dirname
$0
`
source
${
CURRENT_DIR
}
/env.sh
if
[
$#
-eq
1
]
;
then
DATA_TYPE
=
$1
fi
bazel build //mace/python/tools:converter
||
exit
1
rm
-rf
${
MODEL_CODEGEN_DIR
}
mkdir
-p
${
MODEL_CODEGEN_DIR
}
...
...
tools/mace_tools.py
浏览文件 @
ac0a6951
...
...
@@ -132,8 +132,13 @@ def generate_random_input(target_soc, model_output_dir,
else
:
shutil
.
copy
(
input_file_list
[
i
],
dst_input_file
)
def
generate_model_code
():
command
=
"bash tools/generate_model_code.sh"
def
generate_model_code
(
gpu_data_type
):
data_type
=
""
if
gpu_data_type
==
"half"
:
data_type
=
"DT_HALF"
elif
gpu_data_type
==
"float"
:
data_type
=
"DT_FLOAT"
command
=
"bash tools/generate_model_code.sh {}"
.
format
(
data_type
)
run_command
(
command
)
...
...
@@ -319,6 +324,11 @@ def parse_args():
type
=
str
,
default
=
"all"
,
help
=
"SoCs to build, comma seperated list (getprop ro.board.platform)"
)
parser
.
add_argument
(
"--gpu_data_type"
,
type
=
str
,
default
=
""
,
help
=
"[half|float]"
)
return
parser
.
parse_known_args
()
def
set_environment
(
configs
):
...
...
@@ -412,7 +422,7 @@ def main(unused_args):
model_config
[
'input_nodes'
],
input_file_list
)
if
FLAGS
.
mode
==
"build"
or
FLAGS
.
mode
==
"all"
:
generate_model_code
()
generate_model_code
(
FLAGS
.
gpu_data_type
)
build_mace_run_prod
(
model_name
,
global_runtime
,
target_abi
,
target_soc
,
model_output_dir
,
FLAGS
.
tuning
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录