Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
8a93b96d
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看板
提交
8a93b96d
编写于
7月 24, 2019
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more op mapper
上级
8e27ee0e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
106 addition
and
9 deletion
+106
-9
x2paddle/core/graph.py
x2paddle/core/graph.py
+0
-1
x2paddle/decoder/tf_decoder.py
x2paddle/decoder/tf_decoder.py
+7
-8
x2paddle/op_mapper/tf_op_mapper.py
x2paddle/op_mapper/tf_op_mapper.py
+99
-0
未找到文件。
x2paddle/core/graph.py
浏览文件 @
8a93b96d
...
@@ -110,7 +110,6 @@ class Graph(object):
...
@@ -110,7 +110,6 @@ class Graph(object):
del
self
.
node_map
[
input
].
inputs
[
idx
]
del
self
.
node_map
[
input
].
inputs
[
idx
]
del
self
.
node_map
[
node_name
]
del
self
.
node_map
[
node_name
]
print
(
"remove topo"
,
node_name
)
idx
=
self
.
topo_sort
.
index
(
node_name
)
idx
=
self
.
topo_sort
.
index
(
node_name
)
del
self
.
topo_sort
[
idx
]
del
self
.
topo_sort
[
idx
]
...
...
x2paddle/decoder/tf_decoder.py
浏览文件 @
8a93b96d
...
@@ -26,10 +26,10 @@ class TFGraphNode(GraphNode):
...
@@ -26,10 +26,10 @@ class TFGraphNode(GraphNode):
def
__init__
(
self
,
layer
,
layer_name
=
None
):
def
__init__
(
self
,
layer
,
layer_name
=
None
):
if
layer_name
is
None
:
if
layer_name
is
None
:
super
(
TFGraphNode
,
self
).
__init__
(
layer
,
super
(
TFGraphNode
,
self
).
__init__
(
layer
,
layer
.
name
.
replace
(
'/'
,
'_'
))
layer
.
name
.
replace
(
'/'
,
'_'
)
.
replace
(
'-'
,
'_'
)
)
else
:
else
:
super
(
TFGraphNode
,
self
).
__init__
(
layer
,
super
(
TFGraphNode
,
self
).
__init__
(
layer
,
layer_name
.
replace
(
'/'
,
'_'
))
layer_name
.
replace
(
'/'
,
'_'
)
.
replace
(
'-'
,
'_'
)
)
self
.
layer_type
=
layer
.
op
self
.
layer_type
=
layer
.
op
self
.
fluid_code
=
FluidCode
()
self
.
fluid_code
=
FluidCode
()
...
@@ -89,11 +89,11 @@ class TFGraph(Graph):
...
@@ -89,11 +89,11 @@ class TFGraph(Graph):
def
build
(
self
):
def
build
(
self
):
for
layer
in
self
.
model
.
node
:
for
layer
in
self
.
model
.
node
:
self
.
node_map
[
layer
.
name
.
replace
(
'/'
,
'_'
)]
=
TFGraphNode
(
layer
)
self
.
node_map
[
layer
.
name
.
replace
(
'/'
,
'_'
)
.
replace
(
'-'
,
'_'
)
]
=
TFGraphNode
(
layer
)
for
layer_name
,
node
in
self
.
node_map
.
items
():
for
layer_name
,
node
in
self
.
node_map
.
items
():
for
in_node
in
node
.
layer
.
input
:
for
in_node
in
node
.
layer
.
input
:
in_node
=
in_node
.
replace
(
'/'
,
'_'
)
in_node
=
in_node
.
replace
(
'/'
,
'_'
)
.
replace
(
'-'
,
'_'
)
if
in_node
not
in
self
.
node_map
:
if
in_node
not
in
self
.
node_map
:
if
in_node
.
strip
().
split
(
':'
)[
0
]
in
self
.
node_map
:
if
in_node
.
strip
().
split
(
':'
)[
0
]
in
self
.
node_map
:
self
.
connect
(
in_node
.
strip
().
split
(
':'
)[
0
],
layer_name
)
self
.
connect
(
in_node
.
strip
().
split
(
':'
)[
0
],
layer_name
)
...
@@ -112,7 +112,7 @@ class TFGraph(Graph):
...
@@ -112,7 +112,7 @@ class TFGraph(Graph):
def
get_node
(
self
,
node_name
,
copy
=
False
):
def
get_node
(
self
,
node_name
,
copy
=
False
):
items
=
node_name
.
strip
().
split
(
':'
)
items
=
node_name
.
strip
().
split
(
':'
)
items
[
0
]
=
items
[
0
].
replace
(
'/'
,
'_'
)
items
[
0
]
=
items
[
0
].
replace
(
'/'
,
'_'
)
.
replace
(
'-'
,
'_'
)
if
items
[
0
]
in
self
.
identity_map
:
if
items
[
0
]
in
self
.
identity_map
:
items
[
0
]
=
self
.
identity_map
[
items
[
0
]]
items
[
0
]
=
self
.
identity_map
[
items
[
0
]]
new_node_name
=
":"
.
join
(
items
)
new_node_name
=
":"
.
join
(
items
)
...
@@ -163,11 +163,10 @@ def check_input_shape(graph_def):
...
@@ -163,11 +163,10 @@ def check_input_shape(graph_def):
continue
continue
graph_node
=
TFGraphNode
(
layer
)
graph_node
=
TFGraphNode
(
layer
)
dtype
=
graph_node
.
dtype
dtype
=
graph_node
.
dtype
# print("shape:", graph_node.out_shapes)
if
not
graph_node
.
get_attr
(
"shape"
):
if
not
graph_node
.
get_attr
(
"shape"
):
sys
.
stderr
.
write
(
"
Unknown shape for input tensor[{}
]
\n
"
.
format
(
sys
.
stderr
.
write
(
"
\n
Unknown shape for input tensor[tensor name:
\"
{}
\"
]
\n
"
.
format
(
layer
.
name
))
layer
.
name
))
shape
=
input
(
"Please define shape of input here: "
)
shape
=
input
(
"Please define shape of input here
(e.g. None,224,224,3)
: "
)
shape
=
[
shape
=
[
None
if
dim
==
"None"
else
int
(
dim
)
None
if
dim
==
"None"
else
int
(
dim
)
for
dim
in
shape
.
strip
().
split
(
','
)
for
dim
in
shape
.
strip
().
split
(
','
)
...
...
x2paddle/op_mapper/tf_op_mapper.py
浏览文件 @
8a93b96d
...
@@ -350,6 +350,7 @@ class TFOpMapper(OpMapper):
...
@@ -350,6 +350,7 @@ class TFOpMapper(OpMapper):
param
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
param
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
if
param
.
layer_type
==
"Const"
:
if
param
.
layer_type
==
"Const"
:
attr
=
{
"shape"
:
param
.
value
.
tolist
()}
attr
=
{
"shape"
:
param
.
value
.
tolist
()}
self
.
omit_nodes
.
append
(
param
.
layer_name
)
else
:
else
:
# Here is a trick method to solove tensor parameter in tensorflow
# Here is a trick method to solove tensor parameter in tensorflow
assert
len
(
param
.
out_shapes
[
0
]
assert
len
(
param
.
out_shapes
[
0
]
...
@@ -425,3 +426,101 @@ class TFOpMapper(OpMapper):
...
@@ -425,3 +426,101 @@ class TFOpMapper(OpMapper):
inputs
=
input
,
inputs
=
input
,
output
=
node
,
output
=
node
,
param_attr
=
None
)
param_attr
=
None
)
def
Sigmoid
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
node
.
fluid_code
.
add_layer
(
"sigmoid"
,
inputs
=
input
,
output
=
node
,
param_attr
=
None
)
def
Maximum
(
self
,
node
):
x
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
y
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
inputs
=
{
"x"
:
x
,
"y"
:
y
}
node
.
fluid_code
.
add_layer
(
"elementwise_max"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
def
SplitV
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
num_sections
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
dim
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
2
],
copy
=
True
)
assert
num_sections
.
layer_type
==
"Const"
assert
dim
.
layer_type
==
"Const"
self
.
omit_nodes
.
append
(
num_sections
.
layer_name
)
self
.
omit_nodes
.
append
(
dim
.
layer_name
)
attr
=
{
"num_or_sections"
:
num_sections
.
value
.
tolist
(),
"dim"
:
dim
.
value
}
node
.
fluid_code
.
add_layer
(
"split"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
def
Exp
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
node
.
fluid_code
.
add_layer
(
"exp"
,
inputs
=
input
,
output
=
node
,
param_attr
=
None
)
def
ConcatV2
(
self
,
node
):
inputs
=
[
self
.
graph
.
get_node
(
name
,
copy
=
True
)
for
name
in
node
.
layer
.
input
[:
-
1
]]
axis
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
-
1
],
copy
=
True
)
assert
axis
.
layer_type
==
"Const"
self
.
omit_nodes
.
append
(
axis
.
layer_name
)
attr
=
{
"axis"
:
axis
.
value
}
node
.
fluid_code
.
add_layer
(
"concat"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
def
Tile
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
expand_times
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
assert
expand_times
.
layer_type
==
"Const"
self
.
omit_nodes
.
append
(
expand_times
.
layer_name
)
attr
=
{
"expand_times"
:
expand_times
.
value
.
tolist
()}
node
.
fluid_code
.
add_layer
(
"expand"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
def
Pack
(
self
,
node
):
inputs
=
[
self
.
graph
.
get_node
(
name
,
copy
=
True
)
for
name
in
node
.
layer
.
input
[:
-
1
]]
node
.
fluid_code
.
add_layer
(
"stack"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
def
Pad
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
paddings
=
self
.
graph
.
get_node
(
Node
.
layer
.
input
[
1
],
copy
=
True
)
assert
paddings
.
layer_type
==
"Const"
,
"Padding should be Const"
self
.
omit_nodes
.
append
(
paddings
.
layer_name
)
attr
=
{
"paddings"
:
paddings
.
value
.
tolist
()}
node
.
fluid_code
.
add_layer
(
"pad"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
# def ResizeNearestNeighbor(self, node):
# pass
def
Range
(
self
,
node
):
start
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
limit
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
delta
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
2
],
copy
=
True
)
if
start
.
layer_type
==
"Const"
:
self
.
omit_nodes
.
append
(
start
.
layer_name
)
start
=
start
.
value
if
limit
.
layer_type
==
"Const"
:
self
.
omit_nodes
.
append
(
limit
.
layer_name
)
limit
=
limit
.
value
if
delta
.
layer_type
==
"Const"
:
self
.
omit_nodes
.
append
(
delta
.
layer_name
)
delta
=
delta
.
value
inputs
=
{
"start"
:
start
,
"end"
:
limit
,
"step"
:
delta
}
attr
=
{
"dtype"
:
string
(
node
.
dtype
)}
node
.
fluid_code
.
append
(
"range"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
# def Fill(self, node):
# shape = self.graph.get_node(node.layer
def
Mul
(
self
,
node
):
x
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
y
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
inputs
=
{
"x"
:
x
,
"y"
:
y
}
node
.
fluid_code
.
add_layer
(
"elementwise_mul"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
def
Sub
(
self
,
node
):
x
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
y
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
inputs
=
{
"x"
:
x
,
"y"
:
y
}
node
.
fluid_code
.
add_layer
(
"elementwise_sub"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录