Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
孤小逸
Mace
提交
803f2621
Mace
项目概览
孤小逸
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
1
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,发现更多精彩内容 >>
提交
803f2621
编写于
7月 05, 2018
作者:
李
李寅
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'keep_downloaded' into 'master'
keep downloaded models See merge request !633
上级
82ff5515
a5ad26c8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
58 deletion
+42
-58
tools/converter.py
tools/converter.py
+42
-58
未找到文件。
tools/converter.py
浏览文件 @
803f2621
...
...
@@ -39,6 +39,7 @@ from common import StringFormatter
# common definitions
################################
BUILD_OUTPUT_DIR
=
'build'
BUILD_DOWNLOADS_DIR
=
BUILD_OUTPUT_DIR
+
'/downloads'
PHONE_DATA_DIR
=
"/data/local/tmp/mace_run"
MODEL_OUTPUT_DIR_NAME
=
'model'
MODEL_HEADER_DIR_PATH
=
'include/mace/public'
...
...
@@ -536,36 +537,41 @@ def print_configuration(flags, configs):
MaceLogger
.
summary
(
StringFormatter
.
table
(
header
,
data
,
title
))
def
download_model_files
(
model_file_path
,
model_output_dir
,
weight_file_path
=
""
):
MaceLogger
.
info
(
"Downloading model, please wait ..."
)
if
model_file_path
.
startswith
(
"http://"
)
or
\
model_file_path
.
startswith
(
"https://"
):
model_file
=
model_output_dir
+
"/model.pb"
urllib
.
urlretrieve
(
model_file_path
,
model_file
)
if
weight_file_path
.
startswith
(
"http://"
)
or
\
weight_file_path
.
startswith
(
"https://"
):
weight_file
=
model_output_dir
+
"/model.caffemodel"
urllib
.
urlretrieve
(
weight_file_path
,
weight_file
)
MaceLogger
.
info
(
"Model downloaded successfully."
)
def
get_model_files
(
model_file_path
,
model_sha256_checksum
,
model_output_dir
,
weight_file_path
=
""
,
weight_sha256_checksum
=
""
):
model_file
=
model_file_path
weight_file
=
weight_file_path
def
get_model_files_path
(
model_file_path
,
model_output_dir
,
weight_file_path
=
""
):
if
model_file_path
.
startswith
(
"http://"
)
or
\
model_file_path
.
startswith
(
"https://"
):
model_file
=
model_output_dir
+
"/model.pb"
else
:
model_file
=
model_file_path
model_file
=
model_output_dir
+
"/"
+
md5sum
(
model_file_path
)
+
".pb"
if
not
os
.
path
.
exists
(
model_file
)
or
\
sha256_checksum
(
model_file
)
!=
model_sha256_checksum
:
MaceLogger
.
info
(
"Downloading model, please wait ..."
)
urllib
.
urlretrieve
(
model_file_path
,
model_file
)
MaceLogger
.
info
(
"Model downloaded successfully."
)
if
sha256_checksum
(
model_file
)
!=
model_sha256_checksum
:
MaceLogger
.
error
(
ModuleName
.
MODEL_CONVERTER
,
"model file sha256checksum not match"
)
if
weight_file_path
.
startswith
(
"http://"
)
or
\
weight_file_path
.
startswith
(
"https://"
):
weight_file
=
model_output_dir
+
"/model.caffemodel"
else
:
weight_file
=
weight_file_path
weight_file
=
\
model_output_dir
+
"/"
+
md5sum
(
weight_file_path
)
+
".caffemodel"
if
not
os
.
path
.
exists
(
weight_file
)
or
\
sha256_checksum
(
weight_file
)
!=
weight_sha256_checksum
:
MaceLogger
.
info
(
"Downloading model weight, please wait ..."
)
urllib
.
urlretrieve
(
weight_file_path
,
weight_file
)
MaceLogger
.
info
(
"Model weight downloaded successfully."
)
if
weight_file
:
if
sha256_checksum
(
weight_file
)
!=
weight_sha256_checksum
:
MaceLogger
.
error
(
ModuleName
.
MODEL_CONVERTER
,
"weight file sha256checksum not match"
)
return
model_file
,
weight_file
...
...
@@ -578,6 +584,8 @@ def convert_model(configs):
elif
os
.
path
.
exists
(
os
.
path
.
join
(
BUILD_OUTPUT_DIR
,
library_name
)):
sh
.
rm
(
"-rf"
,
os
.
path
.
join
(
BUILD_OUTPUT_DIR
,
library_name
))
os
.
makedirs
(
os
.
path
.
join
(
BUILD_OUTPUT_DIR
,
library_name
))
if
not
os
.
path
.
exists
(
BUILD_DOWNLOADS_DIR
):
os
.
makedirs
(
BUILD_DOWNLOADS_DIR
)
model_output_dir
=
\
'%s/%s/%s'
%
(
BUILD_OUTPUT_DIR
,
library_name
,
MODEL_OUTPUT_DIR_NAME
)
...
...
@@ -609,38 +617,12 @@ def convert_model(configs):
model_config
=
configs
[
YAMLKeyword
.
models
][
model_name
]
runtime
=
model_config
[
YAMLKeyword
.
runtime
]
# Create model build directory
model_path_digest
=
md5sum
(
model_config
[
YAMLKeyword
.
model_file_path
])
model_output_base_dir
=
"%s/%s/%s/%s/%s"
%
(
BUILD_OUTPUT_DIR
,
library_name
,
BUILD_TMP_DIR_NAME
,
model_name
,
model_path_digest
)
if
os
.
path
.
exists
(
model_output_base_dir
):
sh
.
rm
(
"-rf"
,
model_output_base_dir
)
os
.
makedirs
(
model_output_base_dir
)
download_model_files
(
model_config
[
YAMLKeyword
.
model_file_path
],
model_output_base_dir
,
model_config
[
YAMLKeyword
.
weight_file_path
])
model_file_path
,
weight_file_path
=
get_model_files_path
(
model_file_path
,
weight_file_path
=
get_model_files
(
model_config
[
YAMLKeyword
.
model_file_path
],
model_output_base_dir
,
model_config
[
YAMLKeyword
.
weight_file_path
])
if
sha256_checksum
(
model_file_path
)
!=
\
model_config
[
YAMLKeyword
.
model_sha256_checksum
]:
MaceLogger
.
error
(
ModuleName
.
MODEL_CONVERTER
,
"model file sha256checksum not match"
)
if
weight_file_path
:
if
sha256_checksum
(
weight_file_path
)
!=
\
model_config
[
YAMLKeyword
.
weight_sha256_checksum
]:
MaceLogger
.
error
(
ModuleName
.
MODEL_CONVERTER
,
"weight file sha256checksum not match"
)
model_config
[
YAMLKeyword
.
model_sha256_checksum
],
BUILD_DOWNLOADS_DIR
,
model_config
[
YAMLKeyword
.
weight_file_path
],
model_config
[
YAMLKeyword
.
weight_sha256_checksum
])
data_type
=
model_config
[
YAMLKeyword
.
data_type
]
# TODO(liuqi): support multiple subgraphs
...
...
@@ -1068,10 +1050,12 @@ def run_specific_target(flags, configs, target_abi,
linkshared
=
linkshared
,
)
if
flags
.
validate
:
model_file_path
,
weight_file_path
=
get_model_files
_path
(
model_file_path
,
weight_file_path
=
get_model_files
(
model_config
[
YAMLKeyword
.
model_file_path
],
model_output_base_dir
,
model_config
[
YAMLKeyword
.
weight_file_path
])
model_config
[
YAMLKeyword
.
model_sha256_checksum
],
BUILD_DOWNLOADS_DIR
,
model_config
[
YAMLKeyword
.
weight_file_path
],
model_config
[
YAMLKeyword
.
weight_sha256_checksum
])
sh_commands
.
validate_model
(
abi
=
target_abi
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录