Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
69911b60
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看板
提交
69911b60
编写于
7月 19, 2019
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
structure modify
上级
9e3ab110
变更
17
显示空白变更内容
内联
并排
Showing
17 changed file
with
36 addition
and
98 deletion
+36
-98
x2paddle/convert.py
x2paddle/convert.py
+13
-13
x2paddle/core/emitter.py
x2paddle/core/emitter.py
+0
-51
x2paddle/decoder/__init__.py
x2paddle/decoder/__init__.py
+0
-0
x2paddle/decoder/__pycache__/__init__.cpython-35.pyc
x2paddle/decoder/__pycache__/__init__.cpython-35.pyc
+0
-0
x2paddle/decoder/__pycache__/caffe_decoder.cpython-35.pyc
x2paddle/decoder/__pycache__/caffe_decoder.cpython-35.pyc
+0
-0
x2paddle/decoder/__pycache__/caffe_shape.cpython-35.pyc
x2paddle/decoder/__pycache__/caffe_shape.cpython-35.pyc
+0
-0
x2paddle/decoder/__pycache__/tf_decoder.cpython-35.pyc
x2paddle/decoder/__pycache__/tf_decoder.cpython-35.pyc
+0
-0
x2paddle/decoder/caffe_decoder.py
x2paddle/decoder/caffe_decoder.py
+2
-2
x2paddle/decoder/caffe_shape.py
x2paddle/decoder/caffe_shape.py
+0
-0
x2paddle/decoder/tf_decoder.py
x2paddle/decoder/tf_decoder.py
+2
-8
x2paddle/op_mapper/__init__.py
x2paddle/op_mapper/__init__.py
+0
-0
x2paddle/op_mapper/__pycache__/__init__.cpython-35.pyc
x2paddle/op_mapper/__pycache__/__init__.cpython-35.pyc
+0
-0
x2paddle/op_mapper/__pycache__/caffe_op_mapper.cpython-35.pyc
...ddle/op_mapper/__pycache__/caffe_op_mapper.cpython-35.pyc
+0
-0
x2paddle/op_mapper/__pycache__/tf_op_mapper.cpython-35.pyc
x2paddle/op_mapper/__pycache__/tf_op_mapper.cpython-35.pyc
+0
-0
x2paddle/op_mapper/caffe_op_mapper.py
x2paddle/op_mapper/caffe_op_mapper.py
+9
-10
x2paddle/op_mapper/tf_op_mapper.py
x2paddle/op_mapper/tf_op_mapper.py
+9
-13
x2paddle/optimizer/tf_optimizer.py
x2paddle/optimizer/tf_optimizer.py
+1
-1
未找到文件。
x2paddle/convert.py
浏览文件 @
69911b60
...
@@ -46,25 +46,25 @@ def arg_parser():
...
@@ -46,25 +46,25 @@ def arg_parser():
return
parser
return
parser
def
tf2paddle
(
model
,
save_dir
):
def
tf2paddle
(
model
_path
,
save_dir
):
print
(
"Now translating model from tensorflow to paddle."
)
print
(
"Now translating model from tensorflow to paddle."
)
from
x2paddle.
parser.tf_parser
import
TFPars
er
from
x2paddle.
decoder.tf_decoder
import
TFDecod
er
from
x2paddle.optimizer.tf_optimizer
import
TFGraphOptimizer
from
x2paddle.optimizer.tf_optimizer
import
TFGraphOptimizer
from
x2paddle.
emitter.tf_emitter
import
TFEmitt
er
from
x2paddle.
op_mapper.tf_op_mapper
import
TFOpMapp
er
parser
=
TFParser
(
model
)
model
=
TFDecoder
(
model_path
)
emitter
=
TFEmitter
(
parser
)
mapper
=
TFOpMapper
(
model
)
emitt
er
.
run
()
mapp
er
.
run
()
emitt
er
.
save_python_model
(
save_dir
)
mapp
er
.
save_python_model
(
save_dir
)
def
caffe2paddle
(
proto
,
weight
,
save_dir
):
def
caffe2paddle
(
proto
,
weight
,
save_dir
):
print
(
"Now translating model from caffe to paddle."
)
print
(
"Now translating model from caffe to paddle."
)
from
x2paddle.
parser.caffe_parser
import
CaffePars
er
from
x2paddle.
decoder.caffe_decoder
import
CaffeDecod
er
from
x2paddle.
emitter.caffe_emitter
import
CaffeEmitt
er
from
x2paddle.
op_mapper.caffe_op_mapper
import
CaffeOpMapp
er
parser
=
CaffePars
er
(
proto
,
weight
)
model
=
CaffeDecod
er
(
proto
,
weight
)
emitter
=
CaffeEmitter
(
parser
)
mapper
=
CaffeOpMapper
(
model
)
emitt
er
.
run
()
mapp
er
.
run
()
emitt
er
.
save_python_model
(
save_dir
)
mapp
er
.
save_python_model
(
save_dir
)
def
main
():
def
main
():
...
...
x2paddle/core/emitter.py
已删除
100644 → 0
浏览文件 @
9e3ab110
# 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.
from
x2paddle.core.util
import
*
import
os
class
Emitter
(
object
):
def
__init__
(
self
):
self
.
paddle_codes
=
""
self
.
tab
=
" "
self
.
net_code
=
list
()
self
.
weights
=
dict
()
def
add_codes
(
self
,
codes
,
indent
=
0
):
if
isinstance
(
codes
,
list
):
for
code
in
codes
:
self
.
paddle_codes
+=
(
self
.
tab
*
indent
+
code
+
'
\n
'
)
elif
isinstance
(
codes
,
str
):
self
.
paddle_codes
+=
(
self
.
tab
*
indent
+
codes
+
'
\n
'
)
else
:
raise
Exception
(
"Unknown type of codes"
)
def
add_heads
(
self
):
self
.
add_codes
(
"from paddle.fluid.initializer import Constant"
)
self
.
add_codes
(
"from paddle.fluid.param_attr import ParamAttr"
)
self
.
add_codes
(
"import paddle.fluid as fluid"
)
self
.
add_codes
(
""
)
def
save_inference_model
(
self
):
print
(
"Not Implement"
)
def
save_python_model
(
self
,
save_dir
):
for
name
,
param
in
self
.
weights
.
items
():
export_paddle_param
(
param
,
name
,
save_dir
)
self
.
add_heads
()
self
.
add_codes
(
self
.
net_code
)
fp
=
open
(
os
.
path
.
join
(
save_dir
,
"model.py"
),
'w'
)
fp
.
write
(
self
.
paddle_codes
)
fp
.
close
()
x2paddle/
emitt
er/__init__.py
→
x2paddle/
decod
er/__init__.py
浏览文件 @
69911b60
文件已移动
x2paddle/decoder/__pycache__/__init__.cpython-35.pyc
0 → 100644
浏览文件 @
69911b60
文件已添加
x2paddle/decoder/__pycache__/caffe_decoder.cpython-35.pyc
0 → 100644
浏览文件 @
69911b60
文件已添加
x2paddle/decoder/__pycache__/caffe_shape.cpython-35.pyc
0 → 100644
浏览文件 @
69911b60
文件已添加
x2paddle/decoder/__pycache__/tf_decoder.cpython-35.pyc
0 → 100644
浏览文件 @
69911b60
文件已添加
x2paddle/
parser/caffe_pars
er.py
→
x2paddle/
decoder/caffe_decod
er.py
浏览文件 @
69911b60
...
@@ -18,7 +18,7 @@ from google.protobuf import text_format
...
@@ -18,7 +18,7 @@ from google.protobuf import text_format
import
numpy
as
np
import
numpy
as
np
from
x2paddle.core.graph
import
GraphNode
,
Graph
from
x2paddle.core.graph
import
GraphNode
,
Graph
from
x2paddle.core.fluid_code
import
FluidCode
from
x2paddle.core.fluid_code
import
FluidCode
from
x2paddle.
pars
er
import
caffe_shape
from
x2paddle.
decod
er
import
caffe_shape
class
CaffeResolver
(
object
):
class
CaffeResolver
(
object
):
...
@@ -188,7 +188,7 @@ class CaffeGraph(Graph):
...
@@ -188,7 +188,7 @@ class CaffeGraph(Graph):
return
self
.
get_node
(
name
,
copy
=
copy
)
return
self
.
get_node
(
name
,
copy
=
copy
)
class
Caffe
Pars
er
(
object
):
class
Caffe
Decod
er
(
object
):
def
__init__
(
self
,
proto_path
,
model_path
,
use_caffe
=
True
):
def
__init__
(
self
,
proto_path
,
model_path
,
use_caffe
=
True
):
self
.
proto_path
=
proto_path
self
.
proto_path
=
proto_path
self
.
model_path
=
model_path
self
.
model_path
=
model_path
...
...
x2paddle/
pars
er/caffe_shape.py
→
x2paddle/
decod
er/caffe_shape.py
浏览文件 @
69911b60
文件已移动
x2paddle/
parser/tf_pars
er.py
→
x2paddle/
decoder/tf_decod
er.py
浏览文件 @
69911b60
...
@@ -153,14 +153,8 @@ class TFGraph(Graph):
...
@@ -153,14 +153,8 @@ class TFGraph(Graph):
del
self
.
topo_sort
[
idx
]
del
self
.
topo_sort
[
idx
]
class
TFParser
(
object
):
class
TFDecoder
(
object
):
def
__init__
(
self
,
pb_model
,
in_nodes
=
None
,
out_nodes
=
None
,
in_shapes
=
None
):
def
__init__
(
self
,
pb_model
):
# assert in_nodes is not None, "in_nodes should not be None"
# assert out_nodes is not None, "out_nodes should not be None"
# assert in_shapes is not None, "in_shapes should not be None"
# assert len(in_shapes) == len(
# in_nodes), "length of in_shapes and in_nodes should be equal"
sess
=
tf
.
Session
()
sess
=
tf
.
Session
()
with
gfile
.
FastGFile
(
pb_model
,
'rb'
)
as
f
:
with
gfile
.
FastGFile
(
pb_model
,
'rb'
)
as
f
:
graph_def
=
tf
.
GraphDef
()
graph_def
=
tf
.
GraphDef
()
...
...
x2paddle/
pars
er/__init__.py
→
x2paddle/
op_mapp
er/__init__.py
浏览文件 @
69911b60
文件已移动
x2paddle/op_mapper/__pycache__/__init__.cpython-35.pyc
0 → 100644
浏览文件 @
69911b60
文件已添加
x2paddle/op_mapper/__pycache__/caffe_op_mapper.cpython-35.pyc
0 → 100644
浏览文件 @
69911b60
文件已添加
x2paddle/op_mapper/__pycache__/tf_op_mapper.cpython-35.pyc
0 → 100644
浏览文件 @
69911b60
文件已添加
x2paddle/
emitter/caffe_emitt
er.py
→
x2paddle/
op_mapper/caffe_op_mapp
er.py
浏览文件 @
69911b60
...
@@ -13,18 +13,17 @@
...
@@ -13,18 +13,17 @@
# limitations under the License.
# limitations under the License.
import
numbers
import
numbers
from
x2paddle.
parser.caffe_pars
er
import
CaffeGraph
from
x2paddle.
decoder.caffe_decod
er
import
CaffeGraph
from
x2paddle.core.
emitter
import
Emitt
er
from
x2paddle.core.
op_mapper
import
OpMapp
er
from
x2paddle.core.util
import
*
from
x2paddle.core.util
import
*
class
CaffeEmitter
(
Emitter
):
class
CaffeOpMapper
(
OpMapper
):
def
__init__
(
self
,
parser
):
def
__init__
(
self
,
decoder
):
super
(
CaffeEmitter
,
self
).
__init__
()
super
(
CaffeOpMapper
,
self
).
__init__
()
self
.
parser
=
parser
self
.
graph
=
decoder
.
caffe_graph
self
.
graph
=
parser
.
caffe_graph
self
.
weights
=
dict
()
self
.
weights
=
dict
()
resolver
=
pars
er
.
resolver
resolver
=
decod
er
.
resolver
if
resolver
.
has_pycaffe
():
if
resolver
.
has_pycaffe
():
self
.
did_use_pb
=
False
self
.
did_use_pb
=
False
else
:
else
:
...
@@ -36,8 +35,8 @@ class CaffeEmitter(Emitter):
...
@@ -36,8 +35,8 @@ class CaffeEmitter(Emitter):
node
=
self
.
graph
.
get_node
(
node_name
)
node
=
self
.
graph
.
get_node
(
node_name
)
op
=
node
.
layer_type
op
=
node
.
layer_type
if
hasattr
(
self
,
op
):
if
hasattr
(
self
,
op
):
emit_
func
=
getattr
(
self
,
op
)
func
=
getattr
(
self
,
op
)
emit_
func
(
node
)
func
(
node
)
for
i
in
range
(
len
(
self
.
graph
.
topo_sort
)):
for
i
in
range
(
len
(
self
.
graph
.
topo_sort
)):
node_name
=
self
.
graph
.
topo_sort
[
i
]
node_name
=
self
.
graph
.
topo_sort
[
i
]
...
...
x2paddle/
emitter/tf_emitt
er.py
→
x2paddle/
op_mapper/tf_op_mapp
er.py
浏览文件 @
69911b60
...
@@ -12,21 +12,17 @@
...
@@ -12,21 +12,17 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
x2paddle.parser.tf_parser
import
TFGraph
from
x2paddle.decoder.tf_decoder
import
TFGraph
from
x2paddle.core.emitter
import
Emitter
from
x2paddle.core.op_mapper
import
OpMapper
from
x2paddle.core.fluid_code
import
FluidCode
from
x2paddle.core.util
import
*
from
x2paddle.core.util
import
*
import
numpy
import
numpy
class
TFEmitter
(
Emitter
):
class
TFOpMapper
(
OpMapper
):
def
__init__
(
self
,
parser
):
def
__init__
(
self
,
decoder
):
super
(
TFEmitter
,
self
).
__init__
()
super
(
TFOpMapper
,
self
).
__init__
()
self
.
parser
=
parser
self
.
graph
=
decoder
.
tf_graph
self
.
graph
=
parser
.
tf_graph
self
.
weights
=
dict
()
# attr_node is used to record nodes that
# only for define attribute of op
self
.
attr_node
=
list
()
self
.
omit_nodes
=
list
()
self
.
omit_nodes
=
list
()
def
run
(
self
):
def
run
(
self
):
...
@@ -35,8 +31,8 @@ class TFEmitter(Emitter):
...
@@ -35,8 +31,8 @@ class TFEmitter(Emitter):
node
=
self
.
graph
.
get_node
(
node_name
)
node
=
self
.
graph
.
get_node
(
node_name
)
op
=
node
.
layer_type
op
=
node
.
layer_type
if
hasattr
(
self
,
op
):
if
hasattr
(
self
,
op
):
emit_
func
=
getattr
(
self
,
op
)
func
=
getattr
(
self
,
op
)
emit_
func
(
node
)
func
(
node
)
for
i
in
range
(
len
(
self
.
graph
.
topo_sort
)):
for
i
in
range
(
len
(
self
.
graph
.
topo_sort
)):
node_name
=
self
.
graph
.
topo_sort
[
i
]
node_name
=
self
.
graph
.
topo_sort
[
i
]
...
...
x2paddle/optimizer/tf_optimizer.py
浏览文件 @
69911b60
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
# limitations under the License.
# limitations under the License.
# TODO useless node remove
# TODO useless node remove
from
x2paddle.
parser.tf_pars
er
import
TFGraph
from
x2paddle.
decoder.tf_decod
er
import
TFGraph
class
TFGraphOptimizer
(
object
):
class
TFGraphOptimizer
(
object
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录