Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
8882d824
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看板
提交
8882d824
编写于
2月 11, 2019
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
0ba3c62e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
2 deletion
+37
-2
tensorflow2fluid/demo/export_to_checkpoint.py
tensorflow2fluid/demo/export_to_checkpoint.py
+2
-2
tensorflow2fluid/src/paddle_emitter.py
tensorflow2fluid/src/paddle_emitter.py
+34
-0
tensorflow2fluid/src/tensorflow_parser.py
tensorflow2fluid/src/tensorflow_parser.py
+1
-0
未找到文件。
tensorflow2fluid/demo/export_to_checkpoint.py
浏览文件 @
8882d824
...
...
@@ -39,7 +39,7 @@ def resnet_v1_50(ckpt_file):
img_size
=
resnet_v1
.
resnet_v1
.
default_image_size
img
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
[
None
,
img_size
,
img_size
,
3
],
name
=
'inputs'
)
with
slim
.
arg_scope
(
resnet_v1
.
resnet_arg_scope
()):
net
,
endpoint
=
resnet_v1
.
resnet_v1_50
(
img
,
num_classes
=
None
,
is_training
=
False
)
net
,
endpoint
=
resnet_v1
.
resnet_v1_50
(
img
,
num_classes
=
1000
,
is_training
=
False
)
sess
=
tf
.
Session
()
load_model
=
tf
.
contrib
.
slim
.
assign_from_checkpoint_fn
(
ckpt_file
,
tf
.
contrib
.
slim
.
get_model_variables
(
"resnet_v1_50"
))
...
...
@@ -50,7 +50,7 @@ def resnet_v1_101(ckpt_file):
img_size
=
resnet_v1
.
resnet_v1
.
default_image_size
img
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
[
None
,
img_size
,
img_size
,
3
],
name
=
'inputs'
)
with
slim
.
arg_scope
(
resnet_v1
.
resnet_arg_scope
()):
net
,
endpoint
=
resnet_v1
.
resnet_v1_101
(
img
,
num_classes
=
None
,
is_training
=
False
)
net
,
endpoint
=
resnet_v1
.
resnet_v1_101
(
img
,
num_classes
=
1000
,
is_training
=
False
)
sess
=
tf
.
Session
()
sess
.
run
(
tf
.
global_variables_initializer
())
...
...
tensorflow2fluid/src/paddle_emitter.py
浏览文件 @
8882d824
...
...
@@ -52,6 +52,22 @@ class PaddleEmitter(object):
pad_size
=
(
new_size
-
1
)
*
stride
+
filter_size
-
in_size
return
pad_size
def
check_op
(
self
,
node_name_list
):
uncovered_ops
=
set
()
for
name
in
node_name_list
:
node
=
self
.
graph
.
get_node
(
name
)
if
len
(
node
.
inputs
)
==
0
and
len
(
node
.
outputs
)
==
0
:
continue
if
node
.
layer_type
in
self
.
skip_op
:
continue
if
not
hasattr
(
self
,
"emit_"
+
node
.
layer_type
):
uncovered_ops
.
add
(
node
.
layer_type
)
if
len
(
uncovered_ops
)
>
0
:
sys
.
stderr
.
write
(
"Still {} tensorflow OP are not supported
\n
"
.
format
(
len
(
uncovered_ops
)))
for
op
in
uncovered_ops
:
sys
.
stderr
.
write
(
"Unsupported OP: {}
\n
"
.
format
(
op
))
sys
.
exit
(
0
)
def
get_axis
(
self
,
node1
,
node2
):
shape1
=
self
.
tensor_shape_to_list
(
node1
.
get_attr
(
'_output_shapes'
))[
0
]
shape2
=
self
.
tensor_shape_to_list
(
node2
.
get_attr
(
'_output_shapes'
))[
0
]
...
...
@@ -126,6 +142,7 @@ class PaddleEmitter(object):
self
.
save_var_set
=
set
()
self
.
check_op
(
self
.
graph
.
topological_sort
)
ref_name_recorder
=
open
(
self
.
save_dir
+
"/ref_name.txt"
,
'w'
)
total_nodes_num
=
len
(
self
.
graph
.
topological_sort
)
translated_nodes_count
=
1
...
...
@@ -630,6 +647,16 @@ class PaddleEmitter(object):
else
:
code
=
"{} = layers.reshape({}, {})"
.
format
(
node
.
output_name
,
data
.
ref_name
,
shape
.
ref_name
)
logging
.
warn
(
"
\t
Notice there's RESHAPE in translated code, and the code list below:"
)
logging
.
warn
(
"
\t\t
{}"
.
format
(
code
))
logging
.
warn
(
"
\t
Paddle doesn't support tensor type for output_shape now"
)
logging
.
warn
(
"
\t
You need to change
\'
{}
\'
(in tf model:
\'
{}
\'
) to a list with constant value, e.g. [28, 28]. IMPORTANT!!!
\n
"
.
format
(
shape
.
ref_name
,
shape
.
layer_name
))
return
code
def
emit_conv2dbackpropinput
(
self
,
node
):
...
...
@@ -752,3 +779,10 @@ class PaddleEmitter(object):
.
format
(
node
.
output_name
,
data
.
ref_name
,
in_channels
,
[
k_h
,
k_w
],
strides
,
kernel
.
ref_name
,
groups
))
return
code
def
emit_softmax
(
self
,
node
):
data
=
node
.
inputs
[
0
]
code
=
"{} = layers.softmax({})"
.
format
(
node
.
output_name
,
data
.
ref_name
)
return
code
tensorflow2fluid/src/tensorflow_parser.py
浏览文件 @
8882d824
...
...
@@ -84,6 +84,7 @@ class TensorflowPbParser(object):
if
in_type_list
[
in_nodes
[
i
]]
==
1
or
in_type_list
[
in_nodes
[
i
]]
==
0
:
dtype
=
tensorflow
.
float32
print
(
input_shape
[
i
])
x
=
tensorflow
.
placeholder
(
dtype
,
shape
=
input_shape
[
i
])
elif
in_type_list
[
in_nodes
[
i
]]
==
3
:
dtype
=
tensorflow
.
int32
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录