Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
56e2fd76
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
56e2fd76
编写于
2月 22, 2020
作者:
H
huzhiqiang
提交者:
GitHub
2月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【doc and opt tool】add auto_transform.sh into Paddle-Lite project and modify related docs #2973
上级
12a17969
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
170 addition
and
4 deletion
+170
-4
docs/user_guides/model_optimize_tool.md
docs/user_guides/model_optimize_tool.md
+4
-4
lite/tools/auto_transform.sh
lite/tools/auto_transform.sh
+166
-0
未找到文件。
docs/user_guides/model_optimize_tool.md
浏览文件 @
56e2fd76
...
...
@@ -121,14 +121,14 @@ opt可以统计并打印出model中的算子信息、判断Paddle-Lite是否支
**背景**
:如果想用Paddle-Lite运行第三方来源(tensorflow、caffe、onnx)模型,一般需要经过两次转化。即使用x2paddle工具将第三方模型转化为PaddlePaddle格式,再使用opt将PaddlePaddle模型转化为Padde-Lite可支持格式。
为了简化这一过程,我们提供一键脚本,将x2paddle转化和opt转化合并:
**一键转化脚本**
:
[
auto_transform.sh
](
https://
paddlelite-data.bj.bcebos.com/model_optimize_tool
/auto_transform.sh
)
**一键转化脚本**
:
[
auto_transform.sh
](
https://
github.com/PaddlePaddle/Paddle-Lite/blob/release/v2.3/lite/tools
/auto_transform.sh
)
**环境要求**
:使用
`auto_transform.sh`
脚本转化第三方模型时,需要先安装x2paddle环境,请参考
[
x2paddle环境安装方法
](
https://github.com/PaddlePaddle/X2Paddle#环境依赖
)
安装x2paddle和
其环境依赖项
。
**环境要求**
:使用
`auto_transform.sh`
脚本转化第三方模型时,需要先安装x2paddle环境,请参考
[
x2paddle环境安装方法
](
https://github.com/PaddlePaddle/X2Paddle#环境依赖
)
安装x2paddle和
x2paddle依赖项(tensorflow、caffe等)
。
**使用方法**
:
(1)打印帮助帮助信息:
` ./auto_transform.sh`
(1)打印帮助帮助信息:
`
sh
./auto_transform.sh`
(2)转化模型方法
...
...
@@ -138,7 +138,7 @@ USAGE:
tranform model from tensorflow/caffe/onnx form into paddle-lite naive-buffer form.
----------------------------------------
example:
./auto_transform.sh
--framework
=
tensorflow
--model
=
tf_model.pb
--optimize_out
=
opt_model_result
sh
./auto_transform.sh
--framework
=
tensorflow
--model
=
tf_model.pb
--optimize_out
=
opt_model_result
----------------------------------------
Arguments about x2paddle:
--framework
=(
tensorflow|caffe|onnx
)
;
...
...
lite/tools/auto_transform.sh
0 → 100644
浏览文件 @
56e2fd76
#!/usr/bin/env bash
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#set -u # Check for undefined variables
# Global variables
###########################################
# (1) x2paddle variables
framework
=
"caffe"
# framework=(caffe|tensorflow|onnx)
prototxt
=
""
weight
=
""
model
=
""
# fluid_save__dir: the path of x2paddlei's output result; this is used as `model_dir` of opt
fluid_save_dir
=
"saved_fluid"
###########################################
# (2)opt variables
valid_targets
=
"arm"
# valid_targets=(arm|opencl|x86|npu|xpu)
optimize_out
=
"lite_opt_dir"
# check current system
system
=
`
uname
-s
`
opt
=
""
if
[
${
system
}
==
"Darwin"
]
;
then
opt
=
opt_mac
else
opt
=
opt
fi
function
check_x2paddle
{
message
=
$(
which x2paddle
)
if
[
!
$message
]
;
then
echo
"please install x2paddle environment first, you can install it according to https://github.com/PaddlePaddle/X2Paddle#%E7%8E%AF%E5%A2%83%E4%BE%9D%E8%B5%96"
exit
1
fi
}
function
check_model_optimize_tool
{
has_opt
=
$(
find
$opt
)
if
[
-z
"
$has_opt
"
]
;
then
wget https://paddlelite-data.bj.bcebos.com/model_optimize_tool/
$opt
chmod
+x
$opt
fi
}
function
x2paddle_transform
{
check_x2paddle
x2paddle
if
[
"
$framework
"
==
"caffe"
]
;
then
x2paddle
--framework
caffe
\
--prototxt
=
$prototxt
\
--weight
=
$weight
\
--save_dir
=
$fluid_save_dir
elif
[
"
$framework
"
==
"tensorflow"
]
;
then
x2paddle
--framework
=
tensorflow
\
--model
=
$model
\
--save_dir
=
$fluid_save_dir
elif
[
"
$framework
"
==
"onnx"
]
;
then
x2paddle
--framework
=
onnx
\
--model
=
$model
\
--save_dir
=
$fluid_save_dir
else
echo
"error: unsupported framwork, x2paddle supports three framework: caffe、tensorflow and onnx."
exit
1
fi
}
function
model_optimimize_tool_transform
{
check_model_optimize_tool
./
$opt
\
--model_dir
=
$fluid_save_dir
/inference_model
\
--optimize_out_type
=
naive_buffer
\
--optimize_out
=
$optimize_out
\
--valid_targets
=
$valid_targets
}
function
print_usage
{
set
+x
echo
"
\n
USAGE:"
echo
" auto_build.sh combines the function of x2paddle and opt, it can "
echo
" tranform model from tensorflow/caffe/onnx form into paddle-lite naive-buffer form."
echo
"----------------------------------------"
echo
"example:"
echo
" ./auto_build.sh --framework=tensorflow --model=tf_model.pb --optimize_out=opt_model_result"
echo
"----------------------------------------"
echo
"Arguments about x2paddle:"
echo
" --framework=(tensorflow|caffe|onnx);"
echo
" --model='model file for tensorflow or onnx';"
echo
" --prototxt='proto file for caffe' --weight='weight file for caffe'"
echo
"For TensorFlow:"
echo
" --framework=tensorflow --model=tf_model.pb"
echo
echo
"For Caffe:"
echo
" --framework=caffe --prototxt=deploy.prototxt --weight=deploy.caffemodel"
echo
echo
"For ONNX"
echo
" --framework=onnx --model=onnx_model.onnx"
echo
echo
"Arguments about opt:"
echo
" --valid_targets=(arm|opencl|x86|npu|xpu); valid targets on Paddle-Lite."
echo
" --fluid_save_dir='path to outputed model after x2paddle'"
echo
" --optimize_out='path to outputed Paddle-Lite model'"
echo
"----------------------------------------"
echo
}
function
main
{
# Parse command line.
if
[
$#
-eq
0
]
;
then
print_usage
exit
1
fi
for
i
in
"
$@
"
;
do
case
$i
in
--framework
=
*
)
framework
=
"
${
i
#*=
}
"
shift
;;
--prototxt
=
*
)
prototxt
=
"
${
i
#*=
}
"
shift
;;
--weight
=
*
)
weight
=
"
${
i
#*=
}
"
shift
;;
--model
=
*
)
model
=
"
${
i
#*=
}
"
shift
;;
--fluid_save_dir
=
*
)
fluid_save_dir
=
"
${
i
#*=
}
"
shift
;;
--valid_targets
=
*
)
valid_targets
=
"
${
i
#*=
}
"
shift
;;
--optimize_out
=
*
)
optimize_out
=
"
${
i
#*=
}
"
shift
;;
*
)
# unknown option
print_usage
exit
1
;;
esac
done
x2paddle_transform
model_optimimize_tool_transform
}
main
$@
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录