未验证 提交 a7d14023 编写于 作者: S SunAhong1993 提交者: GitHub

Fix readme and converter.py (#551)

上级 54ca1dbb
......@@ -21,14 +21,14 @@ X2Paddle的架构设计着重考虑了对多深度学习框架的的支持以及
## 环境依赖
python >= 3.5
paddlepaddle 2.0.0-rc1 或者 develop
> python >= 3.5
> paddlepaddle 2.0.0+
**按需安装以下依赖**
tensorflow : tensorflow == 1.14.0
caffe : 无
onnx : onnx >= 1.6.0
pytorch:torch >=1.5.0 (script方式暂不支持1.7.0)
> tensorflow : tensorflow == 1.14.0
> caffe : 无
> onnx : onnx >= 1.6.0
> pytorch:torch >=1.5.0 (script方式暂不支持1.7.0)
## 安装
### 方式一:源码安装(推荐)
......@@ -90,6 +90,7 @@ X2Paddle提供了工具解决如下问题,详见[tools/README.md](tools/README
3. [PyTorch模型导出为ONNX模型](./docs/user_guides/pytorch2onnx.md)
4. [X2Paddle添加内置的Caffe自定义层](./docs/user_guides/add_caffe_custom_layer.md)
5. [转换后PaddlePaddle预测模型简介](./docs/user_guides/pd_folder_introduction.py)
6. [Paddle到ONNX的转换](https://github.com/PaddlePaddle/Paddle2ONNX)
## 支持列表文档
1. [X2Paddle测试模型库](./docs/introduction/x2paddle_model_zoo.md)
......
......@@ -41,16 +41,15 @@ def arg_parser():
parser.add_argument(
"--save_dir",
"-s",
required=True,
type=_text_type,
default=None,
help="path to save translated model")
parser.add_argument(
"--framework",
"-f",
type=_text_type,
default=None,
help="define which deeplearning framework(tensorflow/caffe/onnx/paddle2onnx)"
)
choices=['tensorflow', 'caffe', 'onnx'],
help="define which deeplearning framework(tensorflow/caffe/onnx)")
parser.add_argument(
"--caffe_proto",
"-c",
......@@ -73,10 +72,9 @@ def arg_parser():
parser.add_argument(
"--paddle_type",
"-pt",
type=_text_type,
choices=['dygraph', 'static'],
default="dygraph",
help="define the paddle model type after converting(dygraph/static)"
)
help="define the paddle model type after converting(dygraph/static)")
return parser
......@@ -108,7 +106,6 @@ def tf2paddle(model_path,
else:
from x2paddle.op_mapper.static.tf2paddle.tf_op_mapper import TFOpMapper
print("Now translating model from tensorflow to paddle.")
model = TFDecoder(model_path, define_input_shape=define_input_shape)
mapper = TFOpMapper(model)
......@@ -124,7 +121,6 @@ def tf2paddle(model_path,
mapper.paddle_graph.gen_model(save_dir)
def caffe2paddle(proto, weight, save_dir, caffe_proto, paddle_type):
from x2paddle.decoder.caffe_decoder import CaffeDecoder
if paddle_type == "dygraph":
......@@ -202,7 +198,8 @@ def pytorch2paddle(module, save_dir, jit_type="trace", input_examples=None):
mapper.paddle_graph.build()
print("Model optimizing ...")
from x2paddle.optimizer.optimizer import GraphOptimizer
graph_opt = GraphOptimizer(source_frame="pytorch", paddle_type="dygraph", jit_type=jit_type)
graph_opt = GraphOptimizer(
source_frame="pytorch", paddle_type="dygraph", jit_type=jit_type)
graph_opt.optimize(mapper.paddle_graph)
print("Model optimized.")
mapper.paddle_graph.gen_model(save_dir, jit_type=jit_type)
......@@ -224,14 +221,10 @@ def main():
x2paddle.__version__))
return
assert args.framework is not None, "--framework is not defined(support tensorflow/caffe/onnx)"
assert args.save_dir is not None, "--save_dir is not defined"
assert args.paddle_type in ["dygraph", "static"], "--paddle_type must be 'dygraph' or 'static'"
try:
import platform
v0, v1, v2 = platform.python_version().split('.')
if not(int(v0) >= 3 and int(v1) >= 5):
if not (int(v0) >= 3 and int(v1) >= 5):
print("[ERROR] python>=3.5 is required")
return
import paddle
......@@ -252,8 +245,8 @@ def main():
define_input_shape = False
if args.define_input_shape:
define_input_shape = True
tf2paddle(args.model, args.save_dir,
define_input_shape, args.paddle_type)
tf2paddle(args.model, args.save_dir, define_input_shape,
args.paddle_type)
elif args.framework == "caffe":
assert args.prototxt is not None and args.weight is not None, "--prototxt and --weight should be defined while translating caffe model"
......@@ -263,11 +256,12 @@ def main():
assert args.model is not None, "--model should be defined while translating onnx model"
onnx2paddle(args.model, args.save_dir, args.paddle_type)
elif args.framework == "paddle2onnx":
print("Paddle to ONNX tool has been migrated to the new github: https://github.com/PaddlePaddle/paddle2onnx")
print(
"Paddle to ONNX tool has been migrated to the new github: https://github.com/PaddlePaddle/paddle2onnx"
)
else:
raise Exception(
"--framework only support tensorflow/caffe/onnx now")
raise Exception("--framework only support tensorflow/caffe/onnx now")
if __name__ == "__main__":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册