Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
0e572fc5
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看板
提交
0e572fc5
编写于
7月 17, 2019
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add code
上级
51fcdabb
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
78 addition
and
7 deletion
+78
-7
x2paddle/core/fluid_code.py
x2paddle/core/fluid_code.py
+3
-0
x2paddle/core/graph.py
x2paddle/core/graph.py
+6
-1
x2paddle/emitter/tf_emitter.py
x2paddle/emitter/tf_emitter.py
+57
-6
x2paddle/parser/tf_parser.py
x2paddle/parser/tf_parser.py
+12
-0
未找到文件。
x2paddle/core/fluid_code.py
浏览文件 @
0e572fc5
...
...
@@ -60,6 +60,9 @@ class FluidCode(object):
# note should be string
self
.
layers
.
append
(
note
)
def
clear
(
self
):
self
.
layers
=
list
()
def
gen_codes
(
self
):
codes
=
list
()
for
layer
in
self
.
layers
:
...
...
x2paddle/core/graph.py
浏览文件 @
0e572fc5
...
...
@@ -74,6 +74,11 @@ class Graph(object):
def
get_node
(
self
,
name
):
if
name
not
in
self
.
node_map
:
if
name
.
split
(
':'
)[
0
]
in
self
.
node_map
:
name_prefix
,
idx
=
name
.
split
(
':'
)
self
.
node_map
[
name_prefix
].
index
=
int
(
idx
)
return
self
.
node_map
[
name_prefix
]
else
:
raise
Exception
(
"Graph doesn't have node [%s]."
%
name
)
else
:
return
self
.
node_map
[
name
]
...
...
x2paddle/emitter/tf_emitter.py
浏览文件 @
0e572fc5
...
...
@@ -15,6 +15,7 @@
from
x2paddle.parser.tf_parser
import
TFGraph
from
x2paddle.core.emitter
import
Emitter
from
x2paddle.core.fluid_code
import
FluidCode
from
x2paddle.core.util
import
*
class
TFEmitter
(
Emitter
):
...
...
@@ -22,7 +23,7 @@ class TFEmitter(Emitter):
super
(
TFEmitter
,
self
).
__init__
()
self
.
parser
=
parser
self
.
graph
=
parser
.
tf_graph
self
.
fluid_code
=
FluidCode
()
self
.
weights
=
dict
()
def
run
(
self
):
print
(
"Total nodes: {}"
.
format
(
len
(
self
.
graph
.
topo_sort
)))
...
...
@@ -33,16 +34,66 @@ class TFEmitter(Emitter):
emit_func
=
getattr
(
self
,
op
)
emit_func
(
node
)
for
i
in
range
(
len
(
self
.
graph
.
topo_sort
)):
node_name
=
self
.
graph
.
topo_sort
[
i
]
node
=
self
.
graph
.
get_node
(
node_name
)
for
layer
in
node
.
fluid_code
.
layers
:
print
(
layer
.
get_code
())
def
Placeholder
(
self
,
node
):
shape
=
node
.
out_shapes
[
0
]
dtype
=
node
.
dtype
attr
=
{
'dtype'
:
'\{}
\'
'
.
format
(
dtype
),
'dtype'
:
string
(
dtype
),
'shape'
:
shape
,
'name'
:
'
\'
{}
\'
'
.
format
(
node
.
layer_name
)
'name'
:
string
(
node
.
layer_name
)
}
self
.
fluid_code
.
add_layer
(
"data"
,
inputs
=
inputs
,
node
.
fluid_code
.
add_layer
(
"data"
,
inputs
=
None
,
output
=
node
,
param_attr
=
attr
)
def
Const
(
self
,
node
):
shape
=
node
.
out_shapes
[
0
]
dtype
=
node
.
dtype
value
=
node
.
value
initializer
=
"Constant(0.0)"
if
len
(
shape
)
==
0
:
assert
value
.
size
==
1
,
"Unexpected situation happend"
shape
=
[
1
]
initializer
=
"Constant({})"
.
format
(
value
)
attr
=
{
'dtype'
:
string
(
dtype
),
'shape'
:
shape
,
'name'
:
string
(
node
.
layer_name
),
'default_initializer'
:
initializer
}
node
.
fluid_code
.
add_layer
(
"create_parameter"
,
inputs
=
None
,
output
=
node
,
param_attr
=
attr
)
def
Transpose
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
])
perm
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
])
perm
.
fluid_code
.
clear
()
perm
=
perm
.
value
.
tolist
()
attr
=
{
'perm'
:
perm
}
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
print
(
self
.
fluid_code
.
layers
[
0
].
get_code
())
def
RealDiv
(
self
,
node
):
x
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
])
y
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
])
inputs
=
{
'x'
:
x
,
'y'
:
y
}
node
.
fluid_code
.
add_layer
(
"elementwise_div"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
def
Fc
(
self
,
node
):
self
.
weight
[
'asdf'
]
=
np
.
tranpose
(
node
.
kerneln
[
1
,
0
])
x2paddle/parser/tf_parser.py
浏览文件 @
0e572fc5
...
...
@@ -13,6 +13,8 @@
# limitations under the License.
from
x2paddle.core.graph
import
GraphNode
,
Graph
from
x2paddle.core.fluid_code
import
FluidCode
from
tensorflow.python.framework
import
tensor_util
from
tensorflow.python.platform
import
gfile
import
tensorflow
as
tf
import
copy
...
...
@@ -24,7 +26,9 @@ class TFGraphNode(GraphNode):
super
(
TFGraphNode
,
self
).
__init__
(
layer
,
layer
.
name
)
else
:
super
(
TFGraphNode
,
self
).
__init__
(
layer
,
layer_name
)
self
.
layer_type
=
layer
.
op
self
.
fluid_code
=
FluidCode
()
self
.
dtype_map
=
{
1
:
"float32"
,
3
:
"int32"
,
9
:
"int64"
}
...
...
@@ -44,6 +48,14 @@ class TFGraphNode(GraphNode):
raise
Exception
(
"Dtype[{}] not in dtype_map"
.
format
(
dtype
))
return
self
.
dtype_map
[
dtype
]
@
property
def
value
(
self
):
assert
self
.
layer_type
==
"Const"
,
"Only Const node has value."
attr
=
self
.
layer
.
attr
[
'value'
]
field
=
getattr
(
attr
,
attr
.
WhichOneof
(
'value'
))
return
tensor_util
.
MakeNdarray
(
field
)
class
TFGraph
(
Graph
):
def
__init__
(
self
,
model
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录