Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
e1f0c28a
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看板
提交
e1f0c28a
编写于
3月 25, 2019
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some bugs
上级
b9abc476
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
8 deletion
+34
-8
tensorflow2fluid/tf2fluid/paddle_emitter.py
tensorflow2fluid/tf2fluid/paddle_emitter.py
+32
-7
tensorflow2fluid/tf2fluid/tensorflow_parser.py
tensorflow2fluid/tf2fluid/tensorflow_parser.py
+2
-1
未找到文件。
tensorflow2fluid/tf2fluid/paddle_emitter.py
浏览文件 @
e1f0c28a
...
...
@@ -179,7 +179,14 @@ class PaddleEmitter(object):
desc_size
=
tensor_desc
.
ByteSize
()
filew
.
write
(
struct
.
pack
(
'i'
,
desc_size
))
filew
.
write
(
tensor_desc
.
SerializeToString
())
tensor_size
=
reduce
(
lambda
x
,
y
:
x
*
y
,
shape
)
if
len
(
shape
)
==
0
:
if
weight
.
size
==
1
:
tensor_size
=
1
weight
=
numpy
.
array
([
weight
])
else
:
tensor_size
=
0
else
:
tensor_size
=
reduce
(
lambda
x
,
y
:
x
*
y
,
shape
)
weight
=
weight
.
flatten
()
for
i
in
range
(
0
,
tensor_size
):
filew
.
write
(
...
...
@@ -426,7 +433,7 @@ class PaddleEmitter(object):
def
emit_maxpool
(
self
,
node
):
data
=
node
.
inputs
[
0
]
padding_mode
=
node
.
get_attr
(
"padding"
)
input_shape
=
list
(
self
.
infer
.
get_tensor_shape
(
node
.
layer
))
input_shape
=
list
(
self
.
infer
.
get_tensor_shape
(
data
.
layer
))
input_h
,
input_w
=
input_shape
[
2
:
4
]
strides
=
node
.
get_attr
(
"strides"
)[
2
:
4
]
pool_size
=
node
.
get_attr
(
"ksize"
)[
2
:
4
]
...
...
@@ -438,7 +445,7 @@ class PaddleEmitter(object):
pool_param
=
{
"pool_size"
:
pool_size
,
"pool_type"
:
"
\'
max
\'
"
,
"pool_stride"
:
strides
"pool_stride"
:
strides
,
}
if
padding_mode
==
SAME
:
...
...
@@ -446,10 +453,17 @@ class PaddleEmitter(object):
strides
[
0
])
pad_w
=
self
.
compute_padding_size
(
input_w
,
pool_size
[
1
],
strides
[
1
])
pad_right
=
pad_w
[
0
]
+
pad_w
[
1
]
pad_bottom
=
pad_h
[
0
]
+
pad_h
[
1
]
padding
=
[
0
,
pad_right
,
0
,
pad_bottom
]
pad_param
=
{
"paddings"
:
padding
}
# pad_right = pad_w[0] + pad_w[1]
# pad_bottom = pad_h[0] + pad_h[1]
if
(
pad_h
[
0
]
+
pad_h
[
1
])
%
2
!=
0
:
pad_h
[
1
]
+=
pad_h
[
0
]
pad_h
[
0
]
=
0
if
(
pad_w
[
0
]
+
pad_w
[
1
])
%
2
!=
0
:
pad_w
[
1
]
+=
pad_w
[
0
]
pad_w
[
0
]
=
0
#padding = [0, pad_bottom, 0, pad_right]
padding
=
pad_h
+
pad_w
pad_param
=
{
"paddings"
:
padding
,
"pad_value"
:
-
1000000.0
}
node
.
code
.
add_layer
(
"pad2d"
,
data
.
ref_name
,
node
.
output_name
,
pad_param
)
node
.
code
.
add_layer
(
"pool2d"
,
node
.
output_name
,
node
.
output_name
,
...
...
@@ -1050,3 +1064,14 @@ class PaddleEmitter(object):
dim
=
self
.
infer
.
get_const_tensor_value
(
dim
.
layer
)
param
=
{
"axes"
:[
dim
]}
node
.
code
.
add_layer
(
"unsqueeze"
,
data
.
ref_name
,
node
.
output_name
,
param
)
def
emit_cast
(
self
,
node
):
data
=
node
.
inputs
[
0
]
dtype_map
=
{
1
:
"float32"
,
3
:
"int32"
,
9
:
"int64"
}
dtype
=
node
.
get_attr
(
"DstT"
)
if
dtype
in
dtype_map
:
dtype
=
dtype_map
[
dtype
]
else
:
raise
Exception
(
"Unknow dtype: {}"
.
format
(
dtype
))
param
=
{
"dtype"
:
"
\'
{}
\'
"
.
format
(
dtype
)}
node
.
code
.
add_layer
(
"cast"
,
data
.
ref_name
,
node
.
output_name
,
param
)
tensorflow2fluid/tf2fluid/tensorflow_parser.py
浏览文件 @
e1f0c28a
...
...
@@ -17,6 +17,7 @@ from tensorflow_graph import TensorflowGraph
from
tensorflow.python.framework
import
tensor_util
from
tensorflow.python.tools
import
strip_unused_lib
from
tensorflow.python.framework
import
dtypes
import
logging
import
numpy
...
...
@@ -212,7 +213,7 @@ class ModelInfer(object):
def
get_tensor_shape
(
self
,
layer
):
shape
=
layer
.
attr
[
'_output_shapes'
].
list
.
shape
[
0
]
shape
=
numpy
.
array
([
dim
.
size
for
dim
in
shape
.
dim
])
if
numpy
.
argwhere
(
shape
<
0
).
shape
[
0
]
<=
1
:
if
numpy
.
argwhere
(
shape
<
0
).
shape
[
0
]
<=
1
and
len
(
shape
)
!=
0
:
return
shape
tensor_name
=
layer
.
name
if
len
(
tensor_name
.
split
(
':'
))
<
2
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录