Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
e748c25e
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 1 年 前同步成功
通知
328
Star
698
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
26
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
26
Issue
26
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e748c25e
编写于
12月 09, 2020
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
bf803137
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
40 addition
and
23 deletion
+40
-23
x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py
x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py
+1
-4
x2paddle/optimizer/code_optimizer/hierachical_tree.py
x2paddle/optimizer/code_optimizer/hierachical_tree.py
+7
-3
x2paddle/optimizer/code_optimizer/layer_code_generator.py
x2paddle/optimizer/code_optimizer/layer_code_generator.py
+22
-10
x2paddle/optimizer/code_optimizer/subgraphs_union.py
x2paddle/optimizer/code_optimizer/subgraphs_union.py
+10
-6
未找到文件。
x2paddle/op_mapper/static/caffe2paddle/caffe_op_mapper.py
浏览文件 @
e748c25e
...
@@ -89,7 +89,6 @@ class CaffeOpMapper(OpMapper):
...
@@ -89,7 +89,6 @@ class CaffeOpMapper(OpMapper):
input_shape
.
append
(
last_node
.
output_shape
[
idx
])
input_shape
.
append
(
last_node
.
output_shape
[
idx
])
node
.
input_shape
=
input_shape
node
.
input_shape
=
input_shape
func_name
=
'shape_'
+
node
.
layer_type
.
lower
()
func_name
=
'shape_'
+
node
.
layer_type
.
lower
()
if
is_fluid_op
:
if
is_fluid_op
:
node
.
output_shape
=
getattr
(
caffe_shape
,
func_name
)(
node
.
layer
,
node
.
output_shape
=
getattr
(
caffe_shape
,
func_name
)(
node
.
layer
,
...
@@ -458,7 +457,6 @@ class CaffeOpMapper(OpMapper):
...
@@ -458,7 +457,6 @@ class CaffeOpMapper(OpMapper):
def
ReLU
(
self
,
node
):
def
ReLU
(
self
,
node
):
"""
"""
:param node:
:param node:
:return:
:return:
"""
"""
...
@@ -975,4 +973,3 @@ class CaffeOpMapper(OpMapper):
...
@@ -975,4 +973,3 @@ class CaffeOpMapper(OpMapper):
kernel
=
op_info
,
kernel
=
op_info
,
inputs
=
{
"x"
:
self
.
get_input_name
(
input
)},
inputs
=
{
"x"
:
self
.
get_input_name
(
input
)},
outputs
=
[
node
.
layer_name
])
outputs
=
[
node
.
layer_name
])
\ No newline at end of file
\ No newline at end of file
x2paddle/optimizer/code_optimizer/hierachical_tree.py
浏览文件 @
e748c25e
...
@@ -201,7 +201,6 @@ class HierarchicalTree(Tree):
...
@@ -201,7 +201,6 @@ class HierarchicalTree(Tree):
code_str
=
gen_layer_code
(
self
.
pd_graph
,
sub_layers
,
module_name
,
code_str
=
gen_layer_code
(
self
.
pd_graph
,
sub_layers
,
module_name
,
different_attrs
=
diff_attrs_column
)
different_attrs
=
diff_attrs_column
)
# print(code_str)
self
.
codes
.
append
(
code_str
)
self
.
codes
.
append
(
code_str
)
for
sub_layers
in
sub_layers_list
:
for
sub_layers
in
sub_layers_list
:
inputs
,
outputs
=
get_inputs_outputs
(
self
.
pd_graph
,
sub_layers
)
inputs
,
outputs
=
get_inputs_outputs
(
self
.
pd_graph
,
sub_layers
)
...
@@ -359,7 +358,7 @@ class HierarchicalTree(Tree):
...
@@ -359,7 +358,7 @@ class HierarchicalTree(Tree):
run_func_list
.
append
(
" # {}: 形状为{},类型为{}。"
.
format
(
k
,
v
[
0
],
v
[
1
]))
run_func_list
.
append
(
" # {}: 形状为{},类型为{}。"
.
format
(
k
,
v
[
0
],
v
[
1
]))
run_func_list
.
extend
(
run_func_list
.
extend
(
[
" paddle.disable_static()"
,
[
" paddle.disable_static()"
,
" params
, _ = fluid.load_dygraph('{}/model')"
.
format
(
save_dir
),
" params
= paddle.load('{}/model.pdparams')"
.
format
(
osp
.
abspath
(
save_dir
)
),
" model = {}()"
.
format
(
self
.
pd_graph
.
name
),
" model = {}()"
.
format
(
self
.
pd_graph
.
name
),
" model.set_dict(params)"
,
" model.set_dict(params)"
,
" model.eval()"
,
" model.eval()"
,
...
@@ -371,7 +370,12 @@ class HierarchicalTree(Tree):
...
@@ -371,7 +370,12 @@ class HierarchicalTree(Tree):
self
.
update_parameters
()
self
.
update_parameters
()
import_list
=
[
"import paddle"
,
import_list
=
[
"import paddle"
,
"import paddle.fluid as fluid"
,
"import paddle.fluid as fluid"
,
""
,]
"from paddle.fluid.initializer import Constant"
,
"from paddle.fluid.param_attr import ParamAttr"
,
"import math"
,
"from x2paddle.op_mapper.dygraph.pytorch2paddle "
+
\
"import pytorch_custom_layer as x2paddle_nn"
"
\n
"
,]
import_str
=
"
\n
"
.
join
(
import_list
)
import_str
=
"
\n
"
.
join
(
import_list
)
if
not
osp
.
exists
(
save_dir
):
if
not
osp
.
exists
(
save_dir
):
os
.
makedirs
(
save_dir
)
os
.
makedirs
(
save_dir
)
...
...
x2paddle/optimizer/code_optimizer/layer_code_generator.py
浏览文件 @
e748c25e
...
@@ -29,9 +29,9 @@ NN_KERNEL_NAME = {"paddle.nn.BatchNorm": "bn",
...
@@ -29,9 +29,9 @@ NN_KERNEL_NAME = {"paddle.nn.BatchNorm": "bn",
"paddle.nn.Tanh"
:
"tanh"
,
"paddle.nn.Tanh"
:
"tanh"
,
"paddle.nn.AvgPool2D"
:
"pool"
,
"paddle.nn.AvgPool2D"
:
"pool"
,
"paddle.nn.MaxPool2D"
:
"pool"
,
"paddle.nn.MaxPool2D"
:
"pool"
,
"paddle.nn.Pad1
d
"
:
"pad"
,
"paddle.nn.Pad1
D
"
:
"pad"
,
"paddle.nn.Pad2
d
"
:
"pad"
,
"paddle.nn.Pad2
D
"
:
"pad"
,
"paddle.nn.Pad3
d
"
:
"pad"
,
"paddle.nn.Pad3
D
"
:
"pad"
,
"paddle.nn.Dropout"
:
"dropout"
,
"paddle.nn.Dropout"
:
"dropout"
,
"paddle.nn.GELU"
:
"gelu"
,
"paddle.nn.GELU"
:
"gelu"
,
"paddle.nn.Hardtanh"
:
"tanh"
,
"paddle.nn.Hardtanh"
:
"tanh"
,
...
@@ -175,9 +175,11 @@ def gen_layer_code(graph, sub_layers, sub_layers_name, different_attrs=list()):
...
@@ -175,9 +175,11 @@ def gen_layer_code(graph, sub_layers, sub_layers_name, different_attrs=list()):
if
layer
.
kernel
.
startswith
(
"paddle.nn"
)
and
index
==
0
:
if
layer
.
kernel
.
startswith
(
"paddle.nn"
)
and
index
==
0
:
continue
continue
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
or
layer
.
kernel
==
"prim.assert"
or
\
or
layer
.
kernel
==
"prim.assert"
:
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
continue
continue
elif
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
if
index
!=
0
:
outputs
.
append
(
output_name
)
elif
output_name
not
in
outputs
:
elif
output_name
not
in
outputs
:
outputs
.
append
(
output_name
)
outputs
.
append
(
output_name
)
continue
continue
...
@@ -187,15 +189,22 @@ def gen_layer_code(graph, sub_layers, sub_layers_name, different_attrs=list()):
...
@@ -187,15 +189,22 @@ def gen_layer_code(graph, sub_layers, sub_layers_name, different_attrs=list()):
if
layer
.
kernel
.
startswith
(
"paddle.nn"
)
and
index
==
0
and
"functional"
not
in
layer
.
kernel
:
if
layer
.
kernel
.
startswith
(
"paddle.nn"
)
and
index
==
0
and
"functional"
not
in
layer
.
kernel
:
continue
continue
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
or
layer
.
kernel
==
"prim.assert"
or
\
or
layer
.
kernel
==
"prim.assert"
:
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
continue
continue
elif
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
if
index
!=
0
:
outputs
.
append
(
output_name
)
else
:
else
:
outputs
.
append
(
output_name
)
outputs
.
append
(
output_name
)
no_output_count
=
0
no_output_count
=
0
for
i
,
(
layer_id
,
layer
)
in
enumerate
(
sub_layers
.
items
()):
for
i
,
(
layer_id
,
layer
)
in
enumerate
(
sub_layers
.
items
()):
if
(
"paddle.nn"
in
layer
.
kernel
and
"functional"
not
in
layer
.
kernel
):
if
(
"paddle.nn"
in
layer
.
kernel
and
"functional"
not
in
layer
.
kernel
)
or
\
line
=
"self.{} = {}("
.
format
(
layer
.
outputs
[
0
],
layer
.
kernel
)
layer
.
kernel
.
startswith
(
"custom_layer"
):
line
=
"self.{}"
.
format
(
layer
.
outputs
[
0
])
if
layer
.
kernel
.
startswith
(
"custom_layer"
):
line
+=
"= x2paddle_nn.{}("
.
format
(
layer
.
kernel
.
split
(
":"
)[
-
1
])
else
:
line
+=
" = {}("
.
format
(
layer
.
kernel
)
for
k
,
v
in
layer
.
attrs
.
items
():
for
k
,
v
in
layer
.
attrs
.
items
():
key_name
=
"{}_{}"
.
format
(
layer
.
outputs
[
0
],
k
)
key_name
=
"{}_{}"
.
format
(
layer
.
outputs
[
0
],
k
)
if
key_name
in
different_attrs
:
if
key_name
in
different_attrs
:
...
@@ -289,6 +298,9 @@ def gen_layer_code(graph, sub_layers, sub_layers_name, different_attrs=list()):
...
@@ -289,6 +298,9 @@ def gen_layer_code(graph, sub_layers, sub_layers_name, different_attrs=list()):
else
:
else
:
if
v
not
in
cur_outputs
and
v
not
in
inputs
:
if
v
not
in
cur_outputs
and
v
not
in
inputs
:
inputs
.
append
(
v
)
inputs
.
append
(
v
)
if
k
==
"args"
:
line
+=
v
else
:
line
+=
"{}={}, "
.
format
(
k
,
v
)
line
+=
"{}={}, "
.
format
(
k
,
v
)
for
k
,
v
in
layer
.
attrs
.
items
():
for
k
,
v
in
layer
.
attrs
.
items
():
key_name
=
"{}_{}"
.
format
(
layer
.
outputs
[
0
],
k
)
key_name
=
"{}_{}"
.
format
(
layer
.
outputs
[
0
],
k
)
...
...
x2paddle/optimizer/code_optimizer/subgraphs_union.py
浏览文件 @
e748c25e
...
@@ -50,21 +50,25 @@ def get_inputs_outputs(pd_graph, layers):
...
@@ -50,21 +50,25 @@ def get_inputs_outputs(pd_graph, layers):
for
layer_id
,
layer
in
layers
.
items
():
for
layer_id
,
layer
in
layers
.
items
():
# 获取输出节点名字
# 获取输出节点名字
if
layer_id
not
in
pd_graph
.
edges_out
:
if
layer_id
not
in
pd_graph
.
edges_out
:
for
output_name
in
layer
.
outputs
:
for
index
,
output_name
in
enumerate
(
layer
.
outputs
)
:
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
or
layer
.
kernel
==
"prim.assert"
or
\
or
layer
.
kernel
==
"prim.assert"
:
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
continue
continue
elif
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
if
index
!=
0
:
outputs
.
append
(
output_name
)
elif
output_name
not
in
outputs
:
elif
output_name
not
in
outputs
:
outputs
.
append
(
output_name
)
outputs
.
append
(
output_name
)
else
:
else
:
for
out_layer_id
in
pd_graph
.
edges_out
[
layer_id
]:
for
out_layer_id
in
pd_graph
.
edges_out
[
layer_id
]:
if
out_layer_id
not
in
layer_ids
:
if
out_layer_id
not
in
layer_ids
:
for
output_name
in
layer
.
outputs
:
for
index
,
output_name
in
enumerate
(
layer
.
outputs
)
:
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
if
not
output_name
.
startswith
(
"x"
)
or
output_name
in
outputs
\
or
layer
.
kernel
==
"prim.assert"
or
\
or
layer
.
kernel
==
"prim.assert"
:
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
continue
continue
elif
layer
.
kernel
==
"prim.if"
or
layer
.
kernel
==
"prim.loop"
:
if
index
!=
0
:
outputs
.
append
(
output_name
)
else
:
else
:
outputs
.
append
(
output_name
)
outputs
.
append
(
output_name
)
# 获取输入节点名字
# 获取输入节点名字
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录