Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
da7bfb02
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看板
未验证
提交
da7bfb02
编写于
10月 25, 2019
作者:
M
mamingjie-China
提交者:
GitHub
10月 25, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request
#26
from PaddlePaddle/develop-1.6
Develop 1.6
上级
92384a74
41cc9f14
变更
4
展开全部
显示空白变更内容
内联
并排
Showing
4 changed file
with
237 addition
and
399 deletion
+237
-399
x2paddle/convert.py
x2paddle/convert.py
+20
-29
x2paddle/core/fluid_code.py
x2paddle/core/fluid_code.py
+5
-0
x2paddle/decoder/tf_decoder.py
x2paddle/decoder/tf_decoder.py
+8
-28
x2paddle/op_mapper/tf_op_mapper_nhwc.py
x2paddle/op_mapper/tf_op_mapper_nhwc.py
+204
-342
未找到文件。
x2paddle/convert.py
浏览文件 @
da7bfb02
...
@@ -98,29 +98,12 @@ def tf2paddle(model_path,
...
@@ -98,29 +98,12 @@ def tf2paddle(model_path,
print
(
"Now translating model from tensorflow to paddle."
)
print
(
"Now translating model from tensorflow to paddle."
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
if
not
without_data_format_optimization
:
mapper
=
TFOpMapper
(
model
)
optimizer
=
TFOptimizer
(
mapper
)
# neccesary optimization
optimizer
.
delete_redundance_code
()
# optimizer below is experimental
optimizer
.
optimize_elementwise_op
()
optimizer
.
merge_activation
()
optimizer
.
merge_bias
()
optimizer
.
optimize_sub_graph
()
# optimizer.merge_batch_norm()
# optimizer.merge_prelu()
else
:
mapper
=
TFOpMapperNHWC
(
model
)
mapper
=
TFOpMapperNHWC
(
model
)
optimizer
=
TFOptimizer
(
mapper
)
optimizer
=
TFOptimizer
(
mapper
)
optimizer
.
delete_redundance_code
()
optimizer
.
delete_redundance_code
()
optimizer
.
strip_graph
()
optimizer
.
strip_graph
()
optimizer
.
merge_activation
()
# optimizer.merge_activation()
optimizer
.
merge_bias
()
# optimizer.merge_bias()
optimizer
.
make_nchw_input_output
()
optimizer
.
remove_transpose
()
mapper
.
save_inference_model
(
save_dir
)
mapper
.
save_inference_model
(
save_dir
)
...
@@ -182,21 +165,29 @@ def main():
...
@@ -182,21 +165,29 @@ def main():
if
args
.
version
:
if
args
.
version
:
import
x2paddle
import
x2paddle
print
(
"x2paddle-{} with python>=3.5, paddlepaddle>=1.
5.0
\n
"
.
format
(
print
(
"x2paddle-{} with python>=3.5, paddlepaddle>=1.
6.1
\n
"
.
format
(
x2paddle
.
__version__
))
x2paddle
.
__version__
))
return
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"
try
:
try
:
import
paddle
import
paddle
v0
,
v1
,
v2
=
paddle
.
__version__
.
split
(
'.'
)
v0
,
v1
,
v2
=
paddle
.
__version__
.
split
(
'.'
)
if
int
(
v0
)
!=
1
or
int
(
v1
)
<
5
:
if
int
(
v0
)
==
0
and
int
(
v1
)
==
0
and
int
(
v2
)
==
0
:
print
(
"paddlepaddle>=1.5.0 is required"
)
print
(
"You have installed paddlepaddle-dev? We're not sure it's working for x2paddle!"
)
print
(
"==================paddlepaddle>=1.6.1 is strongly recommended================="
)
elif
int
(
v0
)
!=
1
or
int
(
v1
)
<
6
:
print
(
"paddlepaddle>=1.6.1 is required"
)
return
return
except
:
except
:
print
(
"paddlepaddle not installed, use
\"
pip install paddlepaddle
\"
"
)
print
(
"paddlepaddle not installed, use
\"
pip install paddlepaddle
\"
"
)
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"
if
args
.
framework
==
"tensorflow"
:
if
args
.
framework
==
"tensorflow"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
...
...
x2paddle/core/fluid_code.py
浏览文件 @
da7bfb02
...
@@ -80,6 +80,11 @@ class Layer(object):
...
@@ -80,6 +80,11 @@ class Layer(object):
param_attr
=
collections
.
OrderedDict
(
self
.
param_attr
)
param_attr
=
collections
.
OrderedDict
(
self
.
param_attr
)
for
key
,
value
in
param_attr
.
items
():
for
key
,
value
in
param_attr
.
items
():
if
isinstance
(
value
,
GraphNode
):
value_name
=
value
.
layer_name
if
hasattr
(
value
,
"index"
):
value_name
+=
"[{}]"
.
format
(
value
.
index
)
value
=
value_name
if
'
\n
'
in
str
(
value
):
if
'
\n
'
in
str
(
value
):
value
=
string
(
str
(
value
).
replace
(
'
\n
'
,
','
))
value
=
string
(
str
(
value
).
replace
(
'
\n
'
,
','
))
layer_code
=
layer_code
+
key
+
"={}, "
.
format
(
value
)
layer_code
=
layer_code
+
key
+
"={}, "
.
format
(
value
)
...
...
x2paddle/decoder/tf_decoder.py
浏览文件 @
da7bfb02
...
@@ -389,27 +389,11 @@ class TFDecoder(object):
...
@@ -389,27 +389,11 @@ class TFDecoder(object):
compare01
=
(
results
[
0
]
==
results
[
1
])
compare01
=
(
results
[
0
]
==
results
[
1
])
compare12
=
(
results
[
1
]
==
results
[
2
])
compare12
=
(
results
[
1
]
==
results
[
2
])
if
compare01
.
all
()
and
compare12
.
all
():
compare
=
compare01
&
compare12
index
=
numpy
.
argwhere
(
compare
==
False
).
flatten
()
results
[
0
][
index
]
=
-
1
return
results
[
0
].
tolist
()
return
results
[
0
].
tolist
()
if
(
compare01
==
compare12
).
all
():
index
=
numpy
.
argwhere
(
compare01
==
False
).
flatten
()
if
index
.
shape
[
0
]
!=
1
:
raise
Exception
(
"There's not only one unstable dimension"
)
results
[
0
][
index
[
0
]]
=
-
1
index
=
numpy
.
argwhere
(
results
[
0
]
<
0
).
flatten
()
if
index
.
shape
[
0
]
>
2
:
print
(
"Warning: More than two dimension less than zero"
)
if
index
.
shape
[
0
]
==
2
and
out_shape
is
not
None
:
if
out_shape
[
index
[
1
]]
>
0
:
results
[
0
][
index
[
1
]]
=
out_shape
[
index
[
1
]]
else
:
results
[
0
][
index
[
0
]]
=
out_shape
[
index
[
0
]]
return
results
[
0
].
tolist
()
else
:
raise
Exception
(
"Couldn't infer a stable shape shape tensor value"
)
def
infer_tensor_shape
(
self
,
graph_node
):
def
infer_tensor_shape
(
self
,
graph_node
):
if
hasattr
(
graph_node
,
"index"
):
if
hasattr
(
graph_node
,
"index"
):
tensor_name
=
graph_node
.
layer
.
name
+
":{}"
.
format
(
graph_node
.
index
)
tensor_name
=
graph_node
.
layer
.
name
+
":{}"
.
format
(
graph_node
.
index
)
...
@@ -436,11 +420,7 @@ class TFDecoder(object):
...
@@ -436,11 +420,7 @@ class TFDecoder(object):
if
compare01
.
all
()
and
compare12
.
all
():
if
compare01
.
all
()
and
compare12
.
all
():
return
shape
[
0
].
tolist
()
return
shape
[
0
].
tolist
()
if
(
compare01
==
compare12
).
all
():
compare
=
compare01
&
compare12
index
=
numpy
.
argwhere
(
compare01
==
False
).
flatten
()
index
=
numpy
.
argwhere
(
compare
==
False
).
flatten
()
if
index
.
shape
[
0
]
!=
1
:
shapes
[
0
][
index
]
=
-
1
raise
Exception
(
"There's not only one unstable dimension"
)
if
index
[
0
]
!=
0
:
raise
Exception
(
"Batch size not in the first dimension"
)
shapes
[
0
][
0
]
=
-
1
return
shapes
[
0
].
tolist
()
return
shapes
[
0
].
tolist
()
x2paddle/op_mapper/tf_op_mapper_nhwc.py
浏览文件 @
da7bfb02
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录